Simple Machines Community Forum

Customizing SMF => Graphics and Templates => Topic started by: Sir Osis of Liver on May 24, 2023, 10:11:44 PM

Title: CSS multiple classes
Post by: Sir Osis of Liver on May 24, 2023, 10:11:44 PM
When inspector shows this -


     class="top_menu dropmenu notify_dropdown"


What is correct css to address last element?
Title: Re: CSS multiple classes
Post by: Diego Andrés on May 24, 2023, 10:56:16 PM
Last element of what?
Title: Re: CSS multiple classes
Post by: Sir Osis of Liver on May 24, 2023, 11:24:08 PM
I can change background color in top_menu, but would expect that to affect other menus.  Just want to change bg color for notify_dropdown.  I've done it by adding this -


.notify_dropdown div {
background: #023570;
}


But don't understand what it means when inspector displays multiple classes as above.
Title: Re: CSS multiple classes
Post by: Diego Andrés on May 24, 2023, 11:27:47 PM
You could use .top_menu.notify_dropdown so you make sure it only looks for the elements that match both.

Quote from: Sir Osis of Liver on May 24, 2023, 11:24:08 PMBut don't understand what it means when inspector displays multiple classes as above.

They would overwrite depending on the specificity of the selector, or the order in which it appeared in the file.
Title: Re: CSS multiple classes
Post by: Sir Osis of Liver on May 24, 2023, 11:48:07 PM
Will try that, thanks.

Yes, that works same as code I used, but it's more consistent with what inspector displays.  Good for future reference.
Title: Re: CSS multiple classes
Post by: Julius_2000 on May 25, 2023, 11:01:40 AM
A useful css selector I've come to appreciate is :is( )

With that, you can select and combine multiple classes or other elements to which you want to apply a certain style according to their structure.

For instance, if you have more elements that should look the same but are not supposed to affect others, you could write

.top_menu dropmenu :is(.notify_dropdown, .myNextElement, #myNextElemtent, ... ) {

   }
Also saves space as you don't have to repeat code.