CSS first-letter selection highlighting [duplicate]

喜你入骨 提交于 2019-12-01 02:37:24

问题


Is there any way to highlight the first character of an element that has the ::first-letter pseudo-element applied to it?

I'm trying to give the user feedback in regards to a text selection. The text selected is being used for a Twitter plugin and works fine (i.e., the first-letter character is included); however, it doesn't appear as if the text can actually be highlighted.

Here's a link to a CodePen example and here is a screenshot to help demonstrate what I'm talking about:

I attempted to highlight the larger, red "S" but was unable to.

Any help is greatly appreciated and I apologize in advance if this is a duplicate. Thanks!


回答1:


You can do something like this:

p:first-letter {
  float: left;
  font-size: 3em;
  color: #333;
}

<p>This is your paragraph.</p>

I wrote about this a few years ago in an article entitled Styling CSS First-Letter. There are more special case examples there.



来源:https://stackoverflow.com/questions/19649540/css-first-letter-selection-highlighting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!