简体   繁体   English

IE9在左浮动图像之间添加不必要的空间

[英]IE9 Adding unwanted space between left floated image

I have six images inside anchor tags. 我在锚标签中有六个图像。 In CSS they are floated left. 在CSS中,它们向左浮动。

In Chrome/Firefox, the images are all butted right up against each other. 在Chrome / Firefox中,所有图像都彼此对接。 But in IE9 there is a space between all the images and I can see the background colour of the DIV between them. 但是在IE9中,所有图像之间都有一个空格,我可以看到它们之间DIV的背景色。 How can I make these images all touch right up to each other? 如何使这些图像彼此完全接触?

My HTML: 我的HTML:

<div id="headerMenu">
    <a href="<?php bloginfo('url'); ?>/category/cateogry1"><img alt="cateogry1" src="<?php bloginfo('template_directory'); ?>/images/cateogry1.jpg"></a>
    <a href="<?php bloginfo('url'); ?>/category/cateogry2"><img alt="cateogry2" src="<?php bloginfo('template_directory'); ?>/images/cateogry2.jpg"></a>
    <a href="<?php bloginfo('url'); ?>/category/cateogry3"><img alt="cateogry3" src="<?php bloginfo('template_directory'); ?>/cateogry3.jpg"></a>
    <a href="<?php bloginfo('url'); ?>/category/cateogry4"><img alt="cateogry4" src="<?php bloginfo('template_directory'); ?>/images/cateogry4.jpg"></a>
    <a href="<?php bloginfo('url'); ?>/category/cateogry5"><img alt="cateogry5" src="<?php bloginfo('template_directory'); ?>/images/cateogry5.jpg"></a>
    <a href="<?php bloginfo('url'); ?>/category/cateogry6"><img alt="cateogry6" src="<?php bloginfo('template_directory'); ?>/images/cateogry6.jpg"></a>
</div>

My CSS: 我的CSS:

#headerMenu{
height: 50px;
margin: 0;
}

#headerMenu img {
float: left;
margin: 0;
}

a, img {
border: 0px;
margin: 0px;
padding: 0px;
}

Would be grateful for any clues....! 任何线索将不胜感激....!

I couldn't reproduce this in IE9, but I could in IE8. 我无法在IE9中重现它,但可以在IE8中重现。

Try floating the <a> that contains the <img> rather than the image. 尝试浮动包含<img>而不是图像的<a> Then set the img to display: block . 然后将img设置为display: block Like this: 像这样:

#headerMenu{
  height: 50px;
  margin: 0;
}

#headerMenu a {
  float: left /* Add */
}

#headerMenu img {
  /* float: left; Remove */
  margin: 0;
}

a, img {
  border: 0px;
  margin: 0px;
  padding: 0px;
  display: block; /* Add */
}

Demo here. 演示在这里。

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

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