简体   繁体   English

首字母选择器CSS

[英]First-letter selector CSS

Image: 图片:

在此处输入图片说明

In the picture, the text on the right is what I need to accomplish, the text on the left is what I've got. 在图片中,右边的文本是我需要完成的,左边的文本是我所需要的。

Does anyone know a good solution for this. 有谁知道一个好的解决方案。 So far I have only been trying CSS but I will try anything. 到目前为止,我仅尝试CSS,但可以尝试任何方法。

So far my CSS is - 到目前为止,我的CSS是-

.single-post .spb_text_column p:first-child::first-letter{
font-size: 200%;
font-weight: bold;
vertical-align: -14px;
}

I can float the letter and that makes the space in the text go away but still the text does not wrap around the large letter. 我可以使字母浮动,这样可以使文本中的空格消失,但是文本仍不会环绕大字母。 If anyone has a solution for this...Javascript, CSS, or even a Wordpress plugin would be fine. 如果有人对此有解决方案... JavaScript,CSS甚至是Wordpress插件都可以。 Thanks. 谢谢。

Try this: 尝试这个:

 p:first-child:first-letter { float: left; color: #903; font-size: 75px; line-height: 60px; padding-top: 4px; padding-right: 8px; padding-left: 3px; font-family: Georgia; } 
 <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tristique lobortis orci ac lacinia. Fusce eu purus eget diam vehicula auctor nec eu elit. Morbi consequat facilisis orci vel malesuada. Donec ultrices molestie sollicitudin. Aliquam pharetra libero enim. Donec et suscipit massa. Donec dui odio, dignissim non sodales et, tincidunt a sapien. Phasellus elit nibh, adipiscing sed blandit vel, interdum et arcu. </p> 

Notes on Luis's answer: 关于路易斯答案的注释:

You likely want to make the size of the letter = (n-1)*lineheight + fontsize, where n is a small integer. 您可能希望将字母的大小设置为(n-1)* lineheight + fontsize,其中n是一个小整数。

So, for example with 15 px type, on 18 px line height you could use 33 px (2 lines) 48 px (3 lines) or 63 px (4 lines) 因此,例如使用15像素类型,在18像素行高上,您可以使用33像素(2行),48像素(3行)或63像素(4行)

I played around with this for a long time. 我玩了很长时间。 The problem: You can't depend on the font being on the target machine, and a change in font messes up the spacing -- it only has to be a few px out to look tacky. 问题:您不能仅依赖目标计算机上的字体,而更改字体会弄乱间距-看起来只有俗气,只需要几个px。

To get it to work right you are going to have to override some of the browser settings for CSS. 为了使其正常工作,您将不得不覆盖CSS的某些浏览器设置。 I also recommend using the same font as the paragraph, and change only height, weight and color. 我还建议使用与该段落相同的字体,并仅更改高度,粗细和颜色。

I ended up going the other way: Keeping the baseline the same, but using a larger cap. 我最终采取了另一种方式:保持基线不变,但是使用更大的上限。 This also created more space from the preceding element. 这也为前面的元素创造了更多空间。 This tends to work better in the sloppy definitions of web presentation. 这往往在Web演示的草率定义中更好地工作。

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

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