gpt4 book ai didi

javascript - div 元素的固定大小

转载 作者:行者123 更新时间:2023-11-28 20:12:45 24 4
gpt4 key购买 nike

我正在尝试在 html 中创建一个具有固定大小的 div 元素。我的问题是,上面的 div 接收来自主干的输入文本。文本的大小是未知的,因此每次传输的文本很大时,div 的大小都会自动更改。如何只显示适合 div 预定义边框的文本的第一个单词???

我的CSS代码

.hashTagsCloud {
max-width: 500px;
max-height: 400px;
overflow: hidden;
}

和 html 代码:

                <div class= "hashTagsCloud span4 offset1 "> //bootstrap             
<div id="profiles> //backbone view
<script id="profileTemplate" type="text/template">//backbone template
</script>
</div>
</div>

我使用 getElementById 获取数据。

最佳答案

如果您已经设置了 div 的宽度和高度,则可以使用 overflow:hidden; 属性。

<style type='text/css'>
.text {
width: 100px;
height: 18px;
overflow: hidden;
white-space: pre-line; /* breaks up the text on spaces before hiding */
}
</style>
<div class='text'>some really really really long text</div>

关于javascript - div 元素的固定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19659085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com