我试图将导航栏居中,而不会丢失多余的导航栏。我的意思是我希望导航栏显示在整个屏幕上,但导航栏中的文本居中。我发现如果我将SS中的ul {}的宽度更改为...... 28%,则它会在屏幕上居中。但是我希望将它保持在100%,以便我在整个顶部都有导航栏。如何在导航栏中居中文本?
ul {
list-style-type: NONE;
margin: auto;
padding: 0;
width: 100%;
background-color: #449DA2;
text-align: center;
font-size: 15px;
height: 100%
position: fixed;
overflow: auto;
}
<!DOCTYPE html>
<html>
<head>
<body bgcolor=black>
<style>
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 24px 30px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: gray;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: White;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
<link rel="stylesheet" href="style.css">
</head>
<body>
<ul>
<li class="dropdown"><a href="#home">Info Page</a></li>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">East</a>
<div class="dropdown-content">
<a href="#">Maryland</a>
<a href="#">Massachusetts</a>
<a href="#">New England</a>
<a href="#">New Jersey</a>
<a href="#">Pennsylvania</a>
<a href="#">Virginia</a>
<a href="#">Washington D.C.</a>
</div>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">Central</a>
<div class="dropdown-content">
<a href="#">Illinois</a>
<a href="#">Indiana</a>
<a href="#">Michigan</a>
<a href="#">Minnesota</a>
<a href="#">Texas</a>
</div>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">South</a>
<div class="dropdown-content">
<a href="#">Atlanta</a>
<a href="#">Bowling Green</a>
<a href="#">Charleston</a>
<a href="#">Chattanooga</a>
<a href="#">Jackson</a>
<a href="#">Memphis</a>
<a href="#">Miami</a>
<a href="#">Nashville</a>
<a href="#">Panama</a>
<a href="#">Sarasota</a>
<a href="#">Savannah</a>
<a href="#">Tallahassee</a>
<a href="#">WPB</a>
</div>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">West</a>
<div class="dropdown-content">
<a href="#">California</a>
<a href="#">Colorado</a>
<a href="#">New Mexico</a>
<a href="#">Utah</a>
<a href="#">Washington</a>
</div>
</li>
</ul>
</body>
</html>
答案 0 :(得分:0)
您需要在代码中更改的唯一内容是typedef std::function<bool(int)> myFunctor;
的规则:删除li
并添加float: left;
,然后display: inline-block
设置text-align: center
将变得有效:
ul
body {
background: black;
}
ul {
list-style-type: NONE;
margin: auto;
padding: 0;
width: 100%;
background-color: #449DA2;
text-align: center;
font-size: 15px;
height: 100% position: fixed;
overflow: auto;
}
li {
display: inline-block;
}
li a,
.dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 24px 30px;
text-decoration: none;
}
li a:hover,
.dropdown:hover .dropbtn {
background-color: gray;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: White;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}