Spaces and new lines with HTML and CSS
Should I use <br />
and
in HTML to position elements, or should I just use CSS displa开发者_运维问答y:inline with padding/margin for positioning and all styling? what are pros and cons with both?
Use <br>
to represent a linebreak inside a block element and use
to represent a non-breaking space inside an inline element. Nothing more. For the remnant just use CSS the smart way with help of under each the display
, float
, padding
and/or margin
properties.
<br />
has its uses, but if you find yourself using  
a lot, I would consider finding better ways to align things.
is just ugly and clunky.
If it's tabular data, use a table. Your life will be much happier.
If it's not tabular data, use css, as BalusC suggests.
Ideally you should position everything with css, and only use <br />
(line break) and
inside <p>s
.
But this isn't an ideal world ;)
<br />
Can really go either way. But if you find yourself using it to adjsut paragraph spacing orsomething like this then you really have to ask yourself "is there a reason why im using breaks instead of applying a class to adjust margins?"
on the other rarely if ever makes any kind of sense outside of a paragraph (<p />
) and half the time theres not much use for it ther any how as using text-indent
is preferable for indenting the first paragraph and much to the chigirn of Editors everywhere im completely opposed to the double space prepending of senetences on the web - as far as im concerned that is a print only thing.
In HTML5 you also have the new http://html5doctor.com/element-index/#w
the answer is not black and white, it depends on your content, sometimes it should be
and in some cases the so the content will be on a single line.
if you want it as block you can use
Using CSS margin and padding will give you greater flexibility to make adjustments later on.
精彩评论