tags:

views:

59

answers:

5

I have the following:

<div id="view">
    <div id="navbar">
        Placeholder Text
    </div>

</div>

I would like to style the text in 'navbar'. However, there is another div further up in the document called 'navbar' in the stylesheet?

I thought it was something like:

#view#navbar {
font-style: normal;
...etc
}

But that didn't work.

Thoughts?

+2  A: 
#view #navbar {
    font-style: normal;
    ...etc
}

This is what you want. The same applies for classes. You can read all about CSS selectors here.

Mike
Thanks Mike. You are right.
marcamillion
+6  A: 

Put a space in between:

#view #navbar {

If you specify two properties together without spaces, you select elements that have both attributes - which is impossible for an ID, but possible for, say, a class:

<div id="view" class="topmost">

div#view.topmost <-- Will address that element
Pekka
Thnx. This is exactly right. I prefer the top half of your answer though :)
marcamillion
+1  A: 

As it is an id, it must be unique for the document. Thus, you can refer to it by itself:

#navbar {
  font-style: normal;
  ...etc
}
Johan
+3  A: 

First of all, if there is another #navbar in the document it should be a class instead of an id, you shouldn't have 2 ids with the same name.

So it would be:

<div id="view">
    <div class="navbar">
        Placeholder Text
    </div>

</div>

Then for styling it you would do:

#view .navbar {
font-style: normal;
...etc
}
Martin
Well...the thing is, both are not to be styled the same way. So the 2nd navbar will look nothing like, or act anything like the first. But it still acts like a navbar.So that's why that's there.
marcamillion
@marcamillion: Since you want two navbars, then you'll need to change it to a class.
Mike
@marcamillion: You would just use a different id for the second navbar if it's not going to share any style with the first one. Or just the same class name and differentiate them based on their parent div ids like the example I provided.
Martin
A: 

ID are uniques, so you can do :

#navbar {
  ...
}

But, the best it's to do with classes to avoid collisions :

<div class="view">
    <div class="navbar">
        Placeholder Text
    </div>
</div>

And do ;

.view .navbar {
  ...
}
Dorian