I have a heading named "Happy Starting". Now I want to underline only first three characters. For example, "Hap" only instead of entire "Happy".
How can I select first three characters of "Happy" in css?
Use the span
tag
The HTML span
tag is used for grouping and applying styles to inline elements.
There is a difference between the span tag and the div tag. The span tag is used with inline elements whilst the div tag is used with block-level content.
span{
text-decoration:underline;
}
<p><span>Hap</span>py Starring</p>
CSS don't have anything which can help you to style particular or any n characters.
One way to achieve this is put those 3 characters within span and style it using css.
Something like
.word{
color: green;
}
.word span{
color: red;
text-decoration:underline;
}
<div class="word"><span>Hap</span>py Starting</div>
Check this fiddle https://jsfiddle.net/LfsLpz5g/
Or you can use <u>
html tag also.
Copying the answer from: change color css only first 6 character of text
How about using
:before
?I would change the text from "Client Testimonial" to "Testimonial", and then with CSS apply the
:before
rule:HTML:
CSS:
Example: http://jsfiddle.net/LvZt7/