Centered fragment in a paragraph

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gentsquash@gmail.com

    Centered fragment in a paragraph

    I'm trying to display a paragraph that has a centered
    phrase,

    such as this one,

    in the middle of the paragraph. An example is the section
    "End of semester project" on my course-page



    =============== =============== =============== ===============
    In the past, I have used this structure:

    <p>I'm trying to display a paragraph that has a centered
    phrase,
    <center>such as this one,</center>
    in the middle of the paragraph.</p>

    This, or with the <centerreplac ed by

    <div align="center"> .

    In both cases, the text displays the way I would like.
    Alas, the page doesn't validate completely at

    W3C's easy-to-use markup validation service, based on SGML and XML parsers.


    Rather, I get this error:

    Error Line 377, Column 7: end tag for
    element "P" which is not open.

    My *guess* as to why this is happening is that the
    presence a of a block element (either "div" or "center")
    inside of a <pis causing a </pto be inserted before
    the block element.

    =============== =============== =============== ===============

    It would not be disaster if I had to typeset this as

    <p>I'm trying to display a paragraph that has a centered
    phrase,</p>
    <center>such as this one,</center>
    <p>in the middle of the paragraph.</p>

    but I'm wondering if I can

    * typeset it as a single paragraph, the way I think of it,

    * have a centered fragment (like a "displayed equation" in
    a mathematics textbook)

    * have the document validate.

    Sincerely,
    Prof. Jonathan King (gentsquash)
    Mathematics dept, Univ. of Florida
  • gentsquash@gmail.com

    #2
    Re: Centered fragment in a paragraph

    On Jun 3, 4:32 pm, "Jukka K. Korpela" <jkorp...@cs.tu t.fiwrote:
    Scripsit gentsqu...@gmai l.com:
    >
    In the past, I have used this structure:
    >
    <p>I'm trying to display a paragraph that has a centered
    phrase,
    <center>such as this one,</center>
    in the middle of the paragraph.</p>
    >
    While it may give the impression of working, it is invalid
    markup, as you have noted. It's not just a theoretical issue,
    since you get a wrong document tree in the Document Object
    Model. For example, if you assign a CSS rule that applies to
    p elements, it will only be applied to the part that precedes
    the <centertag, since by HTML parsing rules, the paragraph
    ends there.
    Ah --I'd likely get bitten by that sometime in the future. Ta.
    ... You can use <span>, with a suitable class attribute, for
    the text you wish to center, and use CSS for displaying the
    span element (which is inline by HTML rules, hence allowed
    inside a p element) ... with CSS code like ...
    >
    .special { display: block; text-align: center; }
    Very nice. Thank you.

    I realize now that I can use

    <style type="text/css">
    .jukkaspecial { display: block;
    margin-left: 7em;
    margin-top: 0.8em;
    margin-bottom: 0.8em;
    width: 19em;
    }
    </style>

    and get the effect

    /--------------------------------------------------------\
    I'm trying to display a paragraph that has a centered phrase,

    such as this one, which is actually
    quite a bit longer than I realized at
    first blush, and its sesquipedalian
    nature is unusual

    in the middle of the paragraph, but what the Hey!
    \______________ _______________ _______________ ____________/

    of a LaTeX macro that I have often used:

    The LaTeX macro I call "\display". Is there any reason I
    shouldn't call the CSS "jukkaspeci al" class by the name
    "display", so that I'll remember what it does? My concern
    is that "display" is also meaningful in CSS.

    Sincerely, --gentsquash

    Comment

    • Jukka K. Korpela

      #3
      Re: Centered fragment in a paragraph

      Scripsit gentsquash@gmai l.com:
      The LaTeX macro I call "\display". Is there any reason I
      shouldn't call the CSS "jukkaspeci al" class by the name
      "display", so that I'll remember what it does?
      Generally, class names should reflect the meaning of elements. For
      example, if the fragment is a mathematical formula, class="formula"
      would be suitable.

      In LaTeX, the approach is different in principle: you have formatting
      commands (TeX primitives), and you define macros in terms of them. In
      practice, it is rather the other way around: LaTeX macros often have
      meaningful, semantically suggestive names, whereas HTML class names are
      often macro-like.

      In both approaches, semantically meaningful names are usually better
      than purely presentation-oriented. They make the code easier to
      understand (e.g., a few years later when you need to read it) and easier
      to modify. Moreover, you may later wish to change the presentation
      completely (e.g., for a different presentation medium);
      presentation-oriented names would look rather silly after that!

      This leaves the problem that you might wish to use the same rendering
      for semantically different things, like formulas and news extracts. But
      in CSS, this is easily managed. You could use class="formula" and
      class="news" in HTML and a rule like

      ..formula, .news { ... }

      in CSS. You can then later easily differentiate the renderings if you
      like, e.g. by adding rules that apply to just one of those classes.
      My concern
      is that "display" is also meaningful in CSS.
      That's not a problem. There are no reserved names for classes, i.e.
      anything that syntactically matches the pattern of class names can be
      used, with no keywords extracted from the available name space. (The
      so-called HTML 5 activity tries to change this, but this is just one of
      its fundamental flaws.)

      In CSS, you use a class name prefixed with a period ".", so ".display"
      cannot possibly be mistaken for the property name "display" by a CSS
      parser. Moreover, property names appear in CSS in certain contexts only
      (inside curly braces "{...}" or in a style="..." attribute, where class
      names cannot appear), and even this would be sufficient.

      --
      Jukka K. Korpela ("Yucca")


      Comment

      • Dr J R Stockton

        #4
        Re: Centered fragment in a paragraph

        In comp.infosystem s.www.authoring.html message <ad8a6c7e-501d-4faa-961c-
        0417d6fe4052@e5 3g2000hsa.googl egroups.com>, Tue, 3 Jun 2008 12:53:35,
        gentsquash@gmai l.com posted:
        >I'm trying to display a paragraph that has a centered
        >phrase,
        >
        such as this one,
        >
        >in the middle of the paragraph.
        Maybe with CSS
        span.EQN { display: block; text-align: center; } /* Not IE4 */

        --
        (c) John Stockton, nr London, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 7.
        Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
        I find MiniTrue useful for viewing/searching/altering files, at a DOS prompt;
        free, DOS/Win/UNIX, <URL:http://www.idiotsdelig ht.net/minitrue/unsupported.

        Comment

        Working...