Modern Option
Note: it may not be compatible with older browsers:
.live_grid :is(h1,h2,h3,h4,h5) {
/* style here */
}
See here for more information about :is(): https://developer.mozilla.org/en-US/docs/Web/CSS/:is
Standard Option:
If you want to style all the headers in that class, you have to do it like this (which could also be done without the line breaks). Notice each selector has .live_grid in it:
.live_grid h1,
.live_grid h2,
.live_grid h3,
.live_grid h4,
.live_grid h5,
.live_grid h6 {
/* style here */
}
When you comma separate things, they're independent of each other - hence the need to reference the class again.
For example:
#myDiv1, .live_grid, #myDiv2 {
color: blue;
}
This would set the text-color for everything in the #myDiv1 element, everything in the #myDiv2 element, and everything in the .live_grid element to having text color blue.
This also explains the reason your CSS is matching all the headers - you're referencing them individually, separated by commas - there is no selector for their containing element(s).
CSS pre-processor option
Or, you can always go with something like LESS or SASS which allows you to write nested rules something like this:
#live_grid {
h1, h2, h3, h4, h5, h6 {
/* style here */
}
}
Custom class option
Lastly, you could add a class to all of your headers and just refer to that class:
<-- HTML -->
<h1 class="custom-header">Title of Blog Post</h1>
<h2 class="custom-header">Subtitle of Blog Post about Pizza</h2>
/* CSS */
.custom-header {
/* style here */
}
Answer from Dave on Stack OverflowMultiple CSS selectors
How can I set up my CSS so that it will correctly apply to multiple selectors?
Help me with multiple selectors
In CSS, using a selector with multiple elements on page...
Videos
Modern Option
Note: it may not be compatible with older browsers:
.live_grid :is(h1,h2,h3,h4,h5) {
/* style here */
}
See here for more information about :is(): https://developer.mozilla.org/en-US/docs/Web/CSS/:is
Standard Option:
If you want to style all the headers in that class, you have to do it like this (which could also be done without the line breaks). Notice each selector has .live_grid in it:
.live_grid h1,
.live_grid h2,
.live_grid h3,
.live_grid h4,
.live_grid h5,
.live_grid h6 {
/* style here */
}
When you comma separate things, they're independent of each other - hence the need to reference the class again.
For example:
#myDiv1, .live_grid, #myDiv2 {
color: blue;
}
This would set the text-color for everything in the #myDiv1 element, everything in the #myDiv2 element, and everything in the .live_grid element to having text color blue.
This also explains the reason your CSS is matching all the headers - you're referencing them individually, separated by commas - there is no selector for their containing element(s).
CSS pre-processor option
Or, you can always go with something like LESS or SASS which allows you to write nested rules something like this:
#live_grid {
h1, h2, h3, h4, h5, h6 {
/* style here */
}
}
Custom class option
Lastly, you could add a class to all of your headers and just refer to that class:
<-- HTML -->
<h1 class="custom-header">Title of Blog Post</h1>
<h2 class="custom-header">Subtitle of Blog Post about Pizza</h2>
/* CSS */
.custom-header {
/* style here */
}
.live_grid h1,
.live_grid h2,
...
you get the idea
Suppose, I have two p tags.
<p class="apple orange banana">text</p> <p class="banana">text</p>
CSS: p.apple.banana{ background-color: aquamarine; }
Only, the first p tag with both classes gets a bg color. So, does the browser apply my style on the p tag having both the classes 'apple' and 'banana' and not either of the 2 classes?
I know it is a basic concept but just wanted to clarify this up.
I am working with an application where the CSS classes are being automatically generated based on the values of check boxes. The checkbox values are: home, training, members, and youth - always in that order.
The generated class could be any combination of those 4 values, including all 4 at the same time. I want to create CSS that will assign a background color to a DIV based on those classes. For example:
class="home" is a white background
class="training" is a yellow background
class="members" is a red background
class="youth" is a blue background
any combination with "members youth" will be a purple background
The following is a sample of what I'm playing around with. The last 3 DIVs all have red backgrounds as it is now.
<!DOCTYPE>
<html>
<head>
<title>Test</title>
<style>
div {
width: 200px;
height: 200px;
margin: 10px 0;
border: 1px solid black;
text-align: center;
vertical-align: middle;
color: black;
}
.home {
background-color: white;
}
.training {
background-color: yellow;
}
.members{
background-color: red;
]
.youth {
background-color: blue;
}
.members, .youth {
background-color: purple;
}
</style>
</head>
<body>
<div class="home">white</div>
<div class="home training">yellow</div>
<div class="home training members">red</div>
<div class="home training members youth">blue</div>
<div class="home members youth">purple</div>
</body>
</html>