本文将分享CSS拉伸背景图像的详细内容,并且还将对css背景拉伸进行详尽解释,此外,我们还将为大家带来关于css–使用rgba背景颜色覆盖背景图像、css–在IE8中拉伸背景图像、css–垂直拉伸背景
本文将分享CSS拉伸背景图像的详细内容,并且还将对css 背景拉伸进行详尽解释,此外,我们还将为大家带来关于css – 使用rgba背景颜色覆盖背景图像、css – 在IE8中拉伸背景图像、css – 垂直拉伸背景图像、css – 多个背景图像和背景颜色的相关知识,希望对你有所帮助。
本文目录一览:CSS拉伸背景图像(css 背景拉伸)
background: black url("/image/background.jpg") no-repeat fixed center;
解决方法
对于较旧的浏览器(尤其是旧版本的IE),我在使用this one之类的jQuery插件方面取得了很大成功,可以模拟这种行为.
css – 使用rgba背景颜色覆盖背景图像
我想知道是否有一个一维的解决方案(即不是与多个div,一个为图像和一个为颜色等)。
我尝试了多种东西:
<divid="test-1"></div> <divid="test-2"></div> <divid="test-3"></div>
和这个CSS:
.the-div { background-image: url('the-image'); margin: 10px; width: 200px; height: 80px; } #test-1:hover { background-color: rgba(0,0.1); } #test-2:hover { background: url('the-image'),rgba(0,0.1); } #test-3:hover { background: rgba(0,0.1); }
见this fiddle。
我看到的唯一选择是使用覆盖,使用JavaScript预加载另一个图像,然后使用.the-div:hover {background:url(‘the-new-image’); }。但是,我想要一个纯CSS解决方案(更整洁;更少的HTTP请求;更少的硬盘)。有没有?
解决方法
<div>Red text</div> <style type="text/css"> .the-div { background-image: url("the-image.png"); color: #f00; margin: 10px; width: 200px; height: 80px; } .the-div:hover { background-image: linear-gradient(to bottom,0.1),0.1)),url("the-image.png"); background-image: -moz-linear-gradient(top,url("the-image.png"); background-image: -o-linear-gradient(top,url("the-image.png"); background-image: -ms-linear-gradient(top,url("the-image.png"); background-image: -webkit-gradient(linear,left top,left bottom,from(rgba(0,to(rgba(0,0.1))),url("the-image.png"); background-image: -webkit-linear-gradient(top,url("the-image.png"); } </style>
见fiddle.太糟糕了,梯度规格目前是一团糟。看到compatibility table,上面的代码应该在任何具有显着市场份额的浏览器中工作 – 除了MSIE 9.0及更早版本。
css – 在IE8中拉伸背景图像
@H_301_0@.Box:before { background: url(images/body_background2.png) no-repeat; display: block; position: absolute; z-index: -1; height: 100%; width: 100%; content: ''; }
解决方法
有关详细信息,请参阅以下文章:How Do you Stretch a Background Image in a Web Page.
如果您希望将图像用作给定< div>的背景.尝试以下方法:
<div> <imgsrc="yourImageSrc" /> </div>
.fullbackground{ position:relative; } img.fullbackground{ position:absolute; z-index:-1; top:0; left:0; width:100%; /* alternative: right:0; */ height:100%; /* alternative: bottom:0; */ }
css – 垂直拉伸背景图像
background-image: url("left.png"),url("right.png"),url("center.png") background-repeat: no-repeat,no-repeat,repeat-x background-position: top left,top right,top
现在我想垂直拉伸这些图像,它们一直延伸到底部.有没有办法做到这一点?
解决方法
background-size: auto 100%;
这将垂直适合图像,让宽度做任何它需要做的事情(我认为它默认重复).您还可以设置:
background-repeat: no-repeat;
因为它不会在水平方向重复图像.
css – 多个背景图像和背景颜色
我可以使用多个背景图片:
div.arrow{ background: url('arrowtail.png') left no-repeat,url('arrowhead.png') right no-repeat; }
html:
<div>This text is on a transparent background</div>
这给了我一个带箭头和尾巴的div,以及一个透明的中间部分.
中间部分的颜色似乎不可能.
只有一个背景图像,您可以这样做:
div.arrow{ background: red url('some_image.png') no-repeat; }
我知道这是可行的很多方法,但背景颜色的属性真的从速记定义?
解决方法
div.arrow { background: url('arrowtail.png') left no-repeat,url('arrowhead.png') right no-repeat,red; }
请注意,对于您的场景,您的图像可能必须具有完全不透明的背景.背景颜色将显示在图像的任何透明像素下.
jsFiddle demo
然而,单独声明背景颜色可能会比您的场景好多了,因为它可以让您根据相同的背景图像使用不同的颜色(如果您的图像部分上的透明像素可以填充CSS背景)颜色):
div.arrow { background: url('arrowtail.png') left no-repeat,url('arrowhead.png') right no-repeat; } /* Assuming your red arrow has this ID */ #red { background-color: red; }
jsFiddle demo
我们今天的关于CSS拉伸背景图像和css 背景拉伸的分享就到这里,谢谢您的阅读,如果想了解更多关于css – 使用rgba背景颜色覆盖背景图像、css – 在IE8中拉伸背景图像、css – 垂直拉伸背景图像、css – 多个背景图像和背景颜色的相关信息,可以在本站进行搜索。
本文标签: