Solved

Help with CSS id select and class

Posted on 2012-03-30
1
130 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
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.…

809 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