html - 如何垂直对齐父div中的子div?

标签 html css alignment vertical-alignment

所以我有 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/

相关文章:

javascript - 我可以关注动态加载的 AJAX 元素吗?

html - CSS:IE8 与 World(Firefox、Chrome、Safari)

javascript - 如何在到达字母 A 时停止左键?

html - ie8 在第一页加载或刷新时不呈现@font-face 字体

css - 如何将 CSS3 解析器与 HtmlUnitDriver 一起使用

javascript - 使用 CSS 跨浏览器 div 居中对齐

c++ - 如何在 Qt 5.1.0 中将主窗口对齐到屏幕的右侧

html - 水平和垂直居中按钮

html - 我的样式表无法在 Firefox 中正确加载

jquery - 使用 CSS 和 JQuery 在页面之间创建滑动