gpt4 book ai didi

html - 居中导航栏div

转载 作者:太空宇宙 更新时间:2023-11-04 10:03:33 27 4
gpt4 key购买 nike

我在高中学习了一点 html 和 css,但在为我的小企业创建网站时遇到了一些麻烦。我已经创建了我的导航栏设计,但我无法将它放在我的包装器中。我当前的代码如下。

body {
background-color: #3393FF;
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, serif;
}
#wrapper {
width: 1300px;
margin-left: auto;
margin-right: auto;
background-color: white;
}
#navigation: {
margin-left: auto;
margin-right: auto;
}
#navigation li {
display: inline-block;
line-height: 40px;
height: 40px;
}
#navigation a {
text-decoration: none;
text-align: center;
color: #fff;
display: block;
width: 204px;
font-size: 15px;
background-color: #3393ff;
}
#navigation a:hover {
-moz-box-shadow: 3px 3px 4px #000;
-webkit-box-shadow: 3px 3px 3px #000;
color: #fff;
}
<html>

<head>
<meta charset="utf-8">
<link rel="stylesheet" href="main.css">
<title>Xcite Technologies</title>
</head>

<body>
<div id="wrapper">
<br>
<div id="navigation">
<ul>
<li><a href="index.html">Home</a>
</li>
<li><a href="aboutus.html">About Us</a>
</li>
<li><a href="services.html">Services</a>
</li>
<li><a href="pricing.html">Pricing</a>
</li>
<li><a href="contact.html">Contact Us</a>
</li>
</ul>
</div>
<br>
<br>
</div>
</body>

</html>

我已经尝试了这里发布的几个不同的东西,但似乎没有任何效果。我相信这将是一个简单的解决方案,并且感觉我正在获得隧道视野。提前感谢您的帮助!

最佳答案

首先从您的 html 代码中删除 BR 这不是使用填充或边距创建垂直空间的坏主意。

body {
background-color: #3393FF;
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, serif;
}
#wrapper {
width: 1300px;
padding: 20px 0 40px;
background-color: white;
}
#navigation {
text-align: center;
}

#navigation ul {
display: inline-block;
padding: 0;
}

#navigation li {
display: inline-block;
line-height: 40px;
height: 40px;
}
#navigation a {
text-decoration: none;
text-align: center;
color: #fff;
display: block;
width: 204px;
font-size: 15px;
background-color: #3393ff;
}
#navigation a:hover {
-moz-box-shadow: 3px 3px 4px #000;
-webkit-box-shadow: 3px 3px 3px #000;
color: #fff;
}
<html>

<head>
<meta charset="utf-8">
<link rel="stylesheet" href="main.css">
<title>Xcite Technologies</title>
</head>

<body>
<div id="wrapper">
<div id="navigation">
<ul>
<li><a href="index.html">Home</a>
</li>
<li><a href="aboutus.html">About Us</a>
</li>
<li><a href="services.html">Services</a>
</li>
<li><a href="pricing.html">Pricing</a>
</li>
<li><a href="contact.html">Contact Us</a>
</li>
</ul>
</div>
</div>
</body>

</html>

希望这有帮助 :D

关于html - 居中导航栏div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38170107/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com