我在制作导航栏时遇到了一些麻烦。我希望它看起来像我在这里的模型 - https://www.dropbox.com/s/xc01i4ncy7nj66y/home.PNG
我想在不使用边距的情况下居中,因为某些元素似乎没有响应边距编辑。问题是当我试图保持按钮之间的间距(白色分隔线),但也使导航栏居中时,会出现各种奇怪的格式问题。
这是我的HTML -
<!DOCTYPE html>
<html>
<head>
<title>AB Portfolio</title>
<link type="text/css" rel="stylesheet" href="reset.css">
<link type="text/css" rel="stylesheet" href="style.css">
</head>
<body>
<div id = "FalseHeader">
<header>
<nav class="main">
<ul>
<li><a href"">Work</a></li>
<li><a href"">About</a></li>
<li><a href"">Contact</a></li>
</ul>
</nav>
</header>
</div>
<div id="container">
<div id="gallery">
</div>
</div>
</body>
</html>
和我的css
*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
body{
font-family: Futura, "Trebuchet MS", Arial, sans-serif;
background-color: white;
color: #fff;
}
#FalseHeader{
width: 100%;
height:30px;
margin-top:100px;
background-color: #000;
}
header {
width: 960px;
margin-right: auto;
margin-left: auto;
}
nav.main {
height: 30px;
margin-top:100px;
margin-right: auto;
margin-left: auto;
background-color: green;
}
/*nav.main ul{
height: 30px;
width: 500px;
display: inline;
background-color: red;
}
*/
nav.main ul li{
height: 30px;
width: 250px;
display: inline-block;
position: relative;
padding: 15px;
background-color: #000;
}
nav.main ul li a{
text-decoration: none;
transition: all 0.2s;
-moz-transtion: all 0.2s;
-webkit-transition: all 0.2s;
}
nav.main ul li a:hover {
color: #A1A8B2;
}
#container{
width: 100%;
margin: auto;
}
#gallery{
height: 500px;
width: 100%;
background-image: -webkit-gradient(
linear,
left top,
left bottom,
color-stop(0, #3D64B8),
color-stop(1, #1A4C8C)
);
background-image: -o-linear-gradient(bottom, #3D64B8 0%, #1A4C8C 100%);
background-image: -moz-linear-gradient(bottom, #3D64B8 0%, #1A4C8C 100%);
background-image: -webkit-linear-gradient(bottom, #3D64B8 0%, #1A4C8C 100%);
background-image: -ms-linear-gradient(bottom, #3D64B8 0%, #1A4C8C 100%);
background-image: linear-gradient(to bottom, #3D64B8 0%, #1A4C8C 100%);
}
感谢
答案 0 :(得分:0)
为ul标签指定一些对齐
ul{
text-align: center;
display: inline;
}
如果您不想使用保证金在每个按钮之间留出空格,则可以使用白色边框。