Search code examples
htmlcssalignmentvertical-alignment

How to vertically align the child divs in a parent div?


So I have 1 parent div and 4 child divs. I have horizontally aligned those child divs in the parent div, however they are not vertically aligned, it's like a graph the way the child divs are placed. How do I vertically align them?

.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>


Solution

  • Try this

     #lists {
                      display: inline-block;
                      text-align: center;
                      padding: 5px;
                      margin: 5px;
                      border: 1px solid blue;
                      height: 190px;
                 vertical-align: middle;
                    }