我想知道如何将测试与导航栏的中间对齐。我的代码如下:
body {
font-family: 'Arial', sans-serif;
background-color: #f3f3f3;
overflow-x: hidden;
}
.navbar {
overflow: hidden;
background-color: #333;
font-family: Arial, Helvetica, sans-serif;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: red;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="navbar">
<a href="#home">Home</a>
<div class="dropdown">
<button class="dropbtn">Games <i class="fa fa-caret-down"></i></button>
<div class="dropdown-content">
<a href="#">Badge</a>
<a href="#">Undead Nightmare</a>
<a href="#">All Games</a>
</div>
</div>
<a href="#">Videos</a>
<a href="#">Newswire</a>
<a href="#">Social Club</a>
<a href="#">Downloads</a>
<a href="#">Warehouse</a>
<a href="#">Support</a>
</div>
</div>
Nav Bar
我尝试使用display: inline-block
,尝试删除float: left
。我在.navbar a
下面尝试了所有其他方法,还尝试了其他方法,但仍然无法居中。
任何帮助将不胜感激,并在此先感谢您。