[精讚] [會員登入]
9730

CSS 垂直中文字

要把文字垂直顯示的處理中文字正轉或逆轉90度的css設定

分享此文連結 //n.sfs.tw/13102

分享連結 CSS 垂直中文字@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2019-10-25 11:43:34 最後編修
2019-02-12 16:02:35 By 張○○
 

自動目錄

CSS中如果想要用直列的文字,只要把文字選擇直式顯示即可,這時可使用 writing-mode屬性。

這個屬性預設是水平顯示,也就是

writing-mode: horizontal-tb;

可以使用由右到左和由左到右的垂直顯示方式

writing-mode: vertical-rl;

writing-mode: vertical-lr;

來看看範例

由右至左垂直文字

HTML

<div>ABC 123 中文字<br/>DEF 667 第二行</div>

CSS

writing-mode: vertical-rl;

 

由左至右垂直文字

HTML

<div>ABC 123 中文字<br/>DEF 667 第二行</div>

CSS

writing-mode: vertical-lr;

上面的設定中,英文的方向都是由右到左,如果想要讓他轉個180度,突然想到原本CSS有個由右至左有CSS,不知管不管用:

direction: rtl;

上面這個只對水平顯示有用,對垂直的是完全沒作用。

 

所以如果要讓文字轉180度,就得使用 text-orientation 這個屬性質,他有幾個參數可以設定[1]

text-orientation: mixed;  預設值,就是上面看到的那樣

text-orientation: upright;

text-orientation: sideways-right;

text-orientation: sideways;

text-orientation: use-glyph-orientation;

text-orientation: inherit;

text-orientation: initial;

text-orientation: unset;

CSS

writing-mode: vertical-lr;
text-orientation: upright;

CSS

writing-mode: vertical-lr;
text-orientation: sideways-right;

原本轉不過去的中文字也橫轉

 

CSS

writing-mode: vertical-lr;
text-orientation: sideways;

sidewayssideways-right 看不出差異,這兩個是相同的。

text-orientation: use-glyph-orientation; 這個是給svg圖型用的,搭配作廢的什麼svg屬性,有興趣的人再去研究

到目前為只,都沒有辦法把文字轉向逆時針90度方向,無論中文或英數,都只能垂直或是順轉90度。

要逆轉90度或更多,得使出殺手鐧了。

 

中文字逆轉90度

使用transform的rotate函數

writing-mode: vertical-rl;
text-orientation: sideways;
transform: rotate(-180deg);

writing-mode: vertical-rl;
text-orientation: upright;
transform: rotate(-90deg);

如果把upright的轉90度,就會變成這樣,字掉到畫面外,因為字的align是中央,旋轉後以中央為軸心

你得設定區塊的寬度讓他可以完全顯示,加上以下:

width:200px;

或是修改旋轉的軸心,這部分可以參考[3] +transform-origin(0,0)。這裡我沒有試,他的範例還做了一個時鐘,超酷的。

 

參考資料

[1] https://developer.mozilla.org/en-US/docs/Web/CSS/text-orientation

[2] 改变CSS世界纵横规则的writing-mode属性 https://www.zhangxinxu.com/wordpress/2016/04/css-writing-mode/

[3] CSS沒有極限 - CSS transform-origin https://wcc723.github.io/css/2013/10/10/css-transform-origin/

END

你可能感興趣的文章

[CSS] placeholder 屬性的CSS怎麼設定? 常會用到的placeholder可以在沒填值時有提示的文字,想要改變格式該怎麼做?

[HTML5] script 的新增屬性 defer, async script 的新增屬性 defer, async

[CSS] 改變文字選擇的顏色(反選的顏色) 我們會用滑鼠選取一小段文字,可能是為了複製或是為了看他清楚點,這篇來改變他選擇時的背影色。

網頁自動轉址的四種方法 設定網頁自動轉址的四種方法,三種html,一種php

[HTLM5] 表單color、email、url、search、tel輸入類型 介紹HTML5好用的輸入類型:color、email、url,以及兩個形同雞肋的類型search、tel..

textarea計算字數和行數 textarea可以大量的放入文字,但要如何計算字數和行數呢?

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

[Windows7] 移除IE10及移除IE11 Windows7 不得已的情況要移除IE11或IE10怎麼做?

[札記] 2016.7~12月札記 札記,只是札記

NETCRAFT發現你的網站及作業系統 NETCRAFT可以發現你的網站及作業系統

[MAC] 安裝APACHE+PHP OS Darwin OpenIDMac1deAir 15.6.0 Darwin Kernel Version 15.6.

[AS3] FLASH 引入外部as檔 FLASH AS3中,若要引用另外撰寫的 class(*.as) 檔案,該如何處理?