3 replies [Last post]
ggbusta
ggbusta's picture
Offline
newbie
Last seen: 7 years 14 weeks ago
Timezone: GMT-5
Joined: 2014-04-21
Posts: 3
Points: 4

/* I would greatly appreciate help in understanding the following that I found in a book on CSS3 I am studying.

<div>
 
<h2>Our company is great!</h2>
 
<p>More information about why our company is so great</p>
 
<h2>Another news item</h2>
 
<p>Information about the other news item...</p>
 
<h2>...and so on...</h2<
 
<p>...and so on...</p>
 
</div>

Then the text reads, "If you simply slap a class on that opening

then you can create descendent selectors that format the HTML tags within the news section differently. For example,

.news h2 {color:red}
.news p {color:blue}

Here is my question. Why does slapping a class on the opening allow you to create descendent selectors that format the HTML tags within the new section differently?

Thanks for your help.

Jerry

//mod edit: Please wrap your source code in bbcode tags using the code button or directly, using [code] and [/code]. Fixed. ~gt/mod

ggbusta
ggbusta's picture
Offline
newbie
Last seen: 7 years 14 weeks ago
Timezone: GMT-5
Joined: 2014-04-21
Posts: 3
Points: 4

never mind

I obviously posted this wrong. Will try again.

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 21 weeks 3 days ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

Hi, Jerry

Welcome to the forum.

The class and id attributes allow you to differentiate among like elements. In your example, imagine yet another div of class 'gossip'. The classes allow you to apply different styles to each container's descendents.

.news h2 {
  color:red;
  }
 
.news p {
  color: blue;
  }
 
.gossip h2 {
  color: green;
  }
 
.gossip p {
  color: red;
  }

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

ggbusta
ggbusta's picture
Offline
newbie
Last seen: 7 years 14 weeks ago
Timezone: GMT-5
Joined: 2014-04-21
Posts: 3
Points: 4

Thank You

Thanks for taking the time to answer Gary. I now understand. I thought I posted this question wrong.

Thanks again.

Jerry