954,598 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

call a css

hello everyone!!!

what is the difference between this two css

p {
     color : red;
 }

  .name p {
   color : blue;
  }


how do i call this two css so that i can have a two results of p? one is color red and the other is blue.

your help is highly appreciated!!!

thanks in advanced!!!

jk_bscomp
Light Poster
46 posts since Apr 2007
Reputation Points: 4
Solved Threads: 1
 

The difference is the following:

p {} only is a master declaration for your whole page. Definitions here will be inherited by all p tags by default. It is like a default style for p tags.

.name p {} can be used to change the default setting to something else, which will have priority over the default declaration. Note that .name is a class in CSS, so you can reuse it several times, while #name is specific ID in you html code that you want explicitly to modify by css.

For example, if you are building up a forum, you can specify that all p tags by default show in red.
However, each post which is e.g. div, containing some p in it needs to be blue. So it will look like this

<body>
<p>All these will be shown in red</p>
<div class="posts" ><p>My blue content here</p></div>
</body>

But if you want some special formatting do be applied on a specific section of your page only - e.g. header, footer, news, etc..., you should do it like this.

<body>
<p>All these will be shown in red</p>
<div class="posts" ><p>My blue content here</p></div>
<div id="sections_unique_name_here"><p>Only this here will be purple</p></div>
</body>


Note that classes (.name) can appear on a single page multiple times, while id's (#name) can appear on a single page ONLY ONCE!

Rhyan
Posting Whiz in Training
240 posts since Oct 2006
Reputation Points: 21
Solved Threads: 26
 

HELLO RHYAN, thanks a lot.....

thank you so much......

jk_bscomp
Light Poster
46 posts since Apr 2007
Reputation Points: 4
Solved Threads: 1
 

On a similar note, if you have something like #nav p then it will only do that when it tags are encountered in the


section with the ID "nav".

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

thanks to all info... thanks a lot,

i hope you can still help me with this one...

#nav p h1 {
   color : red;
}


how can i call this one...?


thanks a lot!!!

jk_bscomp
Light Poster
46 posts since Apr 2007
Reputation Points: 4
Solved Threads: 1
 

thanks to all info... thanks a lot,

i hope you can still help me with this one...

p {
 color : red;
}

#nav p {
  color : green;
}


#nav p h1 {
color : red;
}


how can i call this three and their differences...?


thanks a lot!!!

jk_bscomp
Light Poster
46 posts since Apr 2007
Reputation Points: 4
Solved Threads: 1
 

The first one sets the defaukt colour for all elements to red. The second one, overrides this to green, but only for

elements in the #nav did.

#nav p h1 wont do anything but #nav p, h1 will. That will override the colour property for both

and

tags in the nav section to be red.

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

Just one thing -


elements are not allowed to contain h1-h6 elements.
This means you cannot have the following

Heading Here

The other text being here

Rhyan
Posting Whiz in Training
240 posts since Oct 2006
Reputation Points: 21
Solved Threads: 26
 

They are in HTML transitional , just not in XHTML.

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

thanks everyone!!!

for my last questions,,, how do i call this one and their difference/s

#search-news {
	float: right;
	width: 140px;
}

#search-news div {
	padding: 3px 0;
	margin: 0;
}

thanks a lot!!!

jk_bscomp
Light Poster
46 posts since Apr 2007
Reputation Points: 4
Solved Threads: 1
 

well to me it seems like that its another div with name search-news div. while the first div's name is search-news. it seems like two different divs. and the styles are applied on each one individually they are not connected anyhow.

wickedsunny
Junior Poster in Training
97 posts since Oct 2008
Reputation Points: 10
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You