【发布时间】:2017-05-09 03:19:47
【问题描述】:
我有自定义文件附加字段。它工作正常,但有一点需要修复:该字段的右侧完全不活动。此外,如果您将光标移到左上角,您会注意到这部分显然是活动的,但 CSS“光标:指针”选项没有效果。很确定我错过了一些简单的事情,请告诉我我的错误是什么?先感谢您。 JSFiddle
@import url('https://fonts.googleapis.com/css?family=Roboto:100,300,500&subset=cyrillic');
* {
margin: 0;
padding: 0;
}
body, html {
height: 100%;
}
body {
color: #fff;
font-size: 18px;
font-family: "Roboto";
font-weight: 100;
background: #333;
}
body a {
color:#fff;
text-decoration: none;
outline: none;
}
#container {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.file-area {
width: 450px;
box-sizing: border-box;
position: relative;
}
.file-area input[type=file] {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0;
cursor: pointer;
}
.file-area .file-dummy {
width: 450px;
padding: 30px;
background: rgba(75, 58, 38, 0.3);
border: 1px dashed rgba(255, 255, 255, 0.5);
text-align: center;
transition: background 0.3s ease-in-out;
}
.file-area .file-dummy .success {
display: none;
}
.file-area:hover .file-dummy {
background: rgba(255, 255, 255, 0.1);
}
.file-area input[type=file]:focus + .file-dummy {
outline: 2px solid rgba(255, 255, 255, 0.5);
outline: -webkit-focus-ring-color auto 5px;
outline: none;
}
.file-area input[type=file]:valid + .file-dummy {
border-color: rgba(0, 255, 0, 0.4);
background-color: rgba(0, 255, 0, 0.2);
}
.file-area input[type=file]:valid + .file-dummy .success {
display: inline-block;
}
.file-area input[type=file]:valid + .file-dummy .default {
display: none;
}
<div id="container">
<div class="file-area">
<input type="file" name="files" id="files" required="required"/>
<div class="file-dummy">
<span class="default">Choose files</span>
<span class="success">Yahoo!</span>
</div>
</div>
</div>
【问题讨论】:
-
因为你的
.file-area类有固定的宽度。 -
@KOKOC 我认为您必须删除
cursor: pointer并将其设为默认值,因为左上角的文件浏览器会对指针产生影响,因此您必须使用相同的指针值。跨度> -
感谢您和其他人,但这是在整个块上传播“光标:指针”效果的任何方式吗?如果我将指针悬停在左上角的框上,指针手指仍然会变成光标。