apple style expanding searchfield

蹲街弑〆低调 提交于 2019-12-13 18:32:08

问题


I'm trying to mimic apple's navbar style, specially the CSS3 expanding searchfield.

It uses an UL with display:table and it's LI's with display:table-cell and width:100%. When focused the search LI expands and the other LI's contract to fit.

Now my li's won't resize.

Anybody got a clue on what I'm missing there?

Also, IE is not even displaying anything.


回答1:


Hey now you can used this one

HTML

<input type="text" placeholder="search bar">

css

input[type="text"] {
    background: #444;
    border: 0 none;
    font: bold 12px Arial,Helvetica,Sans-serif;
    color: #d7d7d7;
    width:50px;
    padding: 6px 15px 6px 35px;
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px;
    border-radius: 20px;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.3);
    -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
    -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2) inset;
    margin:3px 12px;
}

input[type="text"]:focus {
    background:#fcfcfc;
    color: #6a6f75;
    width: 120px;
    -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.9) inset;
    -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.9) inset;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(0, 0, 0, 0.9) inset;
    text-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
    margin:3px 12px;
    outline: none;
}

input[type="text"] {
    -webkit-transition: all 0.7s ease 0s;
    -moz-transition: all 0.7s ease 0s;
    -o-transition: all 0.7s ease 0s;
    transition: all 0.7s ease 0s;
}

live demo http://jsfiddle.net/vzLFS/3/




回答2:


On the apple page, they seem to add a class to the nav-element (.searchmode)when the input gets focused which handles the width of the <li>-element containg the <input>.

While not sure if there a css-only Solution for that you could do somehting like this with jQuery like this:

$('#searchform input').on('focus', function(){
   $(this).closest('li').css('width', '180px');
});

$('#searchform input').on('blur', function(){
   $(this).closest('li').css('width', '50px');
});

...and still use css-transitions for the FX :)



来源:https://stackoverflow.com/questions/11305406/apple-style-expanding-searchfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!