html - 在导航栏上定位

标签 html css

我制作了一个导航栏,上面有一些链接和一个标题,就像 Bootstrap 一样,但我正在努力使帐户下拉列表位于右侧,但是当我添加类“pullRight”时,它会移动它向右但不停留在导航栏上。

Screenshot

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

最佳答案

希望这对您有所帮助。我所做的只是将 float left 添加到除帐户之外的所有其他菜单选项中...我还在 ul 元素中添加了 padding 0 以删除论坛之前的前导空格..

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

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

关于html - 在导航栏上定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26392874/

相关文章:

html - Bootstrap 按钮在页面变小时换行

javascript - 为什么我的复选框没有与我的 jQuery 连接?

javascript - 链接和按钮未触发

css - 这个网站如何做悬停效果?

javascript - 具有固定大小列的响应式网格

html - 用户无法访问但网络服务器可以访问的文件夹

jquery - 将src文件动态插入音频标签,并将src名称存储在html代码中

php mysql fetch语句获取问题

javascript - 网络 worker 是绿色的还是红色的?

javascript - 如何让内容滚动而不超过我的标题?