I want to modify class of an element for specific parent. Here is what I have:
<form id="form2">
<div class="blueform">
<div class="formlegend">
...
</div>
</div>
</form>
I would like to override class formlegend only for form with id “form2”. I have tried:
#form2.formlegend {
padding: 10px;
}
but it does not work. Is this even possible?
You are missing the “descendant combinator” (whitespace, usually just a single space character) between the 2 selectors:
Without the descendant combinator, your selector will match an element with an ID of
form2and a class offormlegend. According to the markup in your question, you need it to match an element with the classformlegendthat is a descendant of an element with an ID ofform2.