gpt4 book ai didi

html - 在 Div 中居中水平 UL 导航栏

转载 作者:太空宇宙 更新时间:2023-11-04 12:34:04 25 4
gpt4 key购买 nike

我知道之前有人问过这个问题,但经过几个小时的搜索后,我仍然无法让我的导航栏居中。我对此还是陌生的,但我认为这与我制作导航栏的方式有关,因为我在其他元素中遇到了同样的问题。显示的代码适用于顶部栏,但我也遇到了底部栏的问题。 here是网站。

这是相关代码。

    #topbar {
width: 100%;
height: 140px;
background-color: #6d6e70;
text-align: center;
}

ul.nav1 {
list-style-type: none;
position: absolute;
width: 760px;
border: 3px solid red;
/*FIX CENTER IM LOSING MY MIND*/
top: 35px;
}

li.hnav {
width: 150px;
height: 70px;
float: left;
display: inline;
}

a.hnav {
padding-top: 25px;
display: block;
text-decoration: none;
width: 150px;
height: 45px;
text-align: center;
border-radius: 10px;
transition: all .5s ease;
font-family: Walkway;
font-size: 20px;
font-weight: bold;
color: #fff;
}

a:hover {
background-color: #fff;
color: #6d6e70;
}
    <div id="topbar">
<img src="AandAlogoFINAL1.png" alt="A and A Logo" id="logo">

<ul class="nav1">
<li class="hnav"><a href="index.html" class="hnav">Home</a></li>
<li class="hnav"><a href="about.html" class="hnav">About</a></li>
<li class="hnav"><a href="framing.html" class="hnav">Framing</a></li>
<li class="hnav"><a href="gallery.html" class="hnav">Gallery</a></li>
<li class="hnav"><a href="community.html" class="hnav">Community</a></li>
</ul>

</div>

最佳答案

位置 ul.nav1 相对,给它 margin: 0 autoheight: 77px

enter image description here

#topbar {
width: 100%;
height: 140px;
background-color: #6d6e70;
text-align: center;
}
ul.nav1 {
list-style-type: none;
position: relative;
width: 760px;
border: 3px solid red;
margin: 0 auto;
height: 77px;
}
li.hnav {
width: 150px;
height: 70px;
float: left;
display: inline;
}
a.hnav {
padding-top: 25px;
display: block;
text-decoration: none;
width: 150px;
height: 45px;
text-align: center;
border-radius: 10px;
transition: all .5s ease;
font-family: Walkway;
font-size: 20px;
font-weight: bold;
color: #fff;
}
a:hover {
background-color: #fff;
color: #6d6e70;
}
<div id="topbar">
<img src="AandAlogoFINAL1.png" alt="A and A Logo" id="logo">
<ul class="nav1">
<li class="hnav"><a href="index.html" class="hnav">Home</a>
</li>
<li class="hnav"><a href="about.html" class="hnav">About</a>
</li>
<li class="hnav"><a href="framing.html" class="hnav">Framing</a>
</li>
<li class="hnav"><a href="gallery.html" class="hnav">Gallery</a>
</li>
<li class="hnav"><a href="community.html" class="hnav">Community</a>
</li>
</ul>

</div>

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

25 4 0