将搜索字段和列表项保留在标题内的右侧

时间:2015-02-10 00:39:31

标签: javascript jquery html css

标题可能不明确,但我想复制本网站使用的搜索字段:http://thenextweb.com/

单击搜索按钮时,它会显示/隐藏输入,但它也会将其余列表项一直滑动到右侧(填充输入的空间)。

我更希望解决方案是在jQuery中。

以下是我正在使用的代码:

HTML     

    <div id ="header">

        <div id="main-list">
            <ul>
                <li id ="logo"><a href=""><img src="../images/nextimages/tnwlistlogo.png"/></a></li>
                <li id ="blog"><a href="">Blog</a></li>
                <li id ="other-main-list"><a href="">Conference</a></li>
                <li id ="other-main-list"><a href="">103 Deals</a></li>
                <li id ="other-main-list"><a href="">Pro</a></li>
            </ul>
        </div>

        <div id ="social">
          <ul>
            <li><div class="fb-like" data-href="https://www.facebook.com/thenextweb" data-layout="button" data-action="like" data-show-faces="false" data-share="false"></div></li>
            <li><a href="https://twitter.com/TheNextWeb" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow</a></li>
            <li><a href="http://thenextweb.com/feed?token=116910" id="rss"></a></li>
            <li id ="icons"><i class="fa fa-sort-desc"></i></li>
            <li id ="icons"><i class="fa fa-user"></i></li>
            <li id ="icons"><i class="fa fa-info-circle"></i></li>
            <li id ="search"><i class="fa fa-search"></i></li>
            <input id ="search-input" name="search" placeholder ="Search..." type="text"></input>
         </ul>

        </div>

    </div>

<!--End of wrapper-->    
</div>

CSS

#wrapper {
    height:100%;
    width:100%;
    padding:0;
    margin:0;
}
#header{
    width:100%;
    max-width:100%;
    height:3em;
    border-bottom: 2px solid #d9e0e2;
    min-width:320px;
}
#main-list{
    width:37%;
    float:left;
}
#main-list li{
    display:inline-block;
    height:3em;
    vertical-align:middle;
}
#main-list ul{
    height::3em;
    padding:0;
    margin:0;
    list-style-type:none;
}
#logo {
    margin-right:.875em;
}
#blog a{
    color:#FF3C1F;
    display:block;
    margin-right:.5em;
    line-height:2.9em;
    text-decoration:none;
    font-size:1em;
    font-weight:400;
    text-transform:capitalize;
    font-family:'Fjalla One', Arial, Helvetica, sans-serif;
    text-transform:uppercase;
    border-bottom:2px solid #FF3C1F;
}
#other-main-list a{
    display:block;
    margin-right:.875em;
    line-height:2.9em;
    text-decoration:none;
    font-size:1em;
    color:#879096;
    font-weight:400;
    opacity:.6;
    text-transform:capitalize;
    font-family:'Fjalla One', Arial, Helvetica, sans-serif;
    text-transform:uppercase;
}

#other-main-list a:hover{
    color:#FF3C1F;
    border-bottom:2px solid #FF3C1F;
    opacity:1;
}
#main-list img{
    padding-top:4px;
    padding-left:5px;
}

#social{
    width:40em;
    float:right;
}
#social li{
    display:inline-block;
    margin-right:.3em;
    vertical-align:middle;
    height:3em;
    padding-top:.75em;
}

#rss{
    display: block;
    height: 20px;
    width: 20px;
    background: #f80;
    color: #fff;
    border-radius: 2px;
    top: 0;
    line-height: 20px;
    font-size: 14px;
    text-align: center;
    text-indent: 2px;
    border: 1px solid #dd7600;
    background-image:url(../images/nextimages/rss.png);
}

#social img{
    width:24px;
    height:24px;
}
#social i:first-child{
    margin-left:.875em;
}
#social i:last-child{
    border-right:none;
}
#icons {
    border-right:1px solid #F2F2F2;
    display:inline-block;
}
#icons i{
    width:24px;
    height:3em;
    margin-right:.5em;}

#icons i:hover{
    color:#FF3C1F;
    cursor:pointer;
}

#search i{
    width:24px;
    height:3em;
    margin-right:.5em;
    border-right:none;
}

#search i:hover{
    color:#FF3C1F;
    cursor:pointer;
}
#search-input {
    width:40%;
    background-color: #f7f9f9;
    border-radius: 3px;
    display: inline-block;
    font-size: 14px;
    line-height: 20px;
    margin: 0;
    outline: 0;
    padding: 8px 8px 6px 8px !important;
    border: 1px solid #d9e0e2 !important;
    box-shadow: none;
    font-family:'Source Sans Pro', sans-serif;
    font-weight:200;
    padding-left:50px;
}

的jQuery

$(document).ready(function(){
    $('#search').click(function(){
        $('#search-input').animate({width:'toggle'});
        return false;
    });

3 个答案:

答案 0 :(得分:0)

怎么样:

#social ul {
    float: right;
}

答案 1 :(得分:0)

这是您的解决方案http://jsbin.com/poturukeha/1/edit

你需要漂浮:整个部分。

答案 2 :(得分:0)

对于css:

#social ul {
    float: right;
}
像@bobdye说的那样......

并使用您的onlick功能隐藏它:

document.getElementById(inputID).style.display = 'none';

或显示它:

document.getElementById(inputID).style.display = 'none';