css中首字母下沉

While it’s long been possible to create traditional dropcaps on the web using the ::first-letter pseudo selector, the process has been difficult: not only does it require a lot of careful, precise CSS, but any changes to the surrounding text, such as altering the typeface or line-height, push the dropcap out of alignment, whereas a good dropcap should always be “top and tail” with its associated text:

长期以来,使用::first-letter伪选择器在网络上创建传统的首字下沉很可能,但此过程非常困难:不仅需要大量仔细,精确的CSS ,而且还需要对周围的文本进行任何更改,例如在更改字体或行高时,将首字下沉不对齐,而好的首字应始终在其相关文本的“顶部和底部”:

A true dropcap: note the alignment of baselines and the ascender of the dropcap with the cap-height of paragraph text
真正的首字下沉:请注意基线和首字下沉的升序与段落文本的大写高度对齐

This complete independence between body text and initial cap meant any changes required alterations to both elements, including within responsive design and @media queries. As a result, CSS dropcaps have tended to be individually art-directed, making them extremely expensive to create, and leaving a typographical feature that has been a standard for over 400 years relatively rare on the web… and when they were attempted, often done badly.

正文和初始上限之间的完全独立性意味着任何更改都需要对这两个元素进行更改,包括响应式设计和@media查询中的更改。 结果,CSS首字下沉往往是单独进行艺术指导的,因此制作起来极其昂贵,并且在400多年来一直是印刷标准中的一项印刷功能在网络上相对罕见……当尝试使用时, 通常会这样做严重的 。

Along with its excellent work on CSS blend modes, shapes, regions and other modules, the Adobe web development team has proposed a new CSS property, initial-cap, that addresses just this issue. While support is limited right now to Chrome and Safari, a nice little polyfill has been released that provides support for the proposal in all modern browsers, giving developers and designers an easy way to add dropcaps to their pages.

除了在CSS混合模式 , 形状 ,区域和其他模块方面的出色工作之外,Adobe Web开发团队还提出了一个新CSS属性initial-cap ,它可以解决此问题。 虽然目前对Chrome和Safari的支持非常有限,但已经发布了一个不错的小polyfill ,可以在所有现代浏览器中为该提案提供支持,从而为开发人员和设计人员提供了一种在其页面上添加首字下沉的简便方法。

The specification works using the same ::first-letter selector, but makes the styling of dropcaps much easier. For example, to style the first letter of the very first paragraph in a page, we could add in the :first-of-type pseudo selector:

该规范使用相同的::first-letter选择器工作,但使::first-letter下沉的样式更加容易。 例如,要为页面中第一段的第一个字母设置样式,我们可以添加:first-of-type伪选择器:

p:first-of-type::first-letter {initial-letter: 3; color: red;
}

…meaning “make the dropcap red, and as high as the first three lines of text in the paragraph”. Naturally, the spec covers a lot of territory, including different writing directions, dealing with descenders and short paragraphs, and much more. Right now, the major limitation is that ::first-letter (and pseudo elements in general) can’t take all the CSS properties required for a truly great dropcap. Until that is resolved, the polyfill requires that we add markup to indicate which letter we want to apply the effect to:

…意思是“将首字下标设为红色,并使其与段落中前三行文字一样高”。 自然,该规范涵盖了很多领域,包括不同的写作方向,涉及后代和短段落的内容等等。 现在,主要的限制是::: ::first-letter (和一般的伪元素)不能采用真正强大的dropcap所需的所有CSS属性。 在解决该问题之前,polyfill要求我们添加标记以指示我们要将效果应用于哪个字母:

<p><span id="dropcap">M</span>y father’s family name being Pirrip, and my Christian name Philip, my infant tongue could make of both names nothing longer or more explicit than Pip...

Then add the polyfill to the bottom of the page and target the <span>:

然后将polyfill添加到页面底部,并定位<span>

<script src="dropcap.min.js"></script>
<script>
var dropcap = document.getElementById("dropcap");
window.Dropcap.layout(dropcap, 3);
</script>

Our CSS then changes to target this id:

然后,我们CSS更改为以该id为目标:

#dropcap {color: red;
}

Naturally, you could use and target a class if you wanted multiple dropcaps on the same page.

当然,如果您想在同一页面上使用多个首字下沉,则可以使用和定位一个class

It’s also possible to create a “pop-cap” by specifying a second, optional, baseline value for the method:

还可以通过为该方法指定第二个可选baseline值来创建“ pop-cap”:

window.Dropcap.layout(dropcap, 3, 2);

This aligns the baseline of the dropcap with the second line of text, but keeps the dropcap three lines high. (By default, an undeclared baseline automatically takes the line-height value).

这使首字下沉的基线与文本的第二行对齐,但使首字下沉保持三行高。 (默认情况下,未声明的baseline自动采用line-height值)。

It’s common for dropcaps to be rendered in a different typeface from body text; if you’re using a webfont purely for dropcaps, it makes sense to subset the font to capital letters only.

首字下沉通常以与正文不同的字体呈现。 如果您仅将webfont用于首字下沉,则仅将字体子集化为大写字母是有意义的。

使首字下沉响应 (Making the dropcap responsive)

An initial letter three lines high will likely be too large at the screen size of mobile devices, so it must be reduced at an appropriate breakpoint:

在移动设备的屏幕尺寸上,三行高的首字母可能会太大,因此必须在适当的断点处减小它:

@media all and (max-width: 600px) {p:first-of-type::first-letter {initial-letter: 2;}
}

Making the dropcap responsive with the polyfill is slightly more complex, as it uses matchMedia to switch the size of the letter: consult the CodePen repo for more information.

使用polyfill使首字下沉响应变得稍微复杂一点,因为它使用matchMedia来切换字母的大小:有关更多信息,请参见CodePen存储库 。

While iOS does support initial-cap, Jen Simmons has pointed out that iOS 9.2 still has a problem with offsetting the first line.

尽管iOS确实支持首字母大写,但Jen Simmons指出, iOS 9.2在偏移第一行方面仍然存在问题 。

结论 (Conclusion)

initial-letter is a promising proposal, filling a typographical gap that has had to be addressed with complex CSS hackery. I’ll return to expand this article as the specification is ironed out and browser support increases; you may wish to follow me on Twitter to receive alerts on updates.

initial-letter是一个很有前途的建议,它填补了必须通过复杂CSS黑客解决的印刷空白。 随着规范的制定和浏览器支持的增加,我将继续扩展本文。 您可能希望在Twitter上关注我,以接收有关更新的警报。

翻译自: https://thenewcode.com/961/Big-Beautiful-Dropcaps-with-CSS-initial-letter

css中首字母下沉

css中首字母下沉_CSS首字母大而精美的首字下沉相关推荐

  1. css中的单位换算_CSS像素、物理像素、逻辑像素、设备像素比、PPI、Viewport

    1.PX(CSS pixels) 1.1 定义 虚拟像素,可以理解为"直觉"像素,CSS和JS使用的抽象单位,浏览器内的一切长度都是以CSS像素为单位的,CSS像素的单位是px. ...

  2. css中调整高度充满_CSS(十三).高度如何铺满全屏

    该需求来源一次面试题. IE6不认识!important声明,IE7.IE8.Firefox.Chrome等浏览器认识:而在怪异模式中,IE6/7/8都不认识!important声明,这只是区别的一种 ...

  3. css中的单位换算_CSS单位px、em、rem及它们之间的换算关系

    作者:WangMin 格言:努力做好自己喜欢的每一件事 国内的设计师大都喜欢用px,而国外的网站大都喜欢用em和rem,那么三者的区别与优势是什么?接下来我们就来学习一下吧! 单位px.em.rem分 ...

  4. css中的媒体查询_CSS中的媒体查询

    css中的媒体查询 CSS | 媒体查询 (CSS | Media Queries) Creating a web page is not an easy task as it requires lo ...

  5. css中的单位换算_css大小单位px em rem的转换和详解

    css大小单位px em rem的转换和详解 PX特点 1. IE无法调整那些使用px作为单位的字体大小: 2. 国外的大部分网站能够调整的原因在于其使用了em或rem作为字体单位: 3. Firef ...

  6. HTML文本下划线效果,聊聊CSS中文本下划线_CSS, SVG, masking, clip-path, 会员专栏, text-decoration 教程_W3cplus...

    在Web中给文本添加下划线常常出现在链接的文本上,早期一般使用text-decoration属性给文本添加下划线.删除线等.除了text-decoration之外,CSS还有很多技术方案可以给文本添加 ...

  7. css中的单位换算_CSS中各种长度单位总结

    在前端开发工作过程中曾碰到这样一问题: .parent{ width:400px; height:300px; border:1px solid #ccc; } .child{ margin:10%; ...

  8. css中的单位换算_css绝对长度单位主要有哪些?绝对长度单位之间如何换算?

    本篇文章就给大家介绍css长度单位中绝对长度单位主要有哪些,它们之间是怎么换算的.有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所帮助. css中的长度单位有很多,可谓五花八门,但基本上可分 ...

  9. css取消a标签自动换行,css中a元素放长英文字母或者数字自动换行的解决

    request .response和session的区别 request: 1.request.getParameter("key")接受的是来自客户登陆端的数据,接受的是post ...

最新文章

  1. [Android]Android端ORM框架——RapidORM(v2.1)
  2. 2015 SegmentFault 黑客马拉松记录
  3. 经典C语言程序100例之五七
  4. 音视频技术开发周刊:FFmpeg内置的一个无中生有的音视频输入数据 | 214
  5. 【简便解法】1077 互评成绩计算 (20分)_32行代码AC
  6. sql注入攻击和PreparedStatement有效防止sql注入攻击
  7. Android应用开发——service连接泄露异常:android.app.ServiceConnectionLeaked: that was originally bound here
  8. 数据链路层:ARP协议详解(绝对经典)
  9. 宝石光是什么石头_捡到这些石头,都是值钱货
  10. C/C++ C# unity经常使用的一些快捷键
  11. 《王道》数据结构笔记整理2022
  12. 有什么推荐的计算机毕设题目吗?2023最新springboot计算机毕业设计选题大全
  13. vue页面加载时闪现_Vue 闪现解决
  14. Springboot 返回数据提示语 国际化 (AOP实现)
  15. 苹果CMS接入GOGO支付实现个人收款回调详细教程(附插件)
  16. ept技术_intel EPT 机制详解
  17. 电影影院购票管理系统
  18. 第五章:使用HBuilder
  19. 广州小学计算机教师待遇,给大家详细的分享一下广州市各区在编教师的待遇到底有多少?一个月的工资大概有多少,到底高不高?...
  20. 董付国老师python教学——学习笔记(一)

热门文章

  1. VS 运行后没有黑框输出
  2. 乘云科技受邀出席2022阿里云合作伙伴大会荣获“聚力行远奖”
  3. Ffmpeg快慢镜头,操作音视频
  4. excel怎么设置打印区域_EXCEL打印页面设置技巧(四)打印区域和分隔符
  5. 计算机应用技术创业ppt,计算机应用基础教程任务4创业计划书排版.pptx
  6. elementui全局去掉输入框前后的空格
  7. 移动机器人系列5——机器人的闭环控制
  8. 2023兰州交通大学计算机考研信息汇总
  9. 剑与家园服务器总是维护,新人经常被点?浅谈剑与家园游戏保护机制
  10. vue中加载loading