导航栏中的居中项 [英] Centering Items within Navigation Bar

查看:103
本文介绍了导航栏中的居中项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使导航项居中,但是没有运气.每个解决方案都将我的导航栏从以下位置:水平导航栏变为:垂直导航栏.

I've been trying to center the items within the navigation but no such luck. Every single solution turns my navigation bar from this: horizontal navigation bar to this: vertical navigation bar.

任何帮助将不胜感激!

带有CSS代码的HTML:

HTML with CSS code:

ul {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
  text-align: center;
}

li {

  float: left;   

}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 10px 10px;
  text-decoration: none;
}

li a:hover {
  background-color: #111;
}

<html>
  <head>
  </head>
  <body>

    <ul>
      <li><a class="active" href="#home">Home</a></li>
      <li><a href="#news">News</a></li>
      <li><a href="#contact">Contact</a></li>
      <li><a href="#about">About</a></li>
    </ul>

  </body>
</html>

推荐答案

我用float删除了 li 标记上的css,并将其更改为显示和宽度:

I removed your css on li tag with float and changed it to display and width:

li {
display: -webkit-inline-box;
width: 60px;

}

https://i.stack.imgur.com/LbYd4.png `

我希望这对您有所帮助.拉各斯

I hope this helped you @C. Lagos

这篇关于导航栏中的居中项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆