Style specific letters in a word [duplicate]

2019-06-28 07:23发布

This question already has an answer here:

My current HTML:

<a href="#" id="word">T<span style="font-size: 28px;">est</span><span style="color: pink;">W<span style="font-size: 28px;">ord</span></span></a>

This is terrible for SEO. Ideally, I'd like all styling done to the anchor tag:

<a href="#" id="word">TestWord</a>

I understand there is a :first-letter selector, but how can I modify an nth letter and get my expeced output?

jsFiddle: http://jsfiddle.net/HUGKv/1/

标签: html css seo
3条回答
Animai°情兽
2楼-- · 2019-06-28 08:04

Tricky, yes, but happier SEO, also:

<h1>TestWord</h1>

h1 {
    color: pink;
}
h1:before {
    content: "Test";
    position: absolute;
    left: 8px;
    color: red;   
}

fiddle

查看更多
Viruses.
3楼-- · 2019-06-28 08:16

Currently there is no way to target n-th letter through CSS. There are some calls for CSS to allow n-th everything in the future, but as of today, no such luck.

Currently, you would probably have to use some JS approach to solve this.

查看更多
【Aperson】
4楼-- · 2019-06-28 08:17

Add a span element with the CSS you require for individual letters.

<a href="#" id="word">Test<span class="classname">W</span>ord</a>
查看更多
登录 后发表回答