gpt4 book ai didi

html - 无法在标题图片下对齐导航栏

转载 作者:太空宇宙 更新时间:2023-11-03 23:17:44 24 4
gpt4 key购买 nike

我已经尝试了 2 个小时以将导航栏很好地对齐在标题图像下方,但它就是行不通。前 4 个列表项排成一行,但最后一个在它们下面,+导航栏没有像我希望的那样居中。我到处寻找答案,但没有任何效果。帮助将不胜感激。附:我是 css 和 html 的新手,所以要温柔。

<html>
<head>
<style>
body {
background-image: url("http://i.imgur.com/SwKXk23.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
body {
margin: 0;
}
.header {
width: 100%;
height: auto;
background-color: none;
padding-top: 24px;
}
.headerContent {
width: 1024px;
height: auto;
margin: 0 auto;
}
.headerContent a img {
width: 659px;
height: 144px;
margin: 0px auto;
display: block;
}
.nav {
width:750px;
margin:0 auto;
list-style:none;
}
.nav li {
float:left;
}
.nav a {
display:block;
text-align:center;
width:150px; /* fixed width */
text-decoration:none;
}
.nav ul li{
height: 40 px;
background: #A14F53;
}
.nav ul li{
list-style-type: none;
width: 150px;
float: left;
}
.nav ul li a{
text-decoration: none;
color: black;
line-height: 40px;
display: block;
border-right: 1px solid #CCC;
text-align:center;
}
.nav ul li a:hover{
background-color:#F9C1B5;
}
.headerBreak{
width: 100%;
height: o%;
border bottom: 2px solid #128e75;
}

</style>
</head>

<body>
<div class="background">
<div class="header">
<div class="headerContent">
<a href="#">
<img style="border:0;width:900px;height:250px;" alt=""
title="" src="http://i.imgur.com/5NhCbxu.png">
</a>
</div>
<div class="nav">
<ul id="nav">
<li><a href="Pagina principala.html">Pagina principala</a></li>
<li><a href="Despre noi.html">Despre noi</a></li>
<li><a href="Clienţii noştri.html">Clientii nostri</a></li>
<li><a href="Produse.html">Produse</a></li>
<li><a href="Contacte.html">Contacte</a></li>
</ul>
</div>
</div>
<div class="headerBreak"></div>
</div>
</body>
</html>

最佳答案

您没有给导航栏足够的宽度。更改 .nav 规则:

.nav {
width:750px; <------- adjust this
margin:0 auto;
list-style:none;
}

我将您的宽度从 750 像素更改为 800 像素,现在菜单适合一行并居中。

这是一个 fiddle :https://jsfiddle.net/macg14fs/

关于html - 无法在标题图片下对齐导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29834696/

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