关于background设置的问题
来源:互联网 发布:数据分析师薪水杭州 编辑:程序博客网 时间:2024/05/22 01:43
最近在写css的时候遇到了一些关于background设置的问题。当一个div中要设置背景图和背景色的时候,某些时候背景色会覆盖掉背景图。
<div class="bg_color"> <div class="txt"> 测试占位 </div></div>
情况1:背景色和背景图片都设在background里面。背景色和背景图片的都存在。调换背景色和背景图的顺序也都显示了。
.bg_color{background:url(../images/test_pic/top_nav.jpg) no-repeat 10px 0px red;}.txt{height:60px;width:100%;}
情况2:背景图片设在background-image中,背景色设在background中,背景色覆盖了背景图
.bg_color{background-image:url(../images/test_pic/top_nav.jpg) no-repeat 10px 0px;background:red;}.txt{height:60px;width:100%;}
情况3:设置和情况2相同,只是顺序反了一下,背景色覆盖了背景图
.bg_color{background:red;background-image:url(../images/test_pic/top_nav.jpg) no-repeat 10px 0px;}.txt{height:60px;width:100%;}
情况4:背景图放在background中,背景色放在background-color中,背景色和背景图片都显示出来了。
.bg_color{background:url(../images/test_pic/top_nav.jpg) no-repeat 10px 0px;background-color:red;}.txt{height:60px;width:100%;}
情况5:设置和情况4相同,只是顺序反了一下。只显示了背景图,没有显示背景色
.bg_color{background-color:red;background:url(../images/test_pic/top_nav.jpg) no-repeat 10px 0px;}.txt{height:60px;width:100%;}
情况6:设置了background-image和background-color,背景色覆盖了背景图。
.bg_color{background-image:url(../images/test_pic/top_nav.jpg) no-repeat 10px 0px;background-color:red;}.txt{height:60px;width:100%;}
情况7:设置和情况6相同,只是顺序反了一下。背景色覆盖了背景图。
.bg_color{background-color:red;background-image:url(../images/test_pic/top_nav.jpg) no-repeat 10px 0px;}.txt{height:60px;width:100%;}
总结:background具有高优先级,background-color比background-image具有高优先级。使用时要注意先后顺序。
0 0
- 关于background设置的问题
- 关于background设置多个背景图片的问题
- 关于动态设置background(.9格式的) 导致padding失效的问题。
- 关于背景background-position的问题
- 关于css中background-size的问题
- 关于外部样式表中background-image:url()的设置
- 关于设置background属性图片不显示的原因
- 关于css3的background
- a标签设置background url出现的问题
- 关于presentViewController的后的background变黑的问题
- 关于presentViewController的后的background变黑的问题
- 关于presentViewController的后的background变黑的问题
- background引发的问题
- background-image的路径设置
- Html中button标签设置background问题
- 关于background-image:url()在样式表里设置后有不管用的办法
- CBCentralManager 的background mode问题
- background-position百分比的问题
- 引用和指针
- C++的进程和线【windows】
- 最具创新混凝土搅拌机
- Tip2:去除图标的玻璃质感(磨光)效果
- 函数中char c[]="hello"与char * c = "hello"区别 -- C
- 关于background设置的问题
- 更减肥换金更健康很快乐
- 更健康据了解
- Android 中mkdir() 和mkdirs()创建目录的区别
- android 优化
- Flash spec中是如何定义图形的
- iOS转屏
- C语言关键字
- <九度 OJ>题目1084:整数拆分