简体   繁体   English

根据文本长度设置div背景颜色

[英]Set div background color according to text length

I have a section on website where different testimonials appear and the div has a background color which appears fine on desktop but if viewed on mobile devices the testimonials text runs longer (vertically) than the background height. 我在网站上的某个部分中出现了不同的推荐,并且div的背景颜色在桌面上看起来很好,但是如果在移动设备上查看,则推荐文本的运行时间(垂直)会比背景高度长。

This is the class that is assigned to the div 这是分配给div的类

.quote{
    background-color: #f7f7f7 !important;
    border: 8px none;
    height: 350px;
    padding: 15px;
}

Now I know that the height is fixed to 350px but if I change that to 100% or auto that does not work. 现在我知道高度固定为350px但是如果我将其更改为100%auto不起作用。 I need the background to appear as long as the text appears. 只要文字出现,我就需要背景出现。

If you want the div to be 350px in height, then you're doing it right. 如果您希望div的高度为350px ,那么您做对了。 But you will need to add overflow-y: hidden; 但是您将需要添加overflow-y: hidden; or overflow-y: auto . overflow-y: auto

However, I do suggest you simply change height to min-height if you want the div to grow with the text. 但是,如果您希望div与文本一起增长,我建议您仅将height更改为min-height

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM