user784637 user784637 - 23 days ago 6
CSS Question

CSS syntax to select class of an element identified by its id

For this code

<div id="dogs" class="content">hello</div>
<div id="frogs" class="content">hello</div>
<div id="hogs" class="content">hello</div>
<div id="logs" class="content">hello</div>


How can I select the class
content
from the element that has the id dogs?

Answer

You can try this:

.content#dogs {
  font: bold 28px sans-serif;
  color: #800000;
}
<div id="dogs" class="content">hello</div>
<div id="frogs" class="content">hello</div>
<div id="hogs" class="content">hello</div>
<div id="logs" class="content">hello</div>