If a div has “clear:right”, nothing should float to the right of it, should it?

前端 未结 5 1867
暗喜
暗喜 2021-02-15 11:04

I seem to have gotten confused as to what the css \"clear\" keyword means.

I have a number of div elements, all with \"float:left\". The second last div element also has

相关标签:
5条回答
  • 2021-02-15 11:43

    There isn't anything floating to the right of it. The Problem you're facing is that you already sent all your content prior to the time, and then you're telling the time to float to the left. It's still floating to the left, it's just stacking on top of the content that's already there to the left.

    But yes, clearing to the right makes that element break down past all elements which are floated to the right before it. Clear does not affect elements after it.

    Have you tried using a simple <br /> after your title?

    0 讨论(0)
  • 2021-02-15 11:53

    The clear property doesn't prevent elements from being placed in that space after the cleared element. It prevents the element from being placed where there are already elements floated to the that direction before it. Adding a clear:left to div.Duration would make it be placed below the navy box. Adding a <br/> before the duration might solve your problem, or, as you already said in your question, you could use another container div for the last three divs.

    0 讨论(0)
  • 2021-02-15 11:55

    ahruss's answer is the correct one, but I also noticed no one really answered your question. Basically clear:left refers to left floating elements. clear:right refers to right floating elements.

    Since your element is floating left, not right, clear:right won't affect it.

    The other thing you could do is wrap the two text elements in a separate div from the blue box, float that container div in and the blue div, then when you float the two text elements, your clear:left code will put the date under the text still within your container div and not under the blue image to it's left.

    Like this:

    <div class="Section">
       <div class="Thumbnail"></div>
       <div class="TextContainer">
          <div class="Number">0</div>
          <div class="Title">ShopTVC Wallace and Gromit WOA 6Apr11</div>
          <div class="Duration">00:00:32</div>
       </div>
    </div>
    

    and add this to your css:

    div.TextContainer {
       float:left;
    }
    

    Add in whatever other visual styles you need.

    0 讨论(0)
  • 2021-02-15 11:59

    I have used padding and margin. If it is not possible to use in your case then the following solution will not be appropriate.

    http://jsfiddle.net/8J7V6/5/

    0 讨论(0)
  • 2021-02-15 12:04

    .Duration { clear: left; } should work

    0 讨论(0)
提交回复
热议问题