开发者

Is using <div> spacers a bad practice? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜