我正在尝试创建一个下拉菜单,其中与父级相比,子级居中对齐。
我已经尝试过设置margin: auto;
或设置left: -50%; right: -50%
以及我在网上找到的其他解决方案,但似乎没有什么对我有用。
我怎样才能做到这一点?
.header {
/*background-image: url("../images/top_menu.png");*/
width: 100%;
background-repeat: no-repeat;
background-position: left top;
background-attachment: fixed;
position: fixed;
top: 0;
background-origin: border-box;
height: 68px;
}
ul {
list-style-type: none;
margin: 0;
padding-left: 5%;
padding-top: 15px;
padding-bottom: 10px;
overflow: hidden;
display: inline-block;
}
li {
float: left;
}
li a,
.dropbtn {
display: inline-block;
color: #000;
text-align: center;
padding: 8px 10px;
text-decoration: none;
background-color: #fff;
margin: 5px;
border-radius: 30px;
min-width: 160px;
}
li a:hover,
.dropdown:hover .dropbtn {
background-color: black;
color: white;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
text-align: center;
}
.dropdown-content a {
color: #e6e6e6;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: center;
background-color: #333333;
}
.dropdown-content a:hover {
background-color: #e6e6e6;
color: #333333;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="header">
<ul class="drop_menu">
<li class="dropdown">
<a href='#' class="dropbtn">Products</a>
<div class="dropdown-content">
<a href='auto_tender_commercial.html'>Link 1</a>
<a href='fruit_series.html'>Link 2</a>
<a href='smart_sensors.html'>Link 3</a>
</div>
</li>
<li class="dropdown">
<a href='#' class="dropbtn">Bar Service Packages</a>
<div class="dropdown-content">
<a href='what_is_it.html'>Really long long long long long long long link</a>
<a href='what_is_it.html'>Link 4</a>
<a href='leasing_plan.html'>Link 5</a>
</div>
</li>
<li><a href='event_leasing.html'>Event Leasing</a></li>
</ul>
</div>