Friday, 9 June 2017

css - Is it necessary to use an end tag with for clearing floats?





When using a DIV element with a style of clear:both to clear a previous float, is it necessary to use a start and end tag to the DIV element? Here is an example ...



Is this OK?







or should it be this?





Answer



You need the closing tag, or browsers will not think the tag is closed.




However, why would you even want to use

? That involves adding an extra unsemantic div for no reason.



There are better ways to contain/clear floats:




  • Use overflow: hidden on the the element that contains your floats.

  • Or, use a clearfix such as the "micro clearfix".


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...