Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 796
CodeIsLaw Avatar asked Jun 09 '26 12:06

CodeIsLaw


2 Answers

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>
like image 54
CookieJarApps Avatar answered Jun 12 '26 01:06

CookieJarApps


You can do it using flex properties of CSS and I have added snippet below. Please check :

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*/
            flex-direction: row;
            justify-content: space-between;
            align-items: flex-start;
          }

          .footer-items .company-items, .footer-items .social-items, .footer-items .other-items {
            display: block;
            width: 100%;
            text-align: left;
          }
    <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> 
like image 41
Himanshu Joshi Avatar answered Jun 12 '26 02:06

Himanshu Joshi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!