473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
3 2295
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stuart Baker | last post by:
I just added session support to a web site and the URL's that contain a #fragment no longer function. Is there a delimiter that I can add following the #fragment that will tell the browser that the...
0
by: VRandy | last post by:
Example: http://pages.prodigy.net/randyv/centerprb.htm The desired effect is a fixed width left margin with a fixed width div centered in the right side. If the browser is resized to become very...
2
by: David Winter | last post by:
This is a totally trivial CSS problem, I'm sure, but I don't get it. I want a centered DIV with a fixed width between two other DIVs that should fill the rest of the window/viewport (= 100%). How...
4
by: Mimo Zus | last post by:
I'm hoping that someone can explain what's going on; better yet provide a workaround. I'm designing a centered CSS site based on a 550 pixel wide vertical background image. Onto this background...
17
by: Stian Lund | last post by:
Hello, I've been struggling with this problem for a while now, so I though I'd get some input from anyone more skilled with CSS than I am. I'm actually trying to accomplish two things with this:...
3
by: Gustaf | last post by:
I'm trying to grasp this little passage from the XBRL spec: "The xlink:href attribute MUST be a URI. The URI MUST point to an XML document or to one or more XML fragments within an XML document....
3
by: larzeb2000 | last post by:
I have constructed a css stylesheet which has a centered layout. The wrapper div is defined as 1000px. It contains a header div for the entire wrapper width, and a left sidebar div and a content...
9
by: Troy Piggins | last post by:
If I use the code: ----- <div style="text-align: center;"> <a href="photos.php?img=xx1.jpg"> <img src="xx1.jpg" style="padding: 10px;" /> </a> <a href="photos.php?img=xx2.jpg">
7
by: TheLongshot | last post by:
I just recently converted a few pages of my application to using master pages. Problem is, in all of my content pages, the contents are centered. I can't figure out why. The markup in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.