【发布时间】:2016-08-21 08:03:20
【问题描述】:
我遇到的问题是,在我的小型测试网站上,我无法让导航栏居中。 我希望所有按钮居中,而导航栏从网站的右侧移动到左侧。我有没有固定宽度,不想拥有一个。该解决方案应该也适用于智能手机和平板电脑,并且只是提一下:我并不真正关心 IE 支持。 我已经在网上搜索了一些,但没有任何我尝试过的工作。
这是我已经得到的代码:
<header class="navigation">
<nav>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#download">Download</a></li>
<li><a href="#contact">Contact</a></li>
<!-- Maybe the navigation bar gets more buttons in the future. -->
</ul>
</nav>
<h1>Test Test Test</h1>
</header>
这是 CSS 代码:
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border-radius: 5px;
background-color: #333333;
}
li { float: left; }
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
border-bottom: none;
}
li a:hover { background-color: #111111 }
我正在使用 HTML5 和 CSS3。
编辑:似乎我对按钮不够清楚。按钮不应与导航栏本身一样大。所有的按钮都应该在导航栏的中心,所以中间是按钮,左右两边只有黑色的导航栏,如果有足够的空间,当然是没有按钮的。
【问题讨论】:
标签: html css web mobile-website navigationbar