我在将内容放在中心位置上有问题
.menuenglish {
overflow: hidden;
background-color: #3c769c;
font-family: Arial;
padding-left: 0px;
}
.menuenglish a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown1 .dropbtn {
cursor: pointer;
font-size: 13px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
}
.dropdown1-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;
}
.dropdown1-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
<div class="hidden-md hidden-lg visible-xs visible-sm">
<div class="menuenglish">
<a href="#">Main Deal </a>
<a href="#" title="E.E.E. Free">E.E.E. Free</a>
<a href="#" title="Perfumes">Perfumes</a>
<div class="dropdown1">
<button class="dropbtn" onclick="myFunction()">More+</button>
<div class="dropdown1-content" id="myDropdown">
<a href="#" title="Mobiles">Mobiles</a>
<a href="#" title="E-cards">E-cards</a>
</div>
</div>
</div>
</div>
最佳答案
从.menuenglish
创建flexbox并使用justify-content: center
。
.menuenglish {
overflow: hidden;
background-color: #3c769c;
font-family: Arial;
padding-left: 0px;
display: flex;
justify-content: center;
}
.menuenglish a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown1 .dropbtn {
cursor: pointer;
font-size: 13px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
}
.dropdown1-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;
}
.dropdown1-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
<div class="hidden-md hidden-lg visible-xs visible-sm">
<div class="menuenglish">
<a href="#">Main Deal </a>
<a href="#" title="E.E.E. Free">E.E.E. Free</a>
<a href="#" title="Perfumes">Perfumes</a>
<div class="dropdown1">
<button class="dropbtn" onclick="myFunction()">More+</button>
<div class="dropdown1-content" id="myDropdown">
<a href="#" title="Mobiles">Mobiles</a>
<a href="#" title="E-cards">E-cards</a>
</div>
</div>
</div>
</div>