Is using <div> spacers a bad practice? [closed]
Is it a bad practice to use <div>开发者_JAVA技巧;
tags to express gaps between elements? If yes - why is it so?
Here's an example:
<div class="panel">
<!-- Content -->
</div>
<div class="spacer"></div>
<div class="panel">
<!-- Content -->
</div>
The CSS:
div.spacer
{
font-size: 0;
height: 10px;
line-height: 0;
}
It's bad if you could add a margin to content
instead. Otherwise, it's the best HTML element for spacers.
Yes, its bad — unnecessary markup. Use margin-top/margin-bottom instead.
It is unsemantic and unnecessary.
By adding:
padding-bottom: 10px;
or
margin-bottom: 10px;
to your div.panel
CSS declaration you can save yourself multiple characters (thus reducing bandwidth costs) and have cleaner code that expresses what you mean not how you want it to look.
It's not a good coding style for web stuff.
All (block) elements contain everything you need for create paddings/layout. Like the other ppl mentioned: use margins, paddings etc - the box model.
Too much of markup = more problems positioning something = needless markup.
精彩评论