简体   繁体   English

CSS重复Y在IE8中不起作用

[英]css repeat-y not working in IE8

I am using a div tag and I am applying css to it. 我正在使用div标签,并对其应用css。 Please find below the div tag 请在div标签下面找到

<div class="testcss">
</div>

My css class is as follows 我的css类如下

.testcss
{
     background-image: url('images/imag2.gif');
     background-repeat: repeat-y;
     background-position: bottom-left;
     padding-left: 10px;
     padding-right: 10px;
}

The div is showing background image and displaying properly in Mozilla other browsers but it is not working in IE8 and IE9. div显示背景图片并在Mozilla其他浏览器中正确显示,但在IE8和IE9中不起作用。 Even it is working fine in IE10. 即使在IE10中也能正常工作。 There is some issue with background-repeat: repeat-y not working properly in IE8 and IE9. 后台重复存在一些问题:重复-在IE8和IE9中无法正常工作。 Is there some way that we can fix this in IE8 and IE9. 有什么办法可以解决IE8和IE9中的问题。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thanks in Advance. 提前致谢。

Regards, Rahul Rathi 此致Rahul Rathi

I believe your syntax is wrong, and no.. it should work in IE8 and IE9 ... try: 我相信您的语法是错误的,并且不可以。它应该可以在IE8和IE9中工作...尝试:

.testcss {
    background: url('images/imag2.gif') bottom left repeat-y;
    padding-left: 10px;
    padding-right: 10px;
}

http://jsfiddle.net/feitla/85XFu/ http://jsfiddle.net/feitla/85XFu/

PS - tested in IE9... background repeated just fine. PS-在IE9中进行了测试...背景可以重复使用。 Make sure your div actually has a set height/width if it is empty. 如果您的div为空,请确保它实际上具有设置的高度/宽度。

I agree with @feitla on the fact that your syntax is wrong. 对于您的语法错误,我同意@feitla。 You can't use bottom-left as it doesn't exist in the background property for CSS. 您不能使用bottom-left因为CSS的background属性中不存在bottom-left

I also agree that you should simply use background: url('images/imag2.gif') left repeat-y as the bottom is not needed because it's already repeating in the Y axis and spanning all the height of the container. 我也同意,您应该只使用background: url('images/imag2.gif') left repeat-y ,因为不需要bottom ,因为它已经在Y轴上重复了并且跨越了容器的所有高度。

Last but not least, you do have to set a width and a height to your element if it's empty (as in with no other markup) because otherwise you would only be able to see 20 pixels in width because of your padding left and right. 最后但并非最不重要的一点是,如果元素为空,则必须为元素设置宽度和高度(没有其他标记),因为否则,由于左右的填充,您只能看到20像素的宽度。

I think that the lesson to take from this is that it's safer to use shorthand styles as it makes your code cleaner and easier to read. 我认为从中可以吸取的教训是,使用速记样式会更安全,因为它可使您的代码更整洁,更易于阅读。

You would end up with: 您最终将得到:

HTML 的HTML

<div class="testcss"></div>

CSS 的CSS

.testcss {
   background: url('images/imag2.gif') repeat-y left;
   padding: 0 10px;
}

Read more about how to use shorthand code as it makes writing CSS a lot cleaner and more fun... and it's not as hard as it may seem, here's a link to this specific issue and shorthand css for background . 阅读更多有关如何使用速记代码的信息,因为它使编写CSS更加整洁和有趣。而且它并不像看起来那样难, 这里是此特定问题的链接以及background的速记css

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

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