我有以下CSS3来源:
input[type="text"], input[type="date"], textarea, input[type="radio"], input[type="number"],
input[type="time"], input[type="password"] {
background: #ffffff; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIzMiUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjZWRlZGVkIiBzdG9wLW9wYWNpdHk9IjEiLz4KICA8L2xpbmVhckdyYWRpZW50PgogIDxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIGZpbGw9InVybCgjZ3JhZC11Y2dnLWdlbmVyYXRlZCkiIC8+Cjwvc3ZnPg==);
background: -moz-linear-gradient(top, #ffffff 32%, #ededed 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(32%,#ffffff), color-stop(100%,#ededed)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffffff 32%,#ededed 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffffff 32%,#ededed 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffffff 32%,#ededed 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffffff 32%,#ededed 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ededed',GradientType=0 ); /* IE6-8 */
font-size: 15px;
border: 1px solid #9e9e9e;
border-radius: 3px;
height: 23px;
padding-right:3px;
}
input[type="text"]:focus, input[type="date"]:focus, textarea:focus, input[type="radio"]:focus, input[type="number"]:focus,
input[type="time"]:focus, input[type="password"]:focus {
border: none;
outline: none;
-webkit-transition: .1s;
-moz-transition: .2s;
transition: .2s;
-o-transition: .2s;
-moz-box-shadow: 0px 0px 4px 2px #5792ea;
-webkit-box-shadow: 0px 0px 4px 2px #5792ea;
box-shadow: 0px 0px 4px 2px #5792ea;
}
这个HTML源代码:
<form name="Login" action="Login.aspx" method="post" runat="server">
<p>
Email:
<input type="text" name="Email" />
</p>
<p>
Password:
<input type="password" name="Password" />
</p>
<p>
<button name="submit" class="blue-button" type="submit" style="margin-right:65px;">התחברות</button>
</p>
</form>
这是现场示例:http://jsfiddle.net/f4sp5/
问题在于,当我专注于输入时,我发现输入下的所有内容都会消失。
我的问题是如何避免这种情况向下移动?
感谢。
答案 0 :(得分:2)
这是因为你的正常状态输入有一个边框,但是当它们被聚焦时,它们会失去那个边界(当你设置它时)。为了避免这种故障,要么在两种状态下都使用边界,要么都不使用......
这就是我所做的:
input[type="text"]:focus {/*border: none;*/}
答案 1 :(得分:1)
我相信它是因为您删除了边框并在:focus
上添加了填充,这只是更改元素宽度 - 尝试添加:
box-sizing: border-box;
和-moz-box-sizing: border-box;
- 您将约束填充和边框到元素内容宽度。