text and <p>

Discussion in 'HTML' started by Clues, Apr 7, 2006.

  1. Clues

    Clues Guest

    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
     
    Clues, Apr 7, 2006
    #1
    1. Advertising

  2. Clues wrote:

    > 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.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Apr 7, 2006
    #2
    1. Advertising

  3. Clues wrote:

    > 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 <br>.

    > 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?
     
    Jukka K. Korpela, Apr 7, 2006
    #3
  4. Clues

    Clues Guest

    Thanks Yukka and David,
    now anything appears clearer :)

    Clues
     
    Clues, Apr 7, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Julie

    Text boxes and read-only text

    Julie, May 12, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,118
    Julie
    May 12, 2004
  2. Krish
    Replies:
    1
    Views:
    1,106
    =?Utf-8?B?Q3VydF9DIFtNVlBd?=
    Oct 20, 2005
  3. Replies:
    5
    Views:
    1,146
    Ian Rastall
    Jun 29, 2005
  4. Replies:
    1
    Views:
    536
    Adrienne Boswell
    Mar 10, 2006
  5. leo
    Replies:
    1
    Views:
    311
    Bob Lehmann
    Dec 5, 2005
Loading...

Share This Page