前言
这一期我们继续记录主题美化:清除字体遮挡、添加黑幕。
清除字体遮挡
这个问题主要是当自己换了字体以后,切换到手机版发现标题部分被遮挡了,例如这样:

就非常不美观。我通过 F12 开发者工具检查发现,把字体调大到 21px 以上就会显示完全,但这样就整体字体非常大,也挺影响美观的。
根据检查可以知道,实际上这里的字体大小不会被 style.css 中设置的 font-size 控制,而是会被 index 里加载的控制(即被后台控制),这个字体的大小在 iro 主题设置 → 主页设置 → 文章区域设置 这里可以调整标题字体大小。

但显然我们不是这个问题。继续看 style.css 中类 .post-list-thumb .post-title h3,其中有一个属性是 overflow: hidden;。CSS overflow 属性用于内容溢出元素框时的处理方式。
overflow 可选值一览(简表):
| 值 | 描述 |
|---|---|
| visible | 默认值。内容不会被修剪,会呈现在元素框之外。 |
| hidden | 内容会被修剪,其余内容不可见。 |
| scroll | 内容被修剪,但显示滚动条以查看其余内容。 |
| auto | 如被修剪则显示滚动条。 |
| inherit | 从父元素继承 overflow 的值。 |
此时可以发现,这里默认修剪了,把文字的上半部分裁掉了。根据这个规则,把 overflow 的值改为 visible 或者删除该属性即可解决。
因此最后在 style.css 中 .post-list-thumb .post-title h3 把 overflow: hidden; 改为 overflow: visible;,就不会被遮挡了:
/* 原 */.post-list-thumb .post-title h3 { /* ...其他样式... */ overflow: hidden;}
/* 修复 */.post-list-thumb .post-title h3 { /* ...其他样式... */ overflow: visible;}当然这只是我的博客的情况,也许这种情况并不会发生在别的博客上,具体情况具体分析。

添加黑幕
我们经常看到在发布一些……的内容时,部分文字需要把鼠标放在黑幕上或点击黑幕才会显示,这种效果适合发布一些重要内容或者是……你懂的 (ΦωΦ)。
添加这个功能也比较简单:打开 WordPress 的 外观 → 自定义 → 额外 CSS,添加下面的 CSS:
span.heimu a.external,span.heimu a.external:visited,span.heimu a.extiw,span.heimu a.extiw:visited { color: #252525;}
.heimu,.heimu a,a .heimu,.heimu a.new { background-color: #252525; color: #252525; text-shadow: none;}
body:not(.heimu_toggle_on) .heimu:hover,body:not(.heimu_toggle_on) .heimu:active,body:not(.heimu_toggle_on) .heimu.off { transition: color .13s linear; color: white;}
body:not(.heimu_toggle_on) .heimu:hover a,body:not(.heimu_toggle_on) a:hover .heimu,body:not(.heimu_toggle_on) .heimu.off a,body:not(.heimu_toggle_on) a:hover .heimu.off { transition: color .13s linear; color: lightblue;}
body:not(.heimu_toggle_on) .heimu.off .new,body:not(.heimu_toggle_on) .heimu.off .new:hover,body:not(.heimu_toggle_on) .new:hover .heimu.off,body:not(.heimu_toggle_on) .heimu.off .new,body:not(.heimu_toggle_on) .heimu.off .new:hover,body:not(.heimu_toggle_on) .new:hover .heimu.off { transition: color .13s linear; color: #BA0000;}使用方法也很简单,只需要在文章中插入如下 HTML 即可:
<span class="heimu" title="光标显示内容">黑幕内容</span>我们还可以把它添加为编辑器的快捷按钮,在主题的 function.php 中添加以下代码(Classic 编辑器 QuickTags):
add_action('after_wp_tiny_mce', 'heimu_add');function heimu_add($mce_settings) {?><script type="text/javascript">QTags.addButton('heimu_show', '黑幕', '<span class="heimu" title="你知道的太多了">', '</span>');function heimu_add() {}</script><?php}