使我的导航栏居中,我已经尝试了一切

时间:2013-07-30 14:23:01

标签: html css navigation uinavigationbar center

好的,所以我正在为我的客户网站导航栏尝试一种不同的技术,我完全不知道为什么它不会居中。我也想让它缩小页面的大小。我通常使ul宽度= 100%,但是当我在这里做的时候,它会让我的链接转到下一行,而后面没有图像。我的想法是将其修复,以便当人们滚动页面时它总是存在。

HTML

<div class="menu_wrap">
<div class="menu_links">
  <ul>
    <li><a class="first" href="home.html">Home</a></li>
    <li><a href="about.html">About Us</a></li>
    <li><a href="start.html">Getting Started</a></li>
    <li><a href="contact.html">Contact Us</a></li>
    <li>
      <n><img src="img/logobar.jpg" width="250" height="150"/></n>
    </li>
    <li><a href="faqs.html">FAQ's</a></li>
    <li><a href="testimonials.html">Testimonials</a></li>
    <li><a href="links.html">Links</a></li>
    <li><a href="gallery.html">Gallery</a></li>
  </ul>
</div>
</div>

CSS

    /* start of navbar */


    .menu_wrap {
        float:left;
        z-index: 60;
        width: 100%;
        height: 69px;
        background-image: url(img/lw.jpg); 
        background-repeat:repeat;
        box-shadow: 0px 2px 5px #000000;
        position: fixed;
        margin-top:40px;
    }

    .menu_links ul {
        width: 100%;
        height: 92px;
        list-style: none;
        box-shadow: 0px 2px 5px #000000;
    }
    .menu_links ul li {
        display: inline;
        float:left;
        height: 92px;
    }
    .menu_links ul li n{
        font-family: "Brush Script MT";
        font-weight: normal;
        font-size: 41px;
        color: #FFF;
        line-height: 1.2em;
        letter-spacing: -.0.03em;
        margin-top: -40px;
        text-align:center;
        text-decoration: none;
        box-shadow: 0px 2px 5px #000000;
        display: block;
        border-right-width: 1px;
        border-right-style: solid;
        border-right-color:#000;

    }
    .menu_links ul li a {
        float:left;
        margin-top: 0px;
        line-height: 70px;
        padding-right: 20px;
        padding-left: 20px;
        color:#FFF;
        font-weight:900;
        font-size: 12px;
        text-decoration: none;
        text-shadow: -1px -1px 1px #333;
        border-right-width: 1px;
        border-right-style: solid;
        border-right-color:#000;
        display:inline-block;
    }


    .menu_links ul li a:hover {
        color:#CCC;
        text-shadow: -1px -1px 1px #EEE;
        background-image: url(img/navbar.png);
        background-position: center;

    }
    .menu_buttons {
        float:right;
        line-height: 50px;
        height: 50px;
        margin-right: 30px;
    }
    .menu_buttons ul {
        margin: 0px;
        padding: 0px;
        list-style-type: none;
    }
    .menu_buttons ul li {
        display: inline;
        height: 50px;
    }
    .menu_buttons ul li a {
        float:left;
        padding-right: 10px;
        display: block;
        border:none;
        line-height: 50px;
        padding-left: 10px;
        height: 50px;
        padding-top: 10px;
         }

    .first {
        border-left-width: 1px;
        border-left-style: solid;
        border-left-color:#000;
    }

    .menu_links {
        height: 50px;
        float: left;
        margin-left: 0px;
    }
    /*end of navbar */

我会给你一个指向该页面的链接,但它是在Dreamweaver中完成的,但尚未启动。 logobar.jpg是网页的标志。我喜欢它的样子,但是当我缩小屏幕尺寸时,它需要居中并且不会被切断或被带到下一行。

我尝试过的事情是

浮动:几乎所有类都是右,左,无 text-align:每个班级的中心 在html方面,我已经尝试了对每个类的align = center 显示:ul和li类的内联,内联块

不,我实际上没有放浮动:右,左,没有。我一个接一个地做了它们并使用了float:right;。向左飘浮;。然后浮动:无;

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

浮动容器不容易居中。每当我面对任何浮动的容器水平居中时,我都会使用以下内容。尝试使用以下内容包装您的标记(需要将其置于中心; div.menu_links):

<div class="center_outer">
    <div class="center_inner">
        <!-- Put your contents here (which needs to be centered) -->
    </div>
</div>

CSS:

.center_outer
{
    position: relative;
    left: 50%;
    float: left;
}
.center_inner
{
    position: relative;
    left: -50%;
}

答案 1 :(得分:0)

在页面上居中元素的一种绝妙方式是在您想要居中的元素上使用:

margin:0 auto;
。例如:

HTML:

<div id="wrap">
    <ul>
         <!-- *list items here* -->
    </ul>
</div>

CSS:

#wrap {
    width:100%;
}

#wrap ul {
    width:960px; /* or however wide you'd like your menu */
    margin:0 auto;
}

我在http://jsfiddle.net/m65rr/设置了一个演示小提琴。希望这会有所帮助。

相关问题