溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么用CSS樣式解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題

發(fā)布時(shí)間:2022-03-02 15:51:45 來(lái)源:億速云 閱讀:146 作者:iii 欄目:web開(kāi)發(fā)

這篇文章主要介紹“怎么用CSS樣式解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題”,在日常操作中,相信很多人在怎么用CSS樣式解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”怎么用CSS樣式解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

CSS樣式 解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題

1、一般樣式

  一般 css 樣式,當(dāng)寬度不夠時(shí),可能會(huì)出現(xiàn)換行的效果。這樣的效果在某些時(shí)候肯定是不行的,可以修改 css 樣式來(lái)解決這個(gè)問(wèn)題。

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>text-overflow</title>
        <link rel="stylesheet" type="text/css" href="http://unpkg.com/view-design/dist/styles/iview.css">
        <script type="text/javascript" src="http://vuejs.org/js/vue.min.js"></script>
        <script type="text/javascript" src="http://unpkg.com/view-design/dist/iview.min.js"></script>
        <style type="text/css">
            .demo-split {
                width: 500px;
                height: 100px;
                border: 1px solid #dcdee2;
                background: palegreen;
            }

            .demo-split-pane {
                padding: 10px;
                color: red;
            }
        </style>
    </head>
    <body>
        <div id="app">
            <div class="demo-split">
                <Split v-model="split">
                    <div slot="left" class="demo-split-pane">
                        未使用 clip 自適應(yīng)寬度
                    </div>
                    <div slot="right" class="demo-split-pane">
                        未使用 ellipsis 自適應(yīng)寬度
                    </div>
                </Split>
            </div>
        </div>
    </body>
    <script type="text/javascript">
        new Vue({
            el: '#app',
            data() {
                return {
                    split: 0.4
                }
            }
        })
    </script>
</html>

左側(cè)寬度變小,文字換行。

怎么用CSS樣式解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題

 右側(cè)寬度變小,文字換行。

怎么用CSS樣式解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題

2、文字過(guò)長(zhǎng)顯示省略號(hào)或顯示截取的效果

【通常寫法:】

<style type="text/css">
    .test_demo_clip {
        text-overflow: clip;
        overflow: hidden;
        white-space: nowrap;
        width: 200px;
        background: palegreen;
    }

    .test_demo_ellipsis {
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        width: 200px;
        background: palegreen;
    }
</style>

【說(shuō)明:】
    text-overflow:表示當(dāng)文本溢出時(shí)是否顯示省略標(biāo)記,ellipsis表示省略號(hào)效果,clip 表示截取的效果。
    overflow:hidden;  將文本溢出的內(nèi)容隱藏。
    white-space:nowrap;  是禁止文字換行。
    width:  (可選)可以寫固定值,也可以根據(jù)寬度自適應(yīng)顯示效果。
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>text-overflow</title>
        <link rel="stylesheet" type="text/css" href="http://unpkg.com/view-design/dist/styles/iview.css">
        <script type="text/javascript" src="http://vuejs.org/js/vue.min.js"></script>
        <script type="text/javascript" src="http://unpkg.com/view-design/dist/iview.min.js"></script>
        <style type="text/css">
            .test_demo_clip {
                text-overflow: clip;
                overflow: hidden;
                white-space: nowrap;
                width: 200px;
                background: palegreen;
            }

            .test_demo_ellipsis {
                text-overflow: ellipsis;
                overflow: hidden;
                white-space: nowrap;
                width: 200px;
                background: palegreen;
            }

            .test_demo_defined_Width_clip {
                text-overflow: clip;
                overflow: hidden;
                white-space: nowrap;
                background: bisque;
            }
            
            .test_demo_defined_Width_ellipsis {
                text-overflow: ellipsis;
                overflow: hidden;
                white-space: nowrap;
                background: bisque;
            }

            .demo-split {
                width: 500px;
                height: 100px;
                border: 1px solid #dcdee2;
                background: palegreen;
            }

            .demo-split-pane {
                padding: 10px;
            }
        </style>
    </head>
    <body>
        <div id="app">
            <h3>text-overflow : clip </h3>
            <div class="test_demo_clip">
                不顯示省略標(biāo)記,而是簡(jiǎn)單的裁切條
            </div>
            <br>

            <h3>text-overflow : ellipsis </h3>
            <div class="test_demo_ellipsis">
                當(dāng)對(duì)象內(nèi)文本溢出時(shí)顯示省略標(biāo)記
            </div>
            <br>

            <h3>自定義寬度,根據(jù)寬度自適應(yīng)大小</h3>
            <div class="demo-split">
                <Split v-model="split">
                    <div slot="left" class="demo-split-pane">
                        <div class="test_demo_defined_Width_clip">
                            使用 clip 自適應(yīng)寬度
                        </div>
                    </div>
                    <div slot="right" class="demo-split-pane">
                        <div class="test_demo_defined_Width_ellipsis">
                            使用 ellipsis 自適應(yīng)寬度
                        </div>
                    </div>
                </Split>
            </div>
        </div>
    </body>
    <script type="text/javascript">
        new Vue({
            el: '#app',
            data() {
                return {
                    split: 0.4
                }
            }
        })
    </script>
</html>

clip 顯示裁剪的效果,ellipsis 顯示省略號(hào)的效果。

怎么用CSS樣式解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題

怎么用CSS樣式解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題

怎么用CSS樣式解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題

到此,關(guān)于“怎么用CSS樣式解決文字過(guò)長(zhǎng)顯示省略號(hào)問(wèn)題”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

css
AI