Duane
Duane

Reputation: 3

Trouble centering CSS columns

I have a three column box in css, I need it to center on the page for the desktop and then stack the columns on top of each other in 600px or less. I have everything working except having it centered on the desktop view.

I have tried adding justify-content: relative, adding a wrapper align: center and a couple other lines of code that did not work. Any help is greatly appreciated.

Here is the code I currently have:

* {
  box-sizing: border-box;
}


/* Create three equal columns that floats next to each other */

.column {
  float: left;
  width: 178px;
}


/* Clear floats after the columns */

.row:after {
  content: "";
  display: table;
  clear: both;
}


/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */

@media screen and (max-width: 600px) {
  .column {
    width: 100%;
  }
}
<p align="center">
  <font size="5" color="336699"><strong>Great American Song Contest</strong></font>
</p>
<p align="center">
  <font size="3" color="a91e21"><strong>3 Easy Ways To Enter Your Songs</strong></font>
</p>

<div class="wrapper">
  <div class="row">
    <div class="column">

      <p>
        <a href="https://www.greatamericansong.com/newsite-backup/Form-Prepage.php/"><img src="https://www.greatamericansong.com/newsite-backup/images/submit-online.gif" alt="" width="178" height="158"></p>
    </div>
    <div class="column">

      <p>
        <a href="https://www.greatamericansong.com/newsite-backup/Entry-Direct.php/"><img src="https://www.greatamericansong.com/newsite-backup/images/submit-email.gif" alt="" width="178" height="158"></p>
    </div>
    <div class="column">

      <p>
        <a href="https://www.greatamericansong.com/newsite-backup/entry-mail.php/"><img src="https://www.greatamericansong.com/newsite-backup/images/submit-mail.gif" alt="" width="178" height="158"></a>
      </p>
    </div>
  </div>
</div>

<div align="center"> <img src="//shield.sitelock.com/shield/greatamericansong.com" id="sl_shield_image" style="cursor: pointer;" alt="SiteLock" align="middle" />
  <script id="sl_shield" type="text/javascript" src="//shield.sitelock.com/sitelock.js" language="javascript"></script>
</div>
<p align="center">


  <p></p>
  <p align="center"><strong>* WRITERS RETAIN ALL RIGHTS TO THEIR SONGS, LYRICS & COMPOSITIONS *</strong></p>

  <p>
    <font size="3" color="a91e21"><strong>2021 Rules & Entry:</strong></font>
  </p>

  <p>The Great American Song Contest is open to songwriters, lyricists & music composers worldwide.</p>

  <p align="center"><strong>* WRITERS RETAIN ALL RIGHTS TO THEIR SONGS, LYRICS & COMPOSITIONS *</strong></p>

Upvotes: 0

Views: 201

Answers (1)

Johannes
Johannes

Reputation: 67776

Apply a dedicated class to the parent of those columns (in my example: class="x"), use display: flex; and justify-content: center on that, and in the media query change it to flex-direction: column (t place them below each other) and align-items: center; (to center them). And forget the floats...

* {
  box-sizing: border-box;
}
.column {
  width: 178px;
}

.x {
display: flex;
justify-content: center;
}

@media screen and (max-width: 600px) {
  .x {
    flex-direction: column;
    align-items: center;
  }
}
<p align="center">
  <font size="5" color="336699"><strong>Great American Song Contest</strong></font>
</p>
<p align="center">
  <font size="3" color="a91e21"><strong>3 Easy Ways To Enter Your Songs</strong></font>
</p>

<div class="wrapper">
  <div class="x">
    <div class="column">

      <p>
        <a href="https://www.greatamericansong.com/newsite-backup/Form-Prepage.php/"><img src="https://www.greatamericansong.com/newsite-backup/images/submit-online.gif" alt="" width="178" height="158"></p>
    </div>
    <div class="column">

      <p>
        <a href="https://www.greatamericansong.com/newsite-backup/Entry-Direct.php/"><img src="https://www.greatamericansong.com/newsite-backup/images/submit-email.gif" alt="" width="178" height="158"></p>
    </div>
    <div class="column">

      <p>
        <a href="https://www.greatamericansong.com/newsite-backup/entry-mail.php/"><img src="https://www.greatamericansong.com/newsite-backup/images/submit-mail.gif" alt="" width="178" height="158"></a>
      </p>
    </div>
  </div>
</div>

<div align="center"> <img src="//shield.sitelock.com/shield/greatamericansong.com" id="sl_shield_image" style="cursor: pointer;" alt="SiteLock" align="middle" />
  <script id="sl_shield" type="text/javascript" src="//shield.sitelock.com/sitelock.js" language="javascript"></script>
</div>
<p align="center">


  <p></p>
  <p align="center"><strong>* WRITERS RETAIN ALL RIGHTS TO THEIR SONGS, LYRICS & COMPOSITIONS *</strong></p>

  <p>
    <font size="3" color="a91e21"><strong>2021 Rules & Entry:</strong></font>
  </p>

  <p>The Great American Song Contest is open to songwriters, lyricists & music composers worldwide.</p>

  <p align="center"><strong>* WRITERS RETAIN ALL RIGHTS TO THEIR SONGS, LYRICS & COMPOSITIONS *</strong></p>

Upvotes: 1

Related Questions