热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

灵活div的背景渐变填充,使用css还是图像?-Backgroundgradientfillforflexiblediv's,eitherusingcssorimages?

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 个解决方案

#1


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.

如果这不是您的目标,请在您的问题中澄清。

#2


I would say background SVG. But afaik they are only supported in safari atm.

我会说背景SVG。但afaik他们只在safari atm支持。

or maybe webkit has a property that does the gradient. Or canvas if you really need it.

或者webkit有一个执行渐变的属性。或者画布,如果你真的需要它。


推荐阅读
author-avatar
mobiledu2502869467
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有