0

I'm trying to find out what I am doing wrong. I have the following HTML:

<div id="dialog-container">
    <div id="dialog-box" title="" >
        <div id="dialog-icon" >
            &nbsp;
        </div>
        <p>
        <span id="dialog-message"></span>
        </p>
    </div>
</div>

I have some CSS which floats to the left. If I enter the following it works

#dialog-box #dialog-icon
{
    float: left; 
    height: 32px; 
    width: 32px;   
}

but if I enter 1 more rule i.e insert #dialog-container before the #dialog-box then it's not applied like this:

#dialog-container #dialog-box #dialog-icon
{
    float: left; 
    height: 32px; 
    width: 32px;   
}

but I thought this means apply to dialog-icon that's inside a dialog-box and that is inside a dialog-container?

Am I missing something?

5
  • A closing </div> for dialog-box maybe? Commented Dec 2, 2010 at 11:46
  • That's a single selector that makes use of descendant combinators (the spaces between the IDs). Commented Dec 2, 2010 at 11:49
  • Re edit, is that new HTML code the one you meant to paste at the top? If so maybe you should replace that code block instead so your question is clearer. Commented Dec 2, 2010 at 11:52
  • ok doing it now.. its not new html.. i pasted it wrong.. i will update the question Commented Dec 2, 2010 at 11:54
  • Hmmm, that selector should work just fine... could you look in your stylesheet and see if there's anything else that might be overriding that rule? Commented Dec 2, 2010 at 11:56

3 Answers 3

3

You HTML is not correctly formed or structured for your needs. You are missing a closing DIV tag on the second DIV. This is maybe what you need:

<div id="dialog-container">
    <div id="dialog-box" title="" >
        <div id="dialog-icon" >
            &nbsp;
        </div>
    </div>
</div>

The way you had it, the third div was not treated as a child (or 'inside') the second.

EDIT Following Update

I've tested this in JSFiddle (adding a colour for red and some text to highlight). It seems to be working ok:

http://jsfiddle.net/WW3v2/

Do you have any more info?

Sign up to request clarification or add additional context in comments.

1 Comment

Yes i think i had a problem with cache ... Sorry to trouble everyone... It was very strange as i also thought it should be working..
0

Firstly, you have three opening <div> tags but only two closing ones.

Secondly, you don't need to declare #id1 #id2 as #id2 is an identifier and is only allowed to identify one element. It is sufficient to declare a rule for #id2.

1 Comment

Very true :-) but i would like to know why its not working for when i need to use it with class names for example
0

This

#dialog-container #dialog-box #dialog-icon

would match the following structure:

<div id="dialog-container">
    <div id="dialog-box">
        <div id="dialog-icon"></div>
    </div>
</div>

but since your dialog-icon is not inside of dialog-box (at least not properly), this does not work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.