超碰人人人人人,亚洲AV午夜福利精品一区二区,亚洲欧美综合区丁香五月1区,日韩欧美亚洲系列

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

原生JavaScript實(shí)現(xiàn)文本內(nèi)容的文字?jǐn)?shù)量變化,適配容器寬度和高度,文本內(nèi)容文字字體的字號大小自動縮小,保障文字全部都在容器內(nèi)顯示完

Ccoffee
2025年4月14日 9:13 本文熱度 411
:原生JavaScript實(shí)現(xiàn)文本內(nèi)容的文字?jǐn)?shù)量變化,適配容器寬度和高度,文本內(nèi)容文字字體的字號大小自動縮小,保障文字全部都在容器內(nèi)顯示完


 

<!DOCTYPE html>

<html lang="en">

 

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>文字自動填充容器</title>

    <style>

        body {

            display: flex;

        }

 

        textarea {

            width: 200px;

            height: 200px;

            margin-left: 20px;

        }

 

        .outer {

            width: 200px;

            height: 200px;

            box-sizing: border-box;

            border: 1px solid #F56C6C;

        }

 

        .container {

            word-wrap: break-word;

            word-break: break-all;

            white-space: break-spaces;

            box-sizing: border-box;

            border: 1px dashed #67C23A;

        }

    </style>

</head>

 

<body>

    <div class="outer">

        <div class="container">這是一段很長的文本內(nèi)容,當(dāng)內(nèi)容超出容器寬度時,字體大小會自動縮小來適應(yīng)容器。</div>

    </div>

    <textarea oninput="input(this.value)"></textarea>

 

</body>

<script>

    let findFontSize = (container, { text, fontSize = 100, containerHeight = 100 } = {}) => {

        container.innerText = text;

        let setFontSize = (size) => (container.style.fontSize = `${size}px`);

        setFontSize(fontSize);

        // 如果內(nèi)容超過了容器高度就減小字號

        console.log(``, container.offsetHeight);

        while (container.offsetHeight > containerHeight) {

 

            fontSize--, setFontSize(fontSize);

        }

    }

 

    let input = (text) => findFontSize(document.querySelector(`.container`), { text, containerHeight: 200 });

 

</script>

 

</html>

?


該文章在 2025/4/14 9:13:32 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場、車隊(duì)、財務(wù)費(fèi)用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved