Page is a not externally linkable
- Code, Content, and Presentation
-- CSS
---- Which element should be used without BR


lucy24 - 5:57 pm on Jun 21, 2012 (gmt 0)


<p>My text <br /><p>

How to avoid BR in the correct way?

Was that a typo or a mistake? There should be a closing </p>. Technically html 4 doesn't require them, though the validator kicks up a fuss. But I kinda think everything has to be closed in xhtml which is what you've got here, with the <br /> form.

At any rate my solution to avoid the empty <br>: I usually style the element with padding or margins or width so that the content area narrows enough to force line breaks. Unfortunately they don't always break where you want them to, but it's one less hard coded element.

Ouch. That's risky when there's such a huge array of user-agents. I generally code it with a

div p

structure. For example (more often in ebooks than in, ahem, real life)

div.verse {nice big side margins, smaller top and bottom margins}
div.verse p {margin-left: 4em; text-indent: -4em; top margin less than for a free-standing paragraph}
... with extra stuff for indented lines, stanza breaks and so on.

Then each line becomes its own paragraph, and if it does overflow, it's got a nice big hanging indent.

otoh I do sometimes take the easy way out and shove in a bit of blank space via a quick <p>&nbsp;<br>&nbsp;</p> ;)

You can constrain width to a certain extent by defining it in ems, but unless you're in a fixed-pitch font you can't be certain your users will see exactly the same thing you do; some fonts are simply wider than others.

<p>Single line</p> is technically wrong.


Well, you don't know that it will be a single line do you? Maybe your user is reading it on an antiquated phone with a display that's only ten characters wide ;)


Thread source:: http://www.webmasterworld.com/css/4467955.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com