使用wordpress建网站的过程中,当首页中或者侧边栏有新闻中心板块,而个别新闻的标题太长的时候,这些标题会分两行显示,严重影响外观美化。我们想控制文字只显示一行,超出部分显示省略号。下面我们就来介绍一下实现的方法,实现的原理是把文本限制在一行(white-space: nowrap;),将溢出的部分要隐藏起来(overflow: hidden;),然后出现省略号( text-overflow: ellipsis)。
打开主题所在目录,找到标题所对应的选择器名称(例如.news-title),添加如下样式:
Crayon-5c891d2a51dae258666280" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-language">CSSCrayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">
Crayon-nums " data-settings="show"> Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;"> Crayon-num" data-line="Crayon-5c891d2a51dae258666280-1">1 Crayon-num" data-line="Crayon-5c891d2a51dae258666280-3">3 Crayon-num" data-line="Crayon-5c891d2a51dae258666280-5">5 Crayon-num" data-line="Crayon-5c891d2a51dae258666280-7">7 | Crayon-code">