Blazor 中的自定义输入文件

Custom InputFile in Blazor

我想用 'attach Icon' 替换 InputFile 的矩形。我尝试将图标的 URL 设置为 InputFile 的 'background-image' 但是没有效果。 只是演示了如何改变InputFile的颜色,并不是我所需要的

我想也许这就是您要找的。

HTML/Razor代码

<div class="file-input-zone">
    <InputFile />
</div>

CSS

<style>
.file-input-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    color: black;
    cursor: pointer;
    position: relative;
    width: 120px;
    height: 120px;
    background-image: url('paper-clip.png');
}

    .file-input-zone:hover {
        background-color: lightblue;
    }

    .file-input-zone input[type=file] {
        position: absolute;
        width: 100%;
        height: 100%;
        opacity: 0;
        cursor: pointer;
    }
</style>

在上面的CSS代码中,文件paper-clip.png安装在wwwroot目录下。

按钮看起来像一个透明的回形针。在下图中,悬停时颜色也会发生变化。

我使用类似的颜色选择器。

<label for="fileinput" class="label-wrapper">
    <span class="oi oi-paperclip"></span>
    <InputFile id="fileinput" class="custom-input-hide" />
</label>

<style>
    .label-wrapper:hover {
        cursor: pointer;
    }

    .custom-input-hide {
        width: 0;
        height: 0;
        overflow: hidden;
    }
</style>

BlazorRepl