首頁  >  文章  >  web前端  >  css怎麼實作字母不到一行就換行

css怎麼實作字母不到一行就換行

WBOY
WBOY原創
2021-11-15 15:30:432450瀏覽

css字母不到一行就換行的方法:1、為元素加上「word-break:break-word;」樣式,使其以單字為單位換行;2、給元素加上「word-break :break-all;」樣式,使其以字母為單位換行。

css怎麼實作字母不到一行就換行

本教學操作環境:windows7系統、CSS3&&HTML5版、Dell G3電腦。

css字母不到一行就換行的方法

#開啟一個html程式碼頁面,建立兩個div標籤並輸入一段英文語句。分別設定按字母自動換行和按單字自動換行兩種css樣式。

word-break:break-word;//表示以单词为单位换行,
word-break:break-all;//表示以字母为单位换行。

程式碼如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    .aa{
        width:150px;
        word-break:break-word;
    }
    .bb{
        width:150px;
        word-break:break-all;
    }
    </style>
</head>
<body>
    <div class="aa">When summer comes, unlike most people, I will be very excited, because I like summer very much. People don’t like summer because of its hot weather, which makes people sweat all the time. But summer is my favorite season, I can wear fewer clothes. I like to wear short jeans and a T-shirt, I feel so free.</div>
    <div class="bb">When summer comes, unlike most people, I will be very excited, because I like summer very much. People don’t like summer because of its hot weather, which makes people sweat all the time. But summer is my favorite season, I can wear fewer clothes. I like to wear short jeans and a T-shirt, I feel so free.</div>
</body>
</html>

輸出結果:

css怎麼實作字母不到一行就換行

css怎麼實作字母不到一行就換行

以上便是兩種不同的換行方式。

更多程式相關知識,請造訪:程式設計影片! !

以上是css怎麼實作字母不到一行就換行的詳細內容。更多資訊請關注PHP中文網其他相關文章!

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