作者:mobiledu2502869467 | 来源:互联网 | 2023-10-13 09:24
Iamusingafixedheightimagetofilladivwithgradientcolorusingsomethinglike:background:t
I am using a fixed height image to fill a div with gradient color using something like: background:transparent url(green_bg.gif) repeat-x scroll 0 0;
我使用固定高度的图像来填充渐变颜色的div使用类似于:background:transparent url(green_bg.gif)repeat-x scroll 0 0;
However it only fills a height equals the image height. What's the best way to fill the backround of a div which changes in height, according to amount of text inside it, either using images or using css?
但是它只填充高度等于图像高度。根据文本中的文本数量,使用图像或使用CSS,填充高度变化的div的背景的最佳方法是什么?
2 个解决方案
I think what you're looking for is a div to be filled with a background image (which is a gradient) and then the rest of the way with a solid color?
我认为你要找的是一个用背景图像填充的div(这是一个渐变)然后剩下的部分用纯色填充?
If so, in photoshop (or the image editor of your choice), get the hex of the last pixel in your gradient. For argument's sake, let's say it is #FF0000. Then do this:
如果是这样,在photoshop(或您选择的图像编辑器)中,获取渐变中最后一个像素的十六进制。为了论证,让我们说它是#FF0000。然后这样做:
.myDiv {
background: #FF0000 url(green_bg.gif) repeat-x 0 0;
}
This will fill your background with #FF0000 (red) and overlay your background image on top of it, repeating horizontally (x-axis) starting at the top of your div. The way to make the red background show is to increase the amount of content in your div.
这将用#FF0000(红色)填充背景,并在背景上覆盖背景图像,从div的顶部开始水平重复(x轴)。制作红色背景的方法是增加div中的内容量。
Also, if you want to make sure that a certain portion of your gradient is always showing, you can increase the padding-top
in your CSS.
此外,如果要确保渐变的某个部分始终显示,则可以增加CSS中的填充顶部。
.myDiv {
background: #FF0000 url(green_bg.gif) repeat-x 0 0;
padding-top: 20px;
}
If this isn't what you're getting at, please clarify in your question.
如果这不是您的目标,请在您的问题中澄清。