I have other company’s html, show three lines:
<div class="classA classB classC">A_display</div>
<div class="classB classC">B_no_display</div>
<div class="classC">C_no_display</div>
I need A_display display, and let B_no_displayC_no_display hide.
The classA, classB, classC’s name is known and the class combination will not change.
Can I use CSS selector make it? Like using this css:
.classA .classB .classC{
/* todo how to display A_display, don't display B_no_display C_no_display*/
/* display: inline !important;*/
}
.classB .classC {
display: none;
}
.classC {
display: none;
}
Then the page show only one line:
A_display
2
Answers
You have to remove the whitespace between class names like
.classA.classB.classC
Yes, CSS selectors can be used to hide specific elements based on their class combinations. The updated CSS code to achieve the desired result is as follows:
This will make the
A display
element visible while hiding theB no display
andC no display
elements. CSS selectors check each element for the exact class combination, and thedisplay
property is used to show or hide the elements.