【问题标题】:nth-everything styling last word with CSS and JSnth-everything 用 CSS 和 JS 设计最后一个字
【发布时间】:2017-04-18 21:19:21
【问题描述】:

我尝试使用 CSS 和 Jquery JS 以及来自此解决方案的其他 JS 为我的示例单词添加样式:

'http://codepen.io/FWeinb/pen/djuIx'

我能够为奇数和偶数字母以及 nth(n) 字母着色,但我对 :last-word 示例有疑问。这是我做的,最后一句话对我不起作用:/ my version

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

下面的代码将突出显示类名为 highlight_last_wordspan, div, p 的最后一个单词。

致谢:https://codepen.io/mel/pen/jLEKH?css-preprocessor=none

$(function() {
  $(".highlight_last_word").html(function() {
    var text = $(this).text().trim().split(" ");
    var last = text.pop();
    return text.join(" ") + (text.length > 0 ? " <span class='last-word'>" + last + "</span>" : last);
  });
})
.last-word {
  color: #F00;
  font-size: 40px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<span class="highlight_last_word">
  This is sample text to color last WORD
</span><br><br>

<span class="highlight_last_word">
  Some text which could be long enought to move to next line. Some text which could be long enought to move to next line. Some text which could be long enought to move to next line. Some text which could be long enought to move to next line.
</span><br><br>

<span class="highlight_last_word">
  This is some other text
</span>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2018-02-04
    • 2016-12-19
    • 2021-09-21
    • 1970-01-01
    • 2017-11-28
    相关资源
    最近更新 更多