Let's say we have this markup:
<div class="abc"> ... </div> <div class="xyz"> ... </div> <div class="abc xyz" style="width: 100px"> ... </div>
Is there a way to select only the <div>
which has BOTH abc
and xyz
classes (the last one) AND override its inline width to make the effective width be 200px?
Something like this:
[selector] { width: 200px !important; }
To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element. Naming rules: Must begin with a letter A-Z or a-z.
An element is usually only assigned one class. The corresponding CSS for that particular class defines the appearance properties for that class. However, we can also assign multiple classes to the same element in CSS. In some cases, assigning multiple classes makes page styling easier and much more flexible.
Use the getElementsByClassName method to get elements by multiple class names, e.g. document. getElementsByClassName('box green') . The method returns an array-like object containing all the elements that have all of the given class names.
div.abc.xyz { /* rules go here */ }
... or simply:
.abc.xyz { /* rules go here */ }
Below applies to all tags with the following two classes
.abc.xyz { width: 200px !important; }
applies to div tags with the following two classes
div.abc.xyz { width: 200px !important; }
If you wanted to modify this using jQuery
$(document).ready(function() { $("div.abc.xyz").width("200px"); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With