简体   繁体   English

CSS:首字母编码不起作用

[英]CSS :first-letter coding won't work

I'm new to HTML and CSS. 我是HTML和CSS的新手。 I'm having problems getting my pseudo elements to work in paragraphs. 我在让我的伪元素在段落中工作时遇到问题。 The CSS I'm writing is 我正在写的CSS是

a:first-letter  { 
  font-size:3em;
}

The HTML code is HTML代码是

<p>Lorem ipsum, etc to end of paragraph</p>

The same thing happens with the before/after pseudo elements as we'll. 之前和之后的伪元素也会发生同样的事情。 the browser I'm using is Safari. 我使用的浏览器是Safari。 I'm sure I've typed it out correctly but it just doesn't work. 我确定我已经正确输入了它,但是它不起作用。 Any suggestions gratefully received. 任何建议表示感谢。

Thanks, 谢谢,
Ingrid 英格丽

Well you did said paragraphs but your CSS rule is applied to an anchor (link) instead of a paragraph. 您确实说过段落,但是您的CSS规则适用于锚点(链接)而不是段落。

So you might want to do something like: 因此,您可能想要执行以下操作:

p:first-letter { font-size:3em; }

After I checked, the :first-letter pseudo element indeed doesn't work for inline elements and if you wan't to use it on an <a> you have to define your element as an inline-block or block element: 在我检查之后, :first-letter伪元素确实不适用于内联元素,并且如果您不想在<a>上使用它,则必须将元素定义为inline-blockblock元素:

a { 
    display: inline-block;
    /* Since inline-block doesn't work on IE 7 and below you will need the following hack */
    *display: inline;
    zoom: 1;
}

Here is a jsFiddle example. 这是一个jsFiddle示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM