:first-line
:first-line
:first-line
p::first-line { font-weight: bold; color: #e44d26; /* 醒目的橙红色 */ font-size: 1.2em; text-transform: uppercase; /* 转换为大写,增加视觉冲击 */ }
<p>
::first-line
width
height
margin
padding
:first-line
<span>
<span>
<p>这是一段示例文本,用来展示CSS如何对首行或首字进行特殊处理。
.first-word { font-size: 2em; color: #007bff; /* 蓝色 */ font-weight: bold; margin-right: 0.05em; /* 稍微拉开一点距离,避免粘连 */ }
::first-letter
p::first-letter { font-size: 2.5em; /* 放大很多 */ color: #28a745; /* 绿色 */ font-weight: bold; float: left; /* 让它悬浮,形成首字下沉效果 */ line-height: 1; /* 避免影响行高 */ margin-right: 0.05em; padding-right: 0.05em; }
::first-letter
:first-line
:first-line
:first-line
margin
padding
border
width
height
:first-line
:first-line
:first-line
:first-line
:first-letter
<span>
<span>
<p>这里是文章的开头,我们希望第一个词能有特殊的样式。
.first-word-highlight { font-family: 'Georgia', serif; font-size: 2em; color: #8a2be2; /* 紫罗兰色 */ font-weight: bold; text-shadow: 1px 1px 2px rgba(0,0,0,0.3); margin-right: 0.1em; }
<span>
document.querySelectorAll('p.intro').forEach(paragraph => { const text = paragraph.textContent; const words = text.split(/\s+/); // 按空格分割 if (words.length > 0) { const firstWord = words[0]; const restOfText = words.slice(1).join(' '); paragraph.innerHTML = `<span class="first-word-js">${firstWord}</span> ${restOfText}`; } });
<span>
:first-line
:first-letter
:first-line
:first-letter
:first-line
:first-letter
p.drop-cap::first-letter { font-size: 4em; line-height: 1; float: left; margin: 0.1em 0.1em 0 0; color: #6c757d; /* 灰色 */ font-family: 'Playfair Display', serif; /* 选用衬线字体更显古典 */ }
:first-line
:first-letter
以上就是CSS如何实现文字首行首字特效?:first-line伪元素的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 //m.sbmmt.com/ All Rights Reserved | php.cn | 湘ICP备2023035733号