- This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I am trying to create a header and would like to have the first letters of each word in the name stylized differently than the rest of the name. So this is what I did:
There has to be a better, cleaner way to do this, but if there is I don’t know it. Hopefully someone out there can help.
Thanks,
Aaron
There is a pseudo element in CSS called :first-letter. Not supported in all browsers but then nothing you’re already doing is ;-)
Strictly HTML + CSS-wise you could do (as ChristopherBurton said) span tags.
The Company Name
And in the CSS you would do something like:
h1 { color: blue; }
h1 span { color: red; }
I’m sure there are Javascript techniques that could also achieve it, and as TT_Mark suggested :first-letter (which is the cleanest way by far) though good old spans have the widest browser support.
I appreciate the span technique which is probably what I will end up doing.
When I try ::first-letter, I am having to place each word in a different h1, otherwise the only thing that happens is the the first letter of the first word is affected. That doesn’t seem like how first-letter was supposed to work?
First letter only affects the first letter of each word, but then you can place each word in a span tag
Yeah first-letter should affect the first letter of each word, which I thought was the case. I haven’t really had a chance to use it to be honest.
Either way, spans are definitely better than multiple H1 tags. Good luck with the rest of your site. :)