Is there a way to ignore the first character that resides in <p>
and only apply inline styling to the remaining?
i.e. : Welcome
I want to make the word Welcome Red but the colon I want to ignore and leave it black
Is this possible?
I tried this but it makes the :
and W
Red.
p::first-letter {
color: red;
}
p::after {
content: ':';
float: right;
}
p {
color: black;
}
<p>:Welcome</p>
2
Answers
According to the docs:
This means selecting only the colon is not possible. You can, however, use a pseudo-element to create a inaccessible colon that precedes your actual content:
…or wrap the colon inside an element:
If you have no other choice, and unfortunately you have to act on the scheme we adopted at the beginning, i.e.
<p>:Welcome</p>
then you have several options for this, I couldn’t come up with another that would be more consistent.There are many disadvantages with my concept, that is, it makes:
with something like this.
However, it works and displays the text correctly.
This CSS code applies styling to a paragraph element, as well as adds a pseudo-element ::after, ::first-letter and ::before with additional styling.
If you have a better idea for eliminating unwanted text, as well as getting text selection back to work – write a comment.