I have a website that I am developing using CSS3 and I have h1
tag for the title:
<h1>main title</h1>
Now I want the title to be in a different color:
<h1>main <span>title</span></h1>
So I do:
h1 { color: #ddd; } h1 span { color: #333; }
Is there a way not to use the span
tag and only specify in CSS the last word to be a different color?
The code snippet below shows the syntax of using the color property to set the color of the <h1> element. The value of the color property can be specified in three ways: Using RGB values e.g. rgb(250,0,0), rgb(0,250,0), etc. Using a Hexadecimal(HEX) value e.g. #FFFFFF, #000000, etc.
Simply add the appropriate CSS selector and define the color property with the value you want. For example, say you want to change the color of all paragraphs on your site to navy. Then you'd add p {color: #000080; } to the head section of your HTML file.
Text ColorThe color property is used to set the color of the text. The color is specified by: a color name - like "red" a HEX value - like "#ff0000"
This is not possible with pure CSS. However you can use lettering.js to get a ::last-word
selector. CSS-Tricks has an excelent article on this: CSS-Tricks: A call for nth-everything. You can then do the following:
h1 { color: #f00; } /* EDIT: Needs lettering.js. Please read the complete post, * before downvoting. Instead vote up. Thank you :) */ h1::last-word { color: #00f; }
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