首頁  >  文章  >  web前端  >  css怎麼把橫著的字豎起來

css怎麼把橫著的字豎起來

藏色散人
藏色散人原創
2020-12-16 10:06:583210瀏覽

css把橫著的字豎起來的實作方法:先建立一個HTML範例檔;然後定義一個div文字;最後一個設定css樣式為「{width: 20px;margin: 0 auto;line-height: 24px;}」即可將文字豎起來。

css怎麼把橫著的字豎起來

本教學操作環境:windows7系統、css3版,此方法適用於所有品牌電腦。

推薦:《css影片教學

1、一個句子的垂直排列

#如圖:

css怎麼把橫著的字豎起來

#
<!DOCTYPE html>  
<html>  
<head>  
    <title>test</title>  
    <meta charset="UTF-8">  
</head>  
<style>  
.one {  
    width: 20px;  
    margin: 0 auto;  
    line-height: 24px;  
    font-size: 20px;
}
.two {  
    width: 15px;  
    margin: 0 auto;  
    line-height: 24px;  
    font-size: 20px;  
    word-wrap: break-word;/*英文的时候需要加上这句,自动换行*/  
}  
</style>  
<body>  
    <div class="one">我是竖列排版</div>  
    <div class="two">I AM ENGLISH</div>  
</body>  
</html>

2、多個句子垂直排列(如古詩)

如圖:

css怎麼把橫著的字豎起來

<!DOCTYPE html>  
<html>  
<head>  
    <title>test</title>  
    <meta charset="UTF-8">  
</head>  
<style>  
.one {  
    margin: 0 auto;  
    height: 140px;  
    writing-mode: vertical-lr;/*从左向右 从右向左是 writing-mode: vertical-rl;*/  
    writing-mode: tb-lr;/*IE浏览器的从左向右 从右向左是 writing-mode: tb-rl;*/  
}  
</style>  
<body>  
    <div class="one">欲话毗陵君反袂,欲言夏口我沾衣。谁知临老相逢日,悲叹声多语笑稀。</div>  
    <div class="one">I AM ENGLISH</div>
</body>  
</html>

3、字體橫行,整體垂直排版

如圖:

css怎麼把橫著的字豎起來

<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta charset="UTF-8">
</head>
<style>
.one {
margin: 150px auto;
width: 200px;
font-size: 20px; 
line-height: 24px;
transform:rotate(90deg);
-ms-transform:rotate(90deg); /* IE 9 */
-moz-transform:rotate(90deg); /* Firefox */
-webkit-transform:rotate(90deg); /* Safari 和 Chrome */
-o-transform:rotate(90deg); /* Opera */
}
</style>
<body>
<div class="one">欲话毗陵君反袂</div>
<div class="one">ENGLISH</div>
</body>
</html>

以上是css怎麼把橫著的字豎起來的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn