文件输入字段不是 100% 活动的
File input field is not 100% active
我有自定义文件附加字段。它工作正常,但有一点需要修复:字段的右侧完全不活动。此外,如果将光标移到左上角,您会注意到这部分显然处于活动状态,但 CSS "cursor: pointer" 选项没有效果。很确定我错过了一些简单的事情,请告诉我我的错误是什么?先感谢您。 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
的宽度,看起来工作正常。
============最新变化================
只是为了改变 cursor: pointer
技巧 font-size:0;
@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 {
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;
font-size:0;
}
.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>
问题只是因为 class file-area
中的固定 width
,请尝试删除宽度,希望它能解决您的问题
去掉.file-dummy
的宽度应该就解决了
.file-area .file-dummy {
width: 450px;
}
将您的 .file-area class 宽度修改为 100%
您添加 padding
和苹果 width 100%
,填充包括宽度。
像这样改变宽度width: calc(100% - 60px);
.file-area .file-dummy {
background: rgba(75, 58, 38, 0.3) none repeat scroll 0 0;
border: 1px dashed rgba(255, 255, 255, 0.5);
padding: 30px;
text-align: center;
transition: background 0.3s ease-in-out 0s;
width: calc(100% - 60px);
}
我有自定义文件附加字段。它工作正常,但有一点需要修复:字段的右侧完全不活动。此外,如果将光标移到左上角,您会注意到这部分显然处于活动状态,但 CSS "cursor: pointer" 选项没有效果。很确定我错过了一些简单的事情,请告诉我我的错误是什么?先感谢您。 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
的宽度,看起来工作正常。
============最新变化================
只是为了改变 cursor: pointer
技巧 font-size:0;
@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 {
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;
font-size:0;
}
.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>
问题只是因为 class file-area
中的固定 width
,请尝试删除宽度,希望它能解决您的问题
去掉.file-dummy
的宽度应该就解决了
.file-area .file-dummy {
width: 450px;
}
将您的 .file-area class 宽度修改为 100%
您添加 padding
和苹果 width 100%
,填充包括宽度。
像这样改变宽度width: calc(100% - 60px);
.file-area .file-dummy {
background: rgba(75, 58, 38, 0.3) none repeat scroll 0 0;
border: 1px dashed rgba(255, 255, 255, 0.5);
padding: 30px;
text-align: center;
transition: background 0.3s ease-in-out 0s;
width: calc(100% - 60px);
}