...">

How to select a <div> tag inside another <div> tag?

I have the following:

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

</div>

I would like to create text in "navbar". However, is there another div in the document called "navbar" in the stylesheet?

I thought it was something like:

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

But that did not work.

Thoughts?

+3
source share
5 answers

Put a space between:

#view #navbar {

If you specify two properties together without spaces, you select elements that have both attributes, which is impossible for the identifier, but it is possible, for example, for a class:

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

div#view.topmost <-- Will address that element
+6
source

First of all, if the document has another #navbar, it should be a class instead of id, you should not have 2 identifiers with the same name.

So this will be:

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

</div>

:

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

, . . CSS .

+1

Like an identifier, it must be unique to the document. Thus, you can refer to it separately:

#navbar {
  font-style: normal;
  ...etc
}
+1
source

Identifiers are unique, so you can:

#navbar {
  ...
}

But it is best to use classes to avoid collisions:

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

And do;

.view .navbar {
  ...
}
0
source

Source: https://habr.com/ru/post/1757425/


All Articles