简体   繁体   English

IE中的div中的background-image和background-color

[英]background-image & background-color in a div with IE

I have a little issue related to mixing background-image and background-color in a div holder. 我有一个与在div支架中混合background-imagebackground-color有关的小问题。

The div looks like this: div看起来像这样:

<div class="board_position" x="1"  y="1"></div>

The CSS is: CSS是:

.board_position {
width:25px;
height:25px;
margin:1px 0 0 1px;
float:left;
-webkit-border-radius:3px;
-moz-border-radius:3px;
border-radius:3px;

background: #f4f4f4; /* Old browsers */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2Y0ZjRmNCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjIzJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top,  #f4f4f4 0%, #ffffff 23%, #ffffff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f4f4f4), color-stop(23%,#ffffff), color-stop(100%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #f4f4f4 0%,#ffffff 23%,#ffffff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #f4f4f4 0%,#ffffff 23%,#ffffff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #f4f4f4 0%,#ffffff 23%,#ffffff 100%); /* IE10+ */
background: linear-gradient(to bottom,  #f4f4f4 0%,#ffffff 23%,#ffffff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4f4f4', endColorstr='#ffffff',GradientType=0 ); /* IE6-8 */
}

The board_position class draws a rounded box with a gradient background-color. board_position类与绘制渐变背景色圆框。

Some divs with that class have additional properties which I supply by adding another class to that div. 该类的某些div具有其他属性,我可以通过向该div添加另一个类来提供这些属性。 This additional class is only a background-image : 这个额外的类只是一个background-image

<div class="board_position bg" x="3"  y="1"></div>
.bg { background-image:url(/img/bg.png); }

In Chrome, Firefox, Safari and Opera it works fine. 在Chrome,Firefox,Safari和Opera中,它可以正常运行。

But in IE the result is a squared box (not rounded) and in the board_position divs which have additional properties added with another class, the image loaded is not shown because it seems that the image is under the background-color . 但是在IE中,结果是一个方形框(未四舍五入),并且在board_position div中添加了与其他类一起添加的其他属性,因此未显示加载的图像,因为该图像似乎在background-color

Is there any solution to this issue? 这个问题有解决方案吗?

Which version of IE? 哪个版本的IE? CSS 3 attributes like border radius are not functional in older versions of IE and result in square corners. CSS 3属性(例如边框半径)在IE的较早版本中不起作用,并会导致出现圆角。 Secondly your css selector .bg and .border_position have the same rule of important so the last one in the css will win so if you list bg first then board_positon, board position will win. 其次,您的css选择器.bg和.border_position具有相同的重要规则,因此css中的最后一个将获胜,因此,如果您先列出bg,然后选择board_positon,则棋盘位置将获胜。 to make sure .bg wins add more to the selector like .board_position.bg now this has importance of 020 and the bkg will overrule .board_position which has a value of 010. 要确保.bg获胜,请向选择器添加更多内容,例如.board_position.bg,这现在的重要性为020,而bkg将否决.board_position的值,即010。

IE8 and under does not support rounded corners. IE8及以下版本不支持圆角。

Try using http://css3pie.com/ 尝试使用http://css3pie.com/

Please remember to use the fixes in http://css3pie.com/documentation/known-issues/ 请记住使用http://css3pie.com/documentation/known-issues/中的修补程序

IE8 doesn't support rounded borders. IE8不支持圆角边框。 As for the other issue, remember that the image path is relative to the CSS file, not the file that links it. 至于另一个问题,请记住图像路径是相对于CSS文件的,而不是相对于链接它的文件的。

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

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