【问题标题】:CSS3 navigation bar top menuCSS3导航栏顶部菜单
【发布时间】:2014-05-30 02:10:12
【问题描述】:

我想创建像http://oi61.tinypic.com/345g7wz.jpg这样的导航菜单

但是我发现了一些问题。 li 背景色未连接,在 IE 中显示不同

这是我的代码http://codepen.io/anon/pen/HdzIf

HTML:

<body>
    <header>
        <div class="logo"></div>
        <nav>
            <ul>
                <li><a href="index.html" class="active">Home</a></li>
                <li><a href="about-us.html">About Us</a></li>
                <li><a href="cupcakes.html">Cupcakes</a></li>
                <li class="empty"></li>
                <li><a href="how-to-order.html">How to Order</a></li>
                <li><a href="contact-us.html">Contact us</a></li>
                <li><a href="faq.html">FAQ</a></li>
            </ul>
        </nav>
        <div class="line"></div>
    </header>
</body>

CSS:

body {
    width: 960px;
    margin: 0 auto;
}
header {
    margin: 60px 0 40px;
}
.logo {
    height: 162px;
    width: 162px;
    background-color: #9BD1AF;
    position: absolute;
    top: 5px;
    left: 50%;
    margin-left: -81px;
    z-index: 1;
    -webkit-border-radius: 80px;
    -moz-border-radius: 80px;
    border-radius: 80px;
}
.line {
    width: 100%;
    height: 10px;
    top: 6px;
    position: relative;
    background-color: #7E5A3A;
}
nav {
    width: 100%;
    text-transform: uppercase;
}
nav ul {
    margin: 0;
    padding: 0;
    list-style-type: none;
    text-align: center;
}
nav ul li {
    display: inline;
    background: #2D4C4E;
    padding: 10px 20px;
}
nav ul li.empty {
    padding: 10px 59px;
}
nav ul li a {
    padding: 3px 10px;
    color: #F9EEC6;
    background: #2D4C4E;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    text-decoration: none;
}
nav ul li a:hover {
    background-color: #7E5A3A;
    color: #FFF;
}

我在http://jsfiddle.net/g8SsP/ 发布代码时又发现了新问题 当浏览器的尺寸变窄时,徽标不在我想要的位置

【问题讨论】:

  • 请将您的代码发布到 Stackoverflow,以防 codepen 网站出现故障。
  • 代码已经添加,请见谅

标签: html css navbar


【解决方案1】:
.logo {
height: 162px;
width: 162px;
background-color: #9BD1AF;
position: absolute;
top: 5px;
left: 50%;
margin-left: -81px;
z-index: 1;
-webkit-border-radius: 80px;
-moz-border-radius: 80px;
border-radius: 80px;
}

改成这样:

.logo {
height: 162px;
width: 162px;
background-color: #9BD1AF;
position: relative;
top:68px;
left: 48%;
margin-left: -81px;
z-index: 1;
-webkit-border-radius: 80px;
-moz-border-radius: 80px;
border-radius: 80px;
}

以上是标志一直都在的地方! 现在列表项之间的空间消失:

nav ul li {
display: inline;
background: #2D4C4E;
padding: 10px 20px;
margin-right:-7px; 
}

设置负边距可以解决问题。

【讨论】:

  • 感谢它有效,但我已经使用了另一种方法,将导航栏分为 3 个部分。左侧部分(3 个菜单)、徽标和右侧(另外 3 个菜单)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-06
  • 2018-03-01
  • 2012-10-12
  • 1970-01-01
  • 1970-01-01
  • 2014-01-25
相关资源
最近更新 更多