如何保持一个div里面的文本,如果更大,然后div扩展下来? [英] How can I keep a text of a div inside it and if bigger, then the div expands down?
问题描述
我想知道如果文本超过 width
的话,有一种方法可以将文本保存在div中。
感谢y'all的帮助+1,那么我应该使用'Inherit'还是'最小高度'?
一个简单的 div
::
然后我添加了一个 word-wrap:break-word;
/ strong>
理想:
div
的<$ c $ <>
提前感谢。
div {width:50px; height:50px; border:1px solid red; display:inline-block; word-wrap:break-word; }
<!DOCTYPE html>< html> ;头> < title> DIV< / title>< / head>< body> < div> asjdkljaddddsadsssssssdfsdfsdfs< / div>< / body>< / html>
将高度
更改为 CSS:
min-height
属性用于设置元素的最小高度。
这可以防止height属性的值小于 min-height
。
div {width:50px; min-height:50px; border:1px solid red; display:inline-block; word-wrap:break-word; }
<!DOCTYPE html>< html> ;头> < title> DIV< / title>< / head>< body> < div> asjdkljaddddsadsssssssdfsdfsdfsf< / div>< / body>< / html>
I'd like to know if there's a way to keep a text inside a div if the text exceeds the width
the ´div´'s height is stretched until all the text is fitted.
UPDATE:
Thank y'all for helping +1, so should I use ´Inherit´ or ´min-height´?
A plain div
:
Then I added a word-wrap: break-word;
, and I've got this:
The Ideal:
The div
's height
should be increased in order to fit the whole text
Thanks in advance.
div {
width: 50px;
height: 50px;
border: 1px solid red;
display: inline-block;
word-wrap: break-word;
}
<!DOCTYPE html>
<html>
<head>
<title>DIV</title>
</head>
<body>
<div>asjdkljaddddsadsssssssdfsdfsdfsf</div>
</body>
</html>
Change height
to min-height
in your CSS:
The min-height
property is used to set the minimum height of an element.
This prevents the value of the height property from becoming smaller than min-height
.
div {
width: 50px;
min-height: 50px;
border: 1px solid red;
display: inline-block;
word-wrap: break-word;
}
<!DOCTYPE html>
<html>
<head>
<title>DIV</title>
</head>
<body>
<div>asjdkljaddddsadsssssssdfsdfsdfsf</div>
</body>
</html>
这篇关于如何保持一个div里面的文本,如果更大,然后div扩展下来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!