在导航栏上定位

时间:2014-10-15 22:01:33

标签: html css

我创建了一个导航栏,上面有一些链接和一个标题,就像bootstrap一样,但是我试图让它成为右侧的帐号下拉列表,但当我添加类“pullRight”时,它会移动它在右边,但不会留在导航栏上。

Screenshot

pullright CSS

.pullRight {
    float: right;
}

HTML

<ul>
    <li><a href="#"><i class="fa fa-comments"></i> Forums</a></li>
    <li><a href="#"><i class="fa fa-trophy"></i> Players</a></li>
    <li><a href="#"><i class="fa fa-shopping-cart"></i> Shop</a></li>
    <li class="pullRight"><a href="#"><i class="fa fa-user"></i> Account</a></li>
</ul>

导航栏CSS

.navigationBar {
    width: 100%;
    height: 40px;
    background: #efefef;
    background: -moz-linear-gradient(top,  #efefef 50%, #d3d3d3 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(50%,#efefef), color-stop(100%,#d3d3d3));
    background: -webkit-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: -o-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: -ms-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: linear-gradient(to bottom,  #efefef 50%,#d3d3d3 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#efefef', endColorstr='#d3d3d3',GradientType=0 );
    border-bottom: 2px solid #EB7727;
}
.navigationBar ul {
    list-style: none;
}
.navigationBar ul li {
    width: 100px;
    height: 40px;
    background: #efefef;
    background: -moz-linear-gradient(top,  #efefef 50%, #d3d3d3 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(50%,#efefef), color-stop(100%,#d3d3d3));
    background: -webkit-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: -o-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: -ms-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: linear-gradient(to bottom,  #efefef 50%,#d3d3d3 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#efefef', endColorstr='#d3d3d3',GradientType=0 );
    border-bottom: 2px solid #EB7727;
    text-align: center;
    border-right: 1px solid gray;
    display: table-cell;
    cursor: pointer;
}
.navigationBar ul li:first-child {
    border-left: 1px solid gray;
}
.navigationBar ul li:hover {
    border-right: 1px solid gray;
    display: table-cell;
    width: 100px;
    height: 40px;
    background: rgb(211,211,211); /* Old browsers */
    background: -moz-linear-gradient(top,  rgba(211,211,211,1) 0%, rgba(239,239,239,1) 50%, rgba(211,211,211,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(211,211,211,1)), color-stop(50%,rgba(239,239,239,1)), color-stop(100%,rgba(211,211,211,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  rgba(211,211,211,1) 0%,rgba(239,239,239,1) 50%,rgba(211,211,211,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  rgba(211,211,211,1) 0%,rgba(239,239,239,1) 50%,rgba(211,211,211,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  rgba(211,211,211,1) 0%,rgba(239,239,239,1) 50%,rgba(211,211,211,1) 100%); /* IE10+ */
    background: linear-gradient(to bottom,  rgba(211,211,211,1) 0%,rgba(239,239,239,1) 50%,rgba(211,211,211,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d3d3d3', endColorstr='#d3d3d3',GradientType=0 ); /* IE6-9 */
    text-align: center;
    cursor: pointer;
}
.navigationBar ul li a ,
.navigationBar ul li a:hover ,
.navigationBar ul li a:active {
    line-height: 40px;
    color: #000;
    text-decoration: none;
    font-size: 14px;
    font-family: "Open Sans", Helvetica, Arial, sans-serif;
    cursor: pointer;
}

2 个答案:

答案 0 :(得分:1)

希望这会有所帮助。我所做的就是将浮动左侧添加到除帐户之外的所有其他菜单选项...我还在ul元素中添加了填充0以删除论坛前的前导空格..

&#13;
&#13;
    
    .navigationBar {
    width: 100%;
    height: 40px;
    background: #efefef;
    background: -moz-linear-gradient(top,  #efefef 50%, #d3d3d3 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(50%,#efefef), color-stop(100%,#d3d3d3));
    background: -webkit-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: -o-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: -ms-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: linear-gradient(to bottom,  #efefef 50%,#d3d3d3 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#efefef', endColorstr='#d3d3d3',GradientType=0 );
    border-bottom: 2px solid #EB7727;
}
.navigationBar ul {
    list-style: none;
    padding: 0;
}
.navigationBar ul li {
    width: 100px;
    height: 40px;
    background: #efefef;
    background: -moz-linear-gradient(top,  #efefef 50%, #d3d3d3 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(50%,#efefef), color-stop(100%,#d3d3d3));
    background: -webkit-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: -o-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: -ms-linear-gradient(top,  #efefef 50%,#d3d3d3 100%);
    background: linear-gradient(to bottom,  #efefef 50%,#d3d3d3 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#efefef', endColorstr='#d3d3d3',GradientType=0 );
    border-bottom: 2px solid #EB7727;
    text-align: center;
    border-right: 1px solid gray;
    display: table-cell;
    cursor: pointer;
}
.navigationBar ul li:first-child {
    border-left: 1px solid gray;
}

.navigationBar ul li:last-child {
    border-left: 1px solid gray;
}
.navigationBar ul li:hover {
    border-right: 1px solid gray;
    display: table-cell;
    width: 100px;
    height: 40px;
    background: rgb(211,211,211); /* Old browsers */
    background: -moz-linear-gradient(top,  rgba(211,211,211,1) 0%, rgba(239,239,239,1) 50%, rgba(211,211,211,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(211,211,211,1)), color-stop(50%,rgba(239,239,239,1)), color-stop(100%,rgba(211,211,211,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  rgba(211,211,211,1) 0%,rgba(239,239,239,1) 50%,rgba(211,211,211,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  rgba(211,211,211,1) 0%,rgba(239,239,239,1) 50%,rgba(211,211,211,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  rgba(211,211,211,1) 0%,rgba(239,239,239,1) 50%,rgba(211,211,211,1) 100%); /* IE10+ */
    background: linear-gradient(to bottom,  rgba(211,211,211,1) 0%,rgba(239,239,239,1) 50%,rgba(211,211,211,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d3d3d3', endColorstr='#d3d3d3',GradientType=0 ); /* IE6-9 */
    text-align: center;
    cursor: pointer;
}
.navigationBar ul li a ,
.navigationBar ul li a:hover ,
.navigationBar ul li a:active {
    line-height: 40px;
    color: #000;
    text-decoration: none;
    font-size: 14px;
    font-family: "Open Sans", Helvetica, Arial, sans-serif;
    cursor: pointer;
}
.pullRight{
    float:right;
}
.pullLeft{
    float:left;
}
&#13;
<div class="navigationBar">
<ul>
    <li class="pullLeft"><a href="#"><i class="fa fa-comments"></i> Forums</a></li>
    <li class="pullLeft"><a href="#"><i class="fa fa-trophy"></i> Players</a></li>
    <li class="pullLeft"><a href="#"><i class="fa fa-shopping-cart"></i> Shop</a></li>
    <li class="pullRight"><a href="#"><i class="fa fa-user"></i> Account</a></li>
</ul>
</div>
&#13;
&#13;
&#13;

希望这是你想要做的......有一个gr8天

答案 1 :(得分:0)

pullRight

应该是

.pullRight

在CSS文件中