Вопрос

Мне было интересно, смогу ли я использовать <p>&nbsp;</p> (просто пространство в абзаце) вместо <br />

Потому что я люблю сохранять свой код семантиком и думал, что это правильно, мне некоторое время беспокоит. Я видел, как редакторы Wysiwsg (tinymce) используют это, но я все еще предпочитаю сделать это неправильно.

Это было полезно?

Решение

What's wrong with using the margins of the paragraphs for vertical-spacing instead?

<p>Hello World</p>
<p>This is much cleaner than using empty tags with non-breaking spaces.</p>

Другие советы

That is not "semantic", an empty paragraph is something that more or less cannot exist, semantically. It contains no information, i.e. no semantic content. All it does is change the visual layout, i.e. the presentation.

You're far better off using styling to change the margins, borders or padding to achieve the effect you're after.

The right way to do it is with CSS: use the margin-top or margin-bottom.

<p>&nbsp;</p> is pretty horrible... I'd rather see <br> than that (even though it may be less "correct").

<p>&nbsp;</p> is not semantic, so I don't know how that helps you.

You should set the space between the paragraphs with css.

I advocate wrapping items in block-level tags, such as divs and ps. This way I don't need either. If you want to space out elements, you should be using margins. You can be more accurate with margins anyway.

In a situation where you're forced to have a line break, use <br />: it, unlike empty paragraph tags, actually does mean 'line break'. There's almost always a better way to do things though.

It's HTML. You can use whatever it wants as long as you're sure it will render the way you wanted on all the browsers you're gonna use. I don't understand what you mean by "keep my code semantic" so I'm not sure what your issue with <br> is. But if you're talking about formatting and such, turn to CSS.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top