By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,221 Members | 1,663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,221 IT Pros & Developers. It's quick & easy.

Centered fragment in a paragraph

P: n/a
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 <centerreplaced 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 <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
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Jun 3, 4:32 pm, "Jukka K. Korpela" <jkorp...@cs.tut.fiwrote:
Scripsit gentsqu...@gmail.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 "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
Jun 27 '08 #2

P: n/a
Scripsit ge********@gmail.com:
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.
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/

Jun 27 '08 #3

P: n/a
In comp.infosystems.www.authoring.html message <ad8a6c7e-501d-4faa-961c-
04**********@e53g2000hsa.googlegroups.com>, Tue, 3 Jun 2008 12:53:35,
ge********@gmail.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.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.
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.