Search code examples
htmlcssmarginfooterlistitem

css margin: auto issue in footer


My problem is to split the space inside my footer bar in 3 part (each with same width)

footer {
  width: 100%;
  /*breite: 100%*/
  padding: 0;
  margin: 0;
  background-color: darkcyan;
  /*Hintergrundfarbe*/
  margin-bottom: 0;
  bottom: 0;
}

.footer-items {
  width: 80%;
  margin: auto;
  display: flex;
  /*bringt alle Teile in eine Linie*/
  text-align: center;
  /*zentriert ganzen Text im footer*/
}
<div class="footer-items">

  <div class="company-items">
    <h3 class="company">Company</h3>
    <ul>
      <li><a href="text1.html">Text1</a></li>
      <li><a href="text2.html">Text2</a></li>
      <li><a href="text3.html">Text3</a></li>
    </ul>
  </div>

  <div class="social-items">
    <h3 class="social">Social</h3>
    <ul>
      <li><a>Twitter</a></li>
      <li><a>Instagram</a></li>
      <li><a>Reddit</a></li>
    </ul>
  </div>

  <div class="other-items">
    <h3 class="text">Text4</h3>
    <ul>
      <li><a>other1</a></li>
      <li><a>other2</a></li>
    </ul>
  </div>

</div>

If I try to do sth like margin-left: 33% for my 3 items in footer this is not gonna work.

thanks for your help


Solution

  • Try using width: 33.33% instead of margin-left: 33% and apply the class to each third of the footer. This will split the footer into 3 columns:

    .footer {
      width: 100%;
      /*breite: 100%*/
      padding: 0;
      margin: 0;
      background-color: darkcyan;
      /*Hintergrundfarbe*/
      margin-bottom: 0;
      bottom: 0;
    }
    
    .footer-column {
      float: left;
      width: 33.33%;
    }
    <div class="footer">
    
      <div class="footer-column">
        <h3 class="company">Company</h3>
        <ul>
          <li><a href="text1.html">Text1</a></li>
          <li><a href="text2.html">Text2</a></li>
          <li><a href="text3.html">Text3</a></li>
        </ul>
      </div>
    
      <div class="footer-column">
        <h3 class="social">Social</h3>
        <ul>
          <li><a>Twitter</a></li>
          <li><a>Instagram</a></li>
          <li><a>Reddit</a></li>
        </ul>
      </div>
    
      <div class="footer-column">
        <h3 class="text">Text4</h3>
        <ul>
          <li><a>other1</a></li>
          <li><a>other2</a></li>
        </ul>
      </div>
    
    </div>