如何随着CSS中文本的数量增加高度?

发布于 2025-01-02 02:03:43 字数 1226 浏览 2 评论 0原文

我遇到这种情况,

<div class="sub_project">
    <div class="sbone brown_gradient optzeci">Description</div>
    <div class="sbtwo optzecitwo">
   Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
    </div>
</div>
.sub_project{
    font-size: 16px;
    margin: 10px 0;
    background: #D7D7D7;
}

.brown_gradient{
    background: #EB994F;
}
.sbone{
    padding: 5px;
    color: white;
    float: left;
    width: 160px;
    margin: 0 10px 0 0;

}

.sbtwo{padding: 5px;}

.optzeci{height: 80px;}
.optzecitwo{min-height: 80px;} * html .optzeci { height:80px; }

我希望

Description
高度随着文本量的增加而增长。

现在我设置了 min-height: 80px; 但我根本不想设置高度。

另外,我不想使用图像或 javascript

请参阅 jsfiddle

有什么想法吗?

谢谢

i have this situation

<div class="sub_project">
    <div class="sbone brown_gradient optzeci">Description</div>
    <div class="sbtwo optzecitwo">
   Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
    </div>
</div>
.sub_project{
    font-size: 16px;
    margin: 10px 0;
    background: #D7D7D7;
}

.brown_gradient{
    background: #EB994F;
}
.sbone{
    padding: 5px;
    color: white;
    float: left;
    width: 160px;
    margin: 0 10px 0 0;

}

.sbtwo{padding: 5px;}

.optzeci{height: 80px;}
.optzecitwo{min-height: 80px;} * html .optzeci { height:80px; }

I would like the <div class="sbone brown_gradient optzeci">Description</div> height to grow with the amount of text.

Right now i set a min-height: 80px; but i do't want to set height at all.

Also i don't want to use images or javascript

See jsfiddle

any ideas?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦言归人 2025-01-09 02:03:44

相对定位容器 .sub_project,并为其提供左侧填充。绝对定位 .optzeci 并给它 top: 0;左:0;底部:0;

http://jsfiddle.net/W7Nrn/9/

.sub_project {
    ...
    padding-left: 175px;
    position: relative;
}
.optzeci {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
}

Relatively position the container, .sub_project, and give it left padding. Absolutely position .optzeci and give it top: 0; left: 0; bottom: 0;.

http://jsfiddle.net/W7Nrn/9/

.sub_project {
    ...
    padding-left: 175px;
    position: relative;
}
.optzeci {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
}
风月客 2025-01-09 02:03:44

如果你可以使用jquery,那么你可以动态地为盒子分配高度。您只需要获取包含文本的 div 的高度,然后将相同的高度分配给描述框。

这是我的尝试: http://jsfiddle.net/W7Nrn/6/

if you can use jquery then you can assign height to the box on the fly. you just need to get the height on the div containing your text then assign the same height to description box.

here is my try: http://jsfiddle.net/W7Nrn/6/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文