Nave Tseva
Nave Tseva

Reputation: 878

styling input outline border - CSS3

I have the following CSS3 source:

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;
    }

And this HTML source:

 <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> 

And here is live example: http://jsfiddle.net/f4sp5/

The problem is that when I focusd on input I see that all the contant under the input is going down.

My question is how can I avoid this moving down?

Thanks.

Upvotes: 0

Views: 2988

Answers (2)

Adrift
Adrift

Reputation: 59799

I believe its because you're removing a border and adding padding on :focus which is simply changing the elements width - try adding:

box-sizing: border-box; and -moz-box-sizing: border-box; for FF - you'll constrain the padding and border to the elements content width.

jsFiddle

Upvotes: 1

Shomz
Shomz

Reputation: 37701

It's because your normal-state inputs have a border, yet when they are focused, they lose that border (as you set it). To avoid this glitch, either use borders on both states or on neither...

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

This is what I did:

input[type="text"]:focus {/*border: none;*/}

Upvotes: 2

Related Questions