HighDots Forums  

Centered fragment in a paragraph

HTML Writing HTML for the Web (comp.infosystems.www.authoring.html)


Discuss Centered fragment in a paragraph in the HTML forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
gentsquash@gmail.com
 
Posts: n/a

Default Centered fragment in a paragraph - 06-03-2008 , 02:53 PM






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

http://www.math.ufl.edu/~squash/course.calc3.html

================================================== ==========
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 <center> replaced by

<div align="center">.

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

http://validator.w3.org/

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 <p> is causing a </p> to 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

Reply With Quote
  #2  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: Centered fragment in a paragraph - 06-03-2008 , 03:32 PM






Scripsit gentsquash (AT) gmail (DOT) com:

Quote:
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 <center> tag, since by HTML parsing rules, the
paragraph ends there.

Quote:
This, or with the <center> replaced by

div align="center">.
Doesn't really matter, since <center> is just a shorthand for it.

Quote:
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 <p> is causing a </p> to be inserted before
the block element.
Right. Technically, the end tag </p> is optional and will be inferred by
a browser when it encounters an element that cannot be contained in a p
element by HTML syntax. So technically <center> ends the paragraph, and
the text after </center> is "loose" text (naked text, not wrapped in any
container except body), and then comes the </p> which is a syntax error.

Quote:
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
That's one possibility, though somewhat illogical, when it's
structurally just one paragraph.

Quote:
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.
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) the way you
like:

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

with CSS code like

..special { display: block; text-align: center; }

(You might wish to add e.g.
margin: 0.5em 0
there, to create some vertical spacing around the centered text.)

This is a little cheating: you use an inline element in HTML and then
turn it to block-level in CSS. But it's valid, makes the structure
logical, and works well on CSS-enabled browsers

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/



Reply With Quote
  #3  
Old   
gentsquash@gmail.com
 
Posts: n/a

Default Re: Centered fragment in a paragraph - 06-03-2008 , 05:29 PM



On Jun 3, 4:32 pm, "Jukka K. Korpela" <jkorp... (AT) cs (DOT) tut.fi> wrote:
Quote:
Scripsit gentsqu... (AT) gmail (DOT) 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 <center> tag, since by HTML parsing rules, the paragraph
ends there.
Ah --I'd likely get bitten by that sometime in the future. Ta.

Quote:
... 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 "jukkaspecial" 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


Reply With Quote
  #4  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: Centered fragment in a paragraph - 06-04-2008 , 01:43 AM



Scripsit gentsquash (AT) gmail (DOT) com:

Quote:
The LaTeX macro I call "\display". Is there any reason I
shouldn't call the CSS "jukkaspecial" 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.

Quote:
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")
http://www.cs.tut.fi/~jkorpela/



Reply With Quote
  #5  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: Centered fragment in a paragraph - 06-04-2008 , 10:54 AM



In comp.infosystems.www.authoring.html message <ad8a6c7e-501d-4faa-961c-
0417d6fe4052 (AT) e53g2000hsa (DOT) googlegroups.com>, Tue, 3 Jun 2008 12:53:35,
gentsquash (AT) gmail (DOT) com posted:
Quote:
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.demon.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.idiotsdelight.net/minitrue/> unsupported.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.