CSS+HTML5实现加号上传效果

参考了博客:html中加号实体,纯css实现加号“+”效果(代码示例)_Paquars的博客-CSDN博客

实际上就是用两个伪元素选择器实现的。

但是在测试过程中,发现::after这个选择器鼠标完全点击到这根线上时,此时选择文件的窗口弹不出来。因此最后选择了 只用::before实现一条杠的效果,然后用一个div实现了另外一条杠的效果。(当然两个杠都可以用div实现,用伪元素选择器只是因为一开始我不会写百度资料所得到的方法,另外是用选择器代码看起来简单些)

 附上代码:

h5

<div class="chuans" style="height: 20rem;">
    <div class="shu"></div>
    <img th:src="@{${task.attachmentPath}}" alt="" data-imgsrc="" id="imageA">
    <input class="uploadImg file1" type="file" name="file1" id="filePath" accept="image/*">
</div>

css

div.chuans {
    position: relative;
    width: 240px;
    height: 20rem;
    border-radius: 3px;
    border: 1px dashed #ccc;
    margin: auto;
    overflow: hidden;
}

div.chuans::before{
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 80px;
    margin-left: -40px;
    margin-top: -1px;
    border-top: 2px solid;
}

div.chuans .shu {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    height: 80px;
    margin-left: -1px;
    margin-top: -40px;
    border-left: 2px solid;
}

div.chuans img {
    position: absolute;
    background-size: contain;
    max-width: 238px;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
}

input.uploadImg {
    display: inline-block;
    width: 100%;
    height: 100%;
    opacity: 0;
    z-index: 999;
}