所以我有 1 个父 div 和 4 个子 div。我在父 div 中水平对齐了这些子 div,但是它们没有垂直对齐,这就像子 div 放置方式的图表。 如何垂直对齐它们?
.servicesContent {
border: solid red 2px;
font-family: arial;
width: 70%;
margin: 0 auto;
}
.servicesH1 {
text-align: center;
color: #3a414e;
}
.servicesContent h2 {
color: #3a414e;
}
#h3 {
color: #3a414e;
}
.contentLists {
border: solid green 2px;
width: 100%;
text-align: center;
}
#lists {
display: inline-block;
text-align: center;
padding: 5px;
margin: 5px;
border: 1px solid blue;
height: 190px;
}
<div class="servicesContent">
<h1 class="servicesH1">Services</h1>
<h2>Help!</h2>
<p>Child Divs are not vertically aligned</p>
<p>Help</p>
<div class="contentLists">
<div id="lists">
<h3 id="h3">first</h3>
<ul>
<li>afasasf</li>
<li>fasfsafas</li>
</ul>
</div>
<div id="lists">
<h3 id="h3">second</h3>
<ul>
<li>gdagadg</li>
<li>agadgadg</li>
</ul>
</div>
<div id="lists">
<h3 id="h3">third</h3>
<ul>
<li>dsfdsfs</li>
</ul>
</div>
<div id="lists">
<h3 id="h3">fourth</h3>
<ul>
<li>dagadg</li>
<li>agadgdhtjrs</li>
<li>jjee</li>
<li>ejtejtjejejgfhdgh</li>
<li>Gtejjtejejtds</li>
</ul>
</div>
</div>
最佳答案
试试这个
#lists {
display: inline-block;
text-align: center;
padding: 5px;
margin: 5px;
border: 1px solid blue;
height: 190px;
vertical-align: middle;
}
关于html - 如何垂直对齐父div中的子div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38698735/