text and <p>

C

Clues

Hi,
I must separate some text blocks.

I started by doing the following:

<p>
texttxtxtxtxtxtxtxtxtxtxtxtx<br />
texttxtxtxtxtxtxtxtxtxtxtxtx
</p>

and using a CSS to style <br />

#content br {margin: 0; padding: 0; border-width: 0; line-height: 2em;}
but I was unhappy with the result.


The question:
in XHTML, is it legal to do something like this:

<div>
<p>textxtxtxtxtxtxtxtxt</p>
<p>tetxtxtxtxtxtxttxtxtx</p>
</div>

?

I thank you very much.
Clues
 
D

David Dorward

Clues said:
I must separate some text blocks.
<p>
texttxtxtxtxtxtxtxtxtxtxtxtx<br />
texttxtxtxtxtxtxtxtxtxtxtxtx
</p>

That would be a single block (the paragraph), with a line break in it.
in XHTML, is it legal to do something like this:

<div>
<p>textxtxtxtxtxtxtxtxt</p>
<p>tetxtxtxtxtxtxttxtxtx</p>
</div>

Two paragraphs in a generic block? Of course.
 
J

Jukka K. Korpela

Clues said:
I must separate some text blocks.

Apparently you wish to make some vertical empty space appear between
them in visual rendering. Have you consider how things work in
non-visual rendering?
I started by doing the following:

<p>
texttxtxtxtxtxtxtxtxtxtxtxtx<br />
texttxtxtxtxtxtxtxtxtxtxtxtx
</p>

and using a CSS to style <br />

That's a wrong approach. The <br> tag means just 'line break'. It
specifically does not separate blocks; it is by definition inline
(text-level) markup. Besides, the odds of styling it successfully are small.
#content br {margin: 0; padding: 0; border-width: 0; line-height: 2em;}
but I was unhappy with the result.

No wonder. What does line height mean for nonexistent lines? Besides, br
elements have by default display: none, in CSS terms, together with a
fancy rule for br:after to implement the presentational semantics of said:
The question:
in XHTML, is it legal to do something like this:

<div>
<p>textxtxtxtxtxtxtxtxt</p>
<p>tetxtxtxtxtxtxttxtxtx</p>
</div>

Of course it's "legal" syntactically. The simple syntactic question can
easily be resolved by consulting the specifications, and there is no
difference between HTML and XHTML in this respect. Whether it is
_semantically_ "legal" depends on what you have their inside the <p>
elements (and on the applicable jurisdiction of semantics).

But beware that by using <p> you effectively invoke some default top and
bottom margins for each <p> element, so you need to be careful to avoid
getting too much spacing. As regards to making the spacing between the
paragraphs e.g. 2em, it suffices in practice to the margin-bottom: 2em
for the first paragraph.

However, if the two blocks are logically parts of the same paragraph,
the situation is more tricky. You would need to resort to a workaround like

<p><span class="part1">textxtxtxtxtxtxtxtxt<br /></span>
<span class="part2">tetxtxtxtxtxtxttxtxtx</span></p>

with something like

..part1, .part2 { display: block; }
..part2 { margin-top: 2em; }

(The <br /> is there to ensure a line break in non-CSS visual rendering.
The first <span> is there just as a matter of logic.)

On the other hand, if parts of a paragraph should be set so much apart
from each other, do they really constitute a paragraph?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top