Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS Headings of Different colours

RobertWA

Active Coder
On my pages I want to be able to use headings of the same level but with different colours. I know that I can specify a colour (eg red)in my CSS file and then change the colour using inline styling wherever I want to use a different colour (eg green). But is there a better way?

Can I set things up in my CSS file so that in my HTML I can just use something like <h3_red> , <h3_green> , <h3_blue> etc to prevent all the inline styling?

Thanks

Robert
 
One way:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Color Headings</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<style>
h2{
  font-family: "Times New Roman", Times, serif;
  font-size: large;
  font-weight: 500;
  width: 150px;
  text-align: center;
  background-color: lightgray;
  color: black;
}
.red{color:red;}
.green{color:green;}
,purple{color:purple;}
</style>
</head>
<h2>Color Headings</h2>
<br>
<h2 class="red">Next Section</h2>
<h2 class="purple">Next Section</h2>
<h2 class="green">Next Section</h2>
<body>
 

</body>
</html>
 
.red{color:red;} .green{color:green;} ,purple{color:purple;} </style> </head> <h2>Color Headings</h2> <br> <h2 class="red">Next Section</h2> <h2 class="purple">Next Section</h2> <h2 class="green">Next Section</h2> <body> </body> </html>
@RobertWA
Inside @OldMan s reply is a list of colors that have class attributes. Looking at the h2 tags, Oldman put 'class="color"' and then selected the class in the CSS with .color{ color: color;}
 

New Threads

Buy us a coffee!

Back
Top Bottom