0

我有以下 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/

问题是当我专注于输入时,我发现输入下的所有内容都在下降。

我的问题是如何避免这种向下移动?

谢谢。

4

2 回答 2

2

这是因为您的正常状态输入具有边框,但是当它们聚焦时,它们会失去该边框(正如您设置的那样)。为了避免这个故障,要么在两个州都使用边界,要么都不在...

http://jsfiddle.net/f4sp5/4/

这就是我所做的:

input[type="text"]:focus {/*border: none;*/}
于 2013-04-25T18:27:56.230 回答
1

我相信它是因为您要删除边框并添加填充,:focus这只是更改元素的宽度 - 尝试添加:

box-sizing: border-box;-moz-box-sizing: border-box;对于 FF - 您将内边距和边框限制为元素内容宽度。

jsFiddle

于 2013-04-25T18:28:48.847 回答