日韩成人免费在线_国产成人一二_精品国产免费人成电影在线观..._日本一区二区三区久久久久久久久不

當前位置:首頁 > 科技  > 軟件

太強了!CSS 文字效果還能這樣玩

來源: 責編: 時間:2024-02-01 12:51:37 211觀看
導讀在 CSS 中,文字算是我們天天會打交道的一大類了,有了文字,則必不可少一些文字裝飾。本文將講講兩個比較新的文字裝飾的概念 text-decoration 與 text-emphasis,在最后,還會講解使用 background 模擬文字下劃線的一些有趣的

epx28資訊網——每日最新資訊28at.com

在 CSS 中,文字算是我們天天會打交道的一大類了,有了文字,則必不可少一些文字裝飾。epx28資訊網——每日最新資訊28at.com

本文將講講兩個比較新的文字裝飾的概念 text-decoration 與 text-emphasis,在最后,還會講解使用 background 模擬文字下劃線的一些有趣的動效。epx28資訊網——每日最新資訊28at.com

text-decoration 文字裝飾

text-decoration 意為文字裝飾,在很早的規范 CSS Level 2 (Revision 1) -- text-decoration[1] 就已經存在了。譬如我們非常熟知的下劃線 text-decoration: underline。epx28資訊網——每日最新資訊28at.com

p {    text-decoration: underline;}

epx28資訊網——每日最新資訊28at.com

而到了比較新的 CSS Text Decoration Module Level 3 - text-decoration[2],text-decoration 得到了比較大的豐富更新,演化出了:epx28資訊網——每日最新資訊28at.com

  • text-decoration-line
  • text-decoration-color
  • text-decoration-style
  • 和還未成為標準的 text-decoration-thickness 等屬性。

如今,text-decoration 是上述 4 個屬性的的縮寫。epx28資訊網——每日最新資訊28at.com

其中:epx28資訊網——每日最新資訊28at.com

  • text-decoration-line:控制用于設置元素中的文本的修飾類型,是在文本下方、上方還是貫穿文本
  • text-decoration-style:不僅僅是實線 solid,類似于 border-style,還支持雙實線 double、點劃線 dotted、虛線 dashed 以及非常有意思的 wavy 波浪線
  • text-decoration-color:這個好理解,控制顏色
  • text-decoration-thickness:控制修飾線的粗細

這里有張非常好的圖,幫助大家快速理解:epx28資訊網——每日最新資訊28at.com

epx28資訊網——每日最新資訊28at.com

CodePen Demo -- Text-decoration Demo[3]epx28資訊網——每日最新資訊28at.com

text-decoration-line 可以同時設置

有意思的一點是,text-decoration-line 可以同時設置。epx28資訊網——每日最新資訊28at.com

p {    text-decoration-line: overline underline line-through;}

epx28資訊網——每日最新資訊28at.com

我們可以得到上中下三條線。epx28資訊網——每日最新資訊28at.com

text-decoration 可以進行過渡與動畫

text-decoration 的每個值都是可以進行過渡與動畫的。合理利用,在一些文本強調的地方,非常有用。epx28資訊網——每日最新資訊28at.com

<p class="transition">Lorem ipsum dolor</p>
.transition {    text-decoration-line: underline;    text-decoration-color: transparent;    text-decoration-thickness: 0.1em;    cursor: pointer;    transition: .5s;    &:hover {        text-decoration-color: pink;        text-decoration-thickness: 0.15em;        color: pink;    }}

epx28資訊網——每日最新資訊28at.com

配合另外一個屬性 text-underline-offset,我們還可以實現如下圖這樣有趣的效果:epx28資訊網——每日最新資訊28at.com

epx28資訊網——每日最新資訊28at.com

當然,上述的例子中使用了 text-underline-offset 的變換,但是本身 CSS 是不支持 text-underline-offset 的過渡動畫的,這里借助了 CSS @property 巧妙的實現了 text-underline-offset 的過渡動畫,感興趣的可以具體了解下 CSS @property  的用法。epx28資訊網——每日最新資訊28at.com

CodePen Demo -- 文字下劃線過渡動畫效果[4]epx28資訊網——每日最新資訊28at.com

text-decoration-color 與 color 分離

text-decoration-color 與 color 是可以不一樣的,類似于這樣。epx28資訊網——每日最新資訊28at.com

.color {    text-decoration-style: wavy;    cursor: pointer;    transition: .5s;    &:hover {        color: transparent;        text-decoration-color: pink;    }}

epx28資訊網——每日最新資訊28at.com

有意思,經過這樣,我們其實得到了一條波浪線。epx28資訊網——每日最新資訊28at.com

如果我們把 wavy 下劃線加給元素的偽元素,然后在 hover 的時候添加一個動畫,讓波浪線動起來,得到一個非常好的強調 hover 效果:epx28資訊網——每日最新資訊28at.com

<p class="animation" data-cnotallow="Lorem ibsum dolor Lorem ibsum dolor">Lorem ibsum dolor</p>
.animation {    position: relative;    text-decoration: none;    overflow: hidden;    cursor: pointer;    line-height: 2;        &::before {        content: attr(data-content);        position: absolute;        top: 0;        left: 0;        color: transparent;        white-space: nowrap;        text-decoration-line: underline;        text-decoration-style: wavy;        text-decoration-color: #000;        z-index: -1;    }    &:hover::before {        animation: move 3s infinite linear;    }}@keyframes move {    100% {        transform: translate(-209px, 0);    }}

epx28資訊網——每日最新資訊28at.com

我們利用偽元素添加了一段長于文本本身的文本,并且顏色為透明,但是設置了波浪線的顏色,然后 hover 的時候,通過運動偽元素的 translate 進行波浪線的位移,稍微調試一下 translate 的值,可以做到動畫的首尾相連,實現運動的波浪線的效果。epx28資訊網——每日最新資訊28at.com

CodePen Demo -- text-decoration Demo[5]epx28資訊網——每日最新資訊28at.com

text-emphasis 文字強調

text-emphasis 意為文字強調,是 CSS Text Decoration Module Level 3[6] 才新增的一個屬性,用于增強文字強調的效果。epx28資訊網——每日最新資訊28at.com

在早些時候,我們如果要強調幾個字,可能更多是使用加粗,斜體這種較為常規的文字樣式類型:epx28資訊網——每日最新資訊28at.com

{    font-weight: bold;   // 加粗    font-style: italic;  // 斜體}

現在,多了一種有意思的強調方式 -- text-emphasis。epx28資訊網——每日最新資訊28at.com

text-emphasis 語法

text-emphasis 包含了 text-emphasis 和 text-emphasis-position,允許我們在文字上方或者下方添加不同的強調裝飾以及不同的顏色。epx28資訊網——每日最新資訊28at.com

看個簡單的 Demo:epx28資訊網——每日最新資訊28at.com

<p>   This is <span>Text-emphasis</span>.</p>
p span{    text-emphasis: circle;}

text-emphasis: circle 的效果是給包裹的文字,在其上方,添加 circle 圖形,也就是圓圈圖形,效果如下:epx28資訊網——每日最新資訊28at.com

epx28資訊網——每日最新資訊28at.com

當然,默認是黑色的,我們可以在 circle 后面補充顏色:epx28資訊網——每日最新資訊28at.com

p span{    text-emphasis: circle #f00;}

epx28資訊網——每日最新資訊28at.com

除了 circle,還提供非常多種圖形可以選擇,也可以自定義傳入字符,甚至是 emoji 表情:epx28資訊網——每日最新資訊28at.com

<p>    A B C D      <span class="keyword">E F</span>    G H    <span class="word">I J</span>    K L    <span class="emoji">M N</span></p>
.keyword {    text-emphasis: circle #f00;}.word {    text-emphasis: 'x' blue;}.emoji {    text-emphasis: ' 
                

本文鏈接:http://www.www897cc.com/showinfo-26-70457-0.html太強了!CSS 文字效果還能這樣玩

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: 一篇文章,徹底理解數據庫操作語言:DDL、DML、DCL、TCL

下一篇: Kubernetes Informer基本原理,你明白了嗎?

標簽:
  • 熱門焦點
Top 主站蜘蛛池模板: 剑阁县| 郎溪县| 二连浩特市| 定襄县| 方山县| 灵川县| 于都县| 大悟县| 贵阳市| 张家川| 饶平县| 郸城县| 南京市| 泉州市| 科尔| 古田县| 东乡族自治县| 嘉义市| 乐陵市| 禄劝| 上虞市| 肇州县| 新邵县| 中西区| 始兴县| 莫力| 桐梓县| 渭南市| 莎车县| 汾阳市| 余庆县| 乐山市| 濮阳县| 安远县| 延安市| 秭归县| 碌曲县| 大悟县| 琼中| 丹江口市| 阿克|