Cannot get the footer div to clear the two floated divs


#1

Hi,

I can't seem to get the footer div to clear the two floated divs in this exercise no matter what I do. If I understood the instructional material correctly, it should be possible to get the footer to sit below those two divs without relying on a "top" property. Please help! Thank you :smile:

HTML:

<!DOCTYPE html>
<html>
<head>
	<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
	<title></title>
</head>
<body>
    <div id="header"></div>
    <div class="left"></div>
    <div class="right"></div>
    <div id="footer"></div>
</body>
</html>

CSS:

    div {
      border-radius: 5px;
  }

  #header {
      background-color: #4499ff;
      height: 90px;
      width: 100%;
      position: fixed;
      z-index: 1;
      top: 0;
      left: 0;
      margin: 0;
      padding: 0;
  }

  .left {
      background-color: #cef;
      height: 550px;
      width: 24%;
      position: relative;
      top: 85px;
      margin-top: 0px;
      float: left;
      display: inline-block;
  }

  .right {
      background-color: #eee;
      height: 550px;
      width: 74%;
      margin-left: 3px;
      position: relative;
      top: 85px;
      margin-top: 0px;
      float: right;
      display: inline-block;
  }

  #footer {
      background-color: #aaa;
      height: 60px;
      width: 100%;
      position: relative;
      padding:0.5px;
      clear: both;
      display: inline-block;
    }

#2

i made a few small changes to your code, you can find it in this bin.

Because you use top: 85px to both .left and .right, .left and .right are 85px down from where they would normally mean, this mean the #footer is cleared of .left and .right, but left and right moved, so the footer is 85px to high, now there are two ways you can solve this: add top: 85px to #footer, or change top: 85px to margin-top: 85px in both .left and .right

One thing i do not understand, is why you used display: inline-block on .left, .right and #footer, i removed it in the bin


#3

That works, thanks so much! I was messing with the display properties because I didn't really understand how they worked. Clearer now. Thanks again.


#4

you're welcome, feel free to ask if you have any questions regarding resume/what next/positioning/display