gpt4 book ai didi

html - 最大高度不会降低文本的高度

转载 作者:太空宇宙 更新时间:2023-11-03 22:13:09 24 4
gpt4 key购买 nike

我试图截断 div 元素内某些文本的高度,但问题是 max-height 不起作用,而 max-width 工作正常。

我的 HTML 代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Page</title>
</head>
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<div class="text">
Improve ashamed married expense bed her comfort pursuit mrs. Four time took ye your as fail lady. Up greatest am exertion or marianne. Shy occasional terminated insensible and inhabiting gay. So know do fond to half on. Now who promise was justice new winding. In finished on he speaking suitable advanced if. Boy happiness sportsmen say prevailed offending concealed nor was provision. Provided so as doubtful on striking required. Waiting we to compass assured.
</div>
</body>
</html>

我的 CSS 代码:

.text{
color: red;
max-height: 10%;
max-width: 80%;
}

这会减小文本的宽度但不会减小高度。

最佳答案

% 计算从父高度/宽度开始。 .text parent 是 body,body 没有应用高度。所以实际上 max-height: 10%; 不会被正确计算。尝试添加一些包装器并在 px 中添加一些高度以查看差异。例如:

.wrapper {
height: 400px;
outline: 1px solid red;
}

.text{
outline: 1px solid green;
color: red;
max-height: 10%;
max-width: 80%;
}
<div class=wrapper>
<div class="text">
Improve ashamed married expense bed her comfort pursuit mrs. Four time took ye your as fail lady. Up greatest am exertion or marianne. Shy occasional terminated insensible and inhabiting gay. So know do fond to half on. Now who promise was justice new winding. In finished on he speaking suitable advanced if. Boy happiness sportsmen say prevailed offending concealed nor was provision. Provided so as doubtful on striking required. Waiting we to compass assured.
</div>
</div>

关于html - 最大高度不会降低文本的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58266966/

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