Div floated left and div floated right causing bac

2019-08-06 04:56发布

I need the footer to have an image floated to the left and some more text (an inline ul with links) floated to the right of the footer.

Here is the CSS & HTML:

footer {
   clear: both;
   background: #113551;
   width: 90%;
   margin: 0 auto;
}
.left-foot {
   float: left;
}
.right-foot {
  float: right;
}
<footer>
   <div class="left-foot">
      <p> derp 1</p>
   </div>

   <div class="right-foot">
      <p>derp2</p>
   </div>
</footer>

It works-ish, however the background color of the footer does not show up. Why not? what is the best way to fix this? It doesn't have to necessarily be exactly like this; I didn't have any luck getting this with position relative and absolute either.

2条回答
smile是对你的礼貌
2楼-- · 2019-08-06 05:16

I was about to write the same as Vitorino Fernandes has written.

However you could also write like given below;

HTML

<footer>
<div>
<p id="p1"> Derp1</p>
<p id="p2> Derp2</p>
</div>
</footer>

CSS

 footer{
    width:100%;
    background: #113551;
    }

    footer > div{
    width:90%;
    margin:auto;
    }

    #p1{
    float:left;
    }
    #p2{
    float:right;
    }

What i have done is that I only used one div as a container of <p>.

查看更多
看我几分像从前
3楼-- · 2019-08-06 05:18

for clearing float use overflow:hidden

demo - http://jsfiddle.net/b0v33rc0/1/

or add a div with styles clear:both before closing tag of the footer

demo - http://jsfiddle.net/b0v33rc0/2/

查看更多
登录 后发表回答