Ryan
Ryan

Reputation: 5546

styling a div with a specific ID

#contentpage div

Does this mean select the div that has id #contentpage?

I am getting some bad layout. I am trying to select the div with the id #contentpage.

Could somebody also please tell me what the following css mean:

#myid div a
.myid a h
div #myid a

Upvotes: 0

Views: 211

Answers (4)

solendil
solendil

Reputation: 8468

#contentpage {color:red} will select whichever element with id contentPage

#myid div a will select <a> elements that are inside <div> that are inside an element with id myid

.myid a h as far as I know there is no <h> element ? Without the h, it would select all links within any elements with the class myid (in this case myid is a dubious name, then, since its not an id per se)

div #myid a will select links inside of an element with id myid, but only if this element is within a <div>. It won't work if the element myid is a direct children of <body> for example

Upvotes: 0

Mikhail
Mikhail

Reputation: 9007

#myid div a
<anytag id="myid"><div><a rel="match">...

.myid a h
<anytag class="myid"><a><h rel="match">...

div #myid a
<div><anytag id="myid"><a rel="match">...

If you would like to match a div with id #myid, then either ignore the fact that it's a div (ids are unique anyway) or match it as follows:

div#myid

Upvotes: 1

James Montagne
James Montagne

Reputation: 78630

#myid div a

This will match an a within a div within an element with the id of myid. When I say "within" I mean anywhere within at any nesting level. The others are all the same but with different elements in different orders.


If you want an element with the id of contentpage you simply use #contentpage. If for some reason you wanted to specify that it was a div it would be div#contentpage.

Upvotes: 1

CBRRacer
CBRRacer

Reputation: 4659

if you want to modify the styling of the div with the id of contentpage then you would do the following

div#contentpage { //input styling here }

OR

#contentpage { //input styling here }

it also looks like you are trying to get at elements under the div these can be accessed in a number of ways but this is usually what I do

<div id="contentpage"><div><a></a></div></div>

#contentpage a { //stying }
#contentpage div a {  //styling }

Upvotes: 0

Related Questions