Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / CSS / February 2007



Tip: Looking for answers? Try searching our database.

Basic CSS question re specificity

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
paul.denlinger@gmail.com - 20 Feb 2007 18:44 GMT
Hi--

I'm working my way through the book, Beginning CSS Web Development by
Simon Collison. I ran into a problem on pages 17-18 (Chapter 2), I
have copied and put in three rules re IDs and the <p> tag.

The first and second paragraphs are red, and the third paragraph
should be
dark gray. My problem is that all three paragraphs are red.

Here are the three CSS rules:
p {
color: #F00;
}

/* Define highlighted text */
-----------------------------------------------------------------
#highlight {
color: #F00;
}

/* Define default text */
-----------------------------------------------------------------
#default {
color #333;
}

Can you tell me what I'm doing wrong which causes the third paragraph
to be
red instead of dark gray?

I wrote to the author, and he told me that there had been a mistake in
the example (not enough specificity), and that the CSS rule should
read:

/* Make text red only for paragraphs within the box class */
#container .box p {
 color: #F00;
}

I have tried that, and it still doesn't work for me. Can you tell me
what I'm doing wrong, and how to correct it?

Thank you.
Bergamot - 20 Feb 2007 18:53 GMT
> Here are the three CSS rules:

The code snippet you posted doesn't give enough info to determine what's
going on. Upload your test page and post the URL.

Signature

Berg

paul.denlinger@gmail.com - 20 Feb 2007 19:59 GMT
> paul.denlin...@gmail.com wrote:
>
[quoted text clipped - 5 lines]
> --
> Berg

Hi--

I have uploaded the page to http://www.china-ready.com/colly/stylesheet.htm

The CSS is http:www.china-ready.com/colly/style1.css It is linked to
the HTML page above.

Thanks,

Paul
Beauregard T. Shagnasty - 20 Feb 2007 20:58 GMT
> I have uploaded the page to
> http://www.china-ready.com/colly/stylesheet.htm
>
> The CSS is http:www.china-ready.com/colly/style1.css It is linked to
> the HTML page above.

Paste your CSS into this checker, then fix the errors.
http://www.htmlhelp.com/tools/csscheck/

New documents should use a Strict doctype, Transitional is for ..
transitioning old legacy code.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">

Also, before you venture much further, have a read of this:
http://k75s.home.att.net/fontsize.html

Signature

  -bts
  -Motorcycles defy gravity; cars just suck

paul.denlinger@gmail.com - 20 Feb 2007 22:32 GMT
Thank you very much; the CSS check site is very helpful.

Paul

> paul.denlin...@gmail.com wrote:
> > I have uploaded the page to
[quoted text clipped - 16 lines]
>    -bts
>    -Motorcycles defy gravity; cars just suck
John Hosking - 20 Feb 2007 18:53 GMT
> [...]
> /* Define default text */
[quoted text clipped - 5 lines]
> Can you tell me what I'm doing wrong which causes the third paragraph
> to be red instead of dark gray?

No. You haven't provided a URL (preferred) or even any HTML code.
All I can guess at for now is that your -------------- lines are messing
up your real CSS. Also, it's Tuesday. This stuff never works on Tuesday.

And is this in all browsers?

Signature

John

Andy Dingley - 21 Feb 2007 15:08 GMT
On 20 Feb, 18:44, "paul.denlin...@gmail.com"
<paul.denlin...@gmail.com> wrote:

> /* Define highlighted text */
> -----------------------------------------------------------------
> #highlight {
> color: #F00;
>
> }

Don't use an id or "#highlight" for highlighted text, use a class
and .highlight instead. Using id in a selector has "powerful"
specificity which is hard to over-ride locally, class is much better
(search, this has been posted many times before)

This will also fix your bug, which is caused by mixing the two.
Bergamot - 21 Feb 2007 17:28 GMT
> On 20 Feb, 18:44, "paul.denlin...@gmail.com"
> <paul.denlin...@gmail.com> wrote:
[quoted text clipped - 3 lines]
> Don't use an id or "#highlight" for highlighted text, use a class
> and .highlight instead.

In this case, "highlight" insinuates emphasis, so it may actually be
better to use an <em> element instead. Depends on the context, of course.

Signature

Berg

Andy Dingley - 21 Feb 2007 18:45 GMT
> In this case, "highlight" insinuates emphasis, so it may actually be
> better to use an <em> element instead.

class="emphasis" and <em>...</em> mean two different things.

The first means a notion of "emphasis" (which is still undefined
ontologically, but that's not at issue) and this notion is applied to
an element or contained DOM tree fragment. This can be any element,
and it includes the elemnt itself.

<em>...</em> means a fragment of HTML matching the %inline;
production. Although we might agree that the concepts can be seen as
exactly equivalent, it's simply not possible to define the same
document scope with it.  You cannot highlight a list element or a menu
element with <em>, only its contents.
Bergamot - 21 Feb 2007 21:09 GMT
> class="emphasis" and <em>...</em> mean two different things.

I did say it depends on context. ;)

Since the OP posted bogus content, we can't know for sure which markup
might be better, but we all know it isn't unusual for newbies to use the
wrong markup for the job.

Signature

Berg

Patrick Smith - 22 Feb 2007 14:42 GMT
> Hi--
>
[quoted text clipped - 22 lines]
> color #333;
> }

Don't know if I am jumping into this too late, but I see a missing colon
after color before #333; Would it make a difference if it read
color: #333;   ?

> Can you tell me what I'm doing wrong which causes the third paragraph
> to be
[quoted text clipped - 13 lines]
>
> Thank you.

Signature

Patrick A. Smith           Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu          Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.