小赖子的英国生活和资讯

如何使博客第一段话的第一个字漂亮的大写?

阅读 桌面完整版

你看!本文的第一段话的第一个字大写!

很容易的, 只需要用到CSS的 first-letterfirst-child 选择器:

只要将下面的CSS先添加到WORDPRESS的模板里(比如可以放在 Single.php)

1
2
3
4
5
6
7
8
9
10
11
12
<style>
.wp_content 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; 
}
</style>
<style>
.wp_content 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; 
}
</style>

然后在模板函数 functions.php 的最后添加以下几行代码:

1
2
3
4
5
6
// https://helloacm.com
add_filter( 'the_content', 'prefix_big_letter' );
 
function prefix_big_letter($content) {
  return "<div class='wp_content'>$content</div>";
}
// https://helloacm.com
add_filter( 'the_content', 'prefix_big_letter' );

function prefix_big_letter($content) {
  return "<div class='wp_content'>$content</div>";
}

就可以了, 清一下缓存, 然后可以看效果.代码也不需要我过多的解释, 简单粗暴有效! 转走吧,不用谢!

查看英文效果, 请看: https://helloacm.com/how-to-make-first-letter-in-first-paragraph-big-in-wordpress-css-articles/

强烈推荐

微信公众号: 小赖子的英国生活和资讯 JustYYUK

阅读 桌面完整版
Exit mobile version