0

I have a CSS class and I want to make sure that whenever a h2 tag is assigned that class, additional CSS is given to the h2 tag on top of the original class. Here is what I currently have for CSS and HTML but it is currently not rendering out the text-align class.

.aligncenter {
 clear: both;
 color: #000000
 h2{
  text-align: center;
 }
<div>
<h2 class="aligncenter"> H2 Text that should be black and centered</h2>
</div>
bbestul
  • 339
  • 1
  • 4
  • 11

3 Answers3

2

You cannot do that with regular css. The only way to achieve what you want with regular css is like this:

.aligncenter {
    clear: both;
    color: #000000
}

h2.aligncenter {
    clear: both;
    color: #000000
    text-align: center;
}

To do nesting and other cool stuff you need some css extension language like SASS

f-CJ
  • 4,235
  • 2
  • 30
  • 28
0

.aligncenter {
 clear: both;
 color: #000000
 h2{
  text-align: center;
 }
<div>
<h2 class="aligncenter"> H2 Text that should be black and centered</h2>
</div>
sushilyogi
  • 31
  • 2
0
<style>
h2.aligncenter {
        clear: both;
        color: #000000;
        text-align: center;
        }
</style>

    <div><h2 class="aligncenter"> H2 Text that should be black and centered</h2></div>
 <!-- end snippet -->
sushilyogi
  • 31
  • 2