Solved

Help with CSS id select and class

Posted on 2012-03-30
1
128 Views
Last Modified: 2012-04-04
Hi All -  I need some CSS help here.

In my stylesheet I have an ID selector like this.

    #newVisitors { ... stuff }

I assigned this ID selector a class

    #newVisitors .cbBlurb{ ....stuff}

Now what I need to do is style a <h2> element within the cbBlurb class that's within #newVisitors

I tried this

    #newVisitors .cbBlurb h2{ ....stuff}

and this

    #newVisitors h2.cbBlurb{ ....stuff}

and this

    #newVisitors .cbBlurb.h2{ ....stuff}

but none of them work.  

What do I need to do in order to get this to work?

Thanks
0
Comment
Question by:cdemott33
1 Comment
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 37789335
The first one you tried is correct but alternatively you can use the second one and apply class cbBlurb to the h2 element as well as its parent element.

using the first notation here is some html that shows how to use it:

<!DOCTYPE html>
<html>
 <head>
  <title> Q_27656397 </title>
  <style type="text/css">
	#newVisitors { border: solid 3px black; background-color: green; }
	#newVisitors .cbBlurb { background-color: silver; }
	#newVisitors .cbBlurb h2 { color: red; }
  </style>
 </head>
 <body>
	<h2> standard black h2 </h2>
  <div id="newVisitors">
		<h2> black h2 on green in #newVisitors </h2>
		<div class="cbBlurb">
			other text in .cbBlurb
			<h2> red h2 </h2>
		</div>
  </div>
 </body>
</html>

Open in new window

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

"I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now