gpt4 book ai didi

html - 导航栏中的中心链接和按钮

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

我想将链接和按钮水平居中,但坦率地说,我不知道该怎么做。非常感谢您的帮助!

我已经尝试过 text-align: center; 但它不起作用。

<nav>
<a href="#">Home</a>
<div>
<button>Products</button>
<div>
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<a href="#">About</a>
</nav>
nav {
overflow: hidden;
background-color: #333;
}

nav a {
float: left;
color: white;
text-align: center;
padding: 15px;
text-decoration: none;
}

nav div {
float: left;
overflow: hidden;
}

nav div button {
line-height: inherit;
border: none;
outline: none;
color: white;
padding: 15px;
font-size: 1em;
background-color: inherit;
font-family: inherit;
margin: 0;
}

nav a:hover, nav div button:hover {
background-color: #222;
}

nav div div {
display: none;
position: absolute;
background-color: #eee;
min-width: 160px;
z-index: 1;
}

nav div div a {
float: none;
color: black;
padding: 12px;
text-decoration: none;
display: block;
text-align: left;
}

nav div div a:hover {
background-color: #ddd;
}

nav div:hover > div {
display: block;
}

最佳答案

请试试这段代码..

CSS

nav {
display: flex;
display: -webkit-flex; *for cross browser*
justify-content: center;
-webkit-justify-content: center; *for cross browser*
}

关于html - 导航栏中的中心链接和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57737584/

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