开发者

How to select inner divs with the IDs?

I would like to select a div within a div by specifying the ID.

HTML with specified ID

<div id="divOuter">
   <div id="divInner">
   </div>
开发者_运维百科</div>

And if I want to select divInner by using ID selectors in more to the point style what should I use?

I tried

div#divOuter> div#divInner 

but cannot make it work.


As IDs have to be unique,

#divInner

is sufficient.

If you have more elements with the same ID you have to change that (you might want to use classes instead).

Update:

Ok, I got your point. But your selector is correct: http://jsfiddle.net/fkling/AsPam/

Either you have another rule that overrides this one, or your structure is different.

Update 2:

Oh, as others have noted , the child selector is not supported by IE6. You have to omit it then:

div#divOuter div#divInner 


As IDs are unique all you really need is

#divInner
{
    /*styles*/
}

This will select the ID attribute of the HTML element and apply the styles.

If you need to repeat the styles to more than one element, use a class

.divInner
{
    /*styles*/
}


#divOuter div{...}

or

#divInner{...}


For starters (and I know this might be a typo), have you checked the spelling?

When it comes to the selection, you seem to want to use the id tag, in other words, all you need is to do as everyone above says: #idInner{...}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜