Home > OS >  Four Column Layout Not Resizing to Screen Size
Four Column Layout Not Resizing to Screen Size

Time:04-20

I'm trying to add a footer to my website. I used W3schools four-column layout: linked here. When I tried to add the resizing it was not working. I tried to change it from affecting width to color, and that worked, so I know it's not a problem with recognizing screen size or anything with an incorrect class/id name.

.footer {
  padding-top: 10px;
  padding-bottom: 10px;
  width: 100%;
  background-color: #1F363D;
  text-align: center;
  color: white;
}

.footer-column {
  float: left;
  width: 20%;
  height: 100%;
}

@media screen and (max-width: 600px) {
  .footer-column {
    width: 100%;
  }
}

.footer a:link {
  color: white;
  font-size: 12px;
}

.footer a:visited {
  color: white;
}

.footer a:hover {
  color: white;
}

.footer a:active {
  color: white;
}
<div >
  <div style="width:100%; display: flex; justify-content: space-evenly; align-text: center; font-size: 13px;">
    <div >
      <p style="font-size: 15px;">Pages</p>
      <a href="/index.html">Home</a><br>
      <a href="/projects.html">Projects</a><br>
      <a href="/contact.html">Contact</a><br>
      <a href="/about.html">About</a>
    </div>
    <div >
      <p>Projects</p>
      <a href="/projects/mastermind.html">Mastermind</a><br>
      <a href="/projects/simon.html">Simon</a><br>
      <a href="/projects/trivia.html">Trivia</a><br>
    </div>
    <div >
      <p>Column 3</p>
    </div>
    <div >
      <p>Column 4</p>
    </div>
  </div>
  <p style="color: white; text-align: center; font-family: monospace;">© 2022 Jake Poyer</p>
</div>

CodePudding user response:

Remove the second parent with the inline styles and set flex onto the main parent .footer. Then set your .footer-column width to 100% with a media query and you can also instruct the browser to change from the default flex-row to flex-direction: column; at the same breaking point so it uses all available space.

.footer {
  padding-top: 10px;
  padding-bottom: 10px;
  width: 100%;
  background-color: #1F363D;
  text-align: center;
  color: white;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.footer-column {
  width: calc(100%/4);
  height: 100%;
}

@media screen and (max-width: 600px) {
  .footer-column {
    width: 100%;
  }
  .footer {
    flex-direction: column;
  }
}

.footer a:link {
  color: white;
  font-size: 12px;
}

.footer a:visited {
  color: white;
}

.footer a:hover {
  color: white;
}

.footer a:active {
  color: white;
}
<div >
  <div >
    <p style="font-size: 15px;">Pages</p>
    <a href="/index.html">Home</a><br>
    <a href="/projects.html">Projects</a><br>
    <a href="/contact.html">Contact</a><br>
    <a href="/about.html">About</a>
  </div>
  <div >
    <p>Projects</p>
    <a href="/projects/mastermind.html">Mastermind</a><br>
    <a href="/projects/simon.html">Simon</a><br>
    <a href="/projects/trivia.html">Trivia</a><br>
  </div>
  <div >
    <p>Column 3</p>
  </div>
  <div >
    <p>Column 4</p>
  </div>
  <p style="color: white; text-align: center; font-family: monospace; width: 100%;">© 2022 Jake Poyer</p>
</div>

CodePudding user response:

Add flex-wrap: wrap to div with display: flex. also no need to float: left for .footer-column:

.footer {
  padding-top: 10px;
  padding-bottom: 10px;
  width: 100%;
  background-color: #1F363D;
  text-align: center;
  color: white;
}

.footer-column {
  width: 20%;
  height: 100%;
}

@media screen and (max-width: 600px) {
  .footer-column {
    width: 100%;
  }
}

.footer a:link {
  color: white;
  font-size: 12px;
}

.footer a:visited {
  color: white;
}

.footer a:hover {
  color: white;
}

.footer a:active {
  color: white;
}
<div >
  <div style="width:100%; display: flex; flex-wrap: wrap; justify-content: space-evenly; align-text: center; font-size: 13px;">
    <div >
      <p style="font-size: 15px;">Pages</p>
      <a href="/index.html">Home</a><br>
      <a href="/projects.html">Projects</a><br>
      <a href="/contact.html">Contact</a><br>
      <a href="/about.html">About</a>
    </div>
    <div >
      <p>Projects</p>
      <a href="/projects/mastermind.html">Mastermind</a><br>
      <a href="/projects/simon.html">Simon</a><br>
      <a href="/projects/trivia.html">Trivia</a><br>
    </div>
    <div >
      <p>Column 3</p>
    </div>
    <div >
      <p>Column 4</p>
    </div>
  </div>
  <p style="color: white; text-align: center; font-family: monospace;">© 2022 Jake Poyer</p>
</div>

  • Related