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

centred text / css selector precedence

P: n/a
I am having a problem with this page:-

http://www.bytronic.com/tests/centre.html

I want a nice centred paragraph, but get a justified paragraph. I
expected the .centre to override the #content p, as it is later in the
css file, but it doesn't.

The reason I have both these rules in the css is because in general
paragraphs in the content section of our pages should be justified, but
some are centred instead, so get their own class.

Thankyou for your help,

Martin

--
Martin Eyles
ma**********@NOSPAMbytronic.com
(posting as ma**********@NOSPAMntlworld.com from google because the
news server is down)

Dec 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
ma**********@ntlworld.com wrote:
I want a nice centred paragraph, but get a justified paragraph. I
expected the .centre to override the #content p, as it is later in the
css file, but it doesn't.


#content p is more specific then .centre so it takes priority.

#content p = 101
..centre = 010

http://www.w3.org/TR/CSS2/cascade.html#specificity

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Dec 22 '05 #2

P: n/a
Im not sure why it doesnt overwrite the first style, but if you do
this:

.centre {text-align: center !important; }

it will use that rule instead.
Adam
http://www.adamrisser.com

Dec 22 '05 #3

P: n/a
"David Dorward" <do*****@yahoo.com> wrote
http://www.w3.org/TR/CSS2/cascade.html#specificity


Thank you for explaining why this happens...

--
Martin Eyles
ma**********@NOSPAM.bytronic.com
(yay, the news server be fixed)
Dec 22 '05 #4

P: n/a
"Adam Risser" <ar*****@gmail.com> wrote
.centre {text-align: center !important; }


.... and thank you for explaining how to fix it.

--
Martin Eyles
ma**********@NOSPAM.bytronic.com
(yay, the news server be fixed)
Dec 22 '05 #5

P: n/a
Adam Risser wrote:
Im not sure why it doesnt overwrite the first style, but if you do
this:

.centre {text-align: center !important; }

it will use that rule instead.
Adam
http://www.adamrisser.com


or depending on how you want to structure things add

#content p.centre {text-align: center}

Stuart
Dec 22 '05 #6

P: n/a
On 2005-12-22, Adam Risser <ar*****@gmail.com> wrote:
Im not sure why it doesnt overwrite the first style, but if you do
this:

.centre {text-align: center !important; }

it will use that rule instead.


I thought !important meant "not important" to IE.
Bye.
Jasen
Dec 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.