I’m trying to figure out if there’s a quicker way to write something like this:
<span class="brandname"><span style="color: #0399f0">Company</span>Name</span> <span class="tagline">TagLine</span>
What should happen is CompanyName gets wrapped in the class brandname
which is a specific font, weight, and text-decoration, and then first half of the name (Company) should be in blue while while the rest of it is default (black). And then Tagline is wrapped in a class called tagline
which displays a different font etc.
Does anyone know if I can just use the class brandname
to target the first half of CompanyName. Looking for a way to save keystrokes for the future.
I feel like the way I’m doing it now would affect SEO. Majority of my googling has resulted in links from 2012-2014…my guess is nth-letter still doesn’t exist but was worth asking for alternative.
Thanks for your help!
2
Answers
I ran into the same before. Unfortunately I couldn’t find CSS only solution.
Then I stumbled upon this pen . This uses jQuery to style the n-th selector.
You could do something like this CSS only, but in this case you have to add the content you want in another color to the css part:
HTML:
<span class="brandname">Name</span> <span class="tagline">TagLine</span>
CSS:
I myself would still prefer the solution with the 2 span elements.
Working fiddle: https://jsfiddle.net/xeyqr4w9/