简体   繁体   English

CSS-图像标题框在IE9中无法正常工作

[英]CSS - Image Caption Box Not Working Correctly In IE9

I have an image with a caption box it works fine in all the other browsers apart from Internet Explorer 9 and I'm not sure why? 我有一个带标题框的图像,它在Internet Explorer 9之外的所有其他浏览器中都可以正常工作,我不确定为什么吗? and how can I fix it? 以及如何解决? the images and captions overlap each other and the text go behind the image. 图像和标题彼此重叠,并且文本位于图像后面。

I have posted the code and also a demo JSFiddle . 我已经发布了代码,还发布了演示JSFiddle

 .caption-box { width: 100%; height: auto; display: inline; } .caption-box .imageHolder { display: inline-block; width: auto; margin: 0 auto; margin-bottom: 5px; } .imageHolder { position: relative; width: 220px; height: 150px; border: 3px solid #ddd; } .imageHolder:hover { opacity: 0.9; border: 3px solid #333; } .imageHolder img { width: 220px; height: 150px; } .imageHolder .caption { position: absolute; width: 220px; height: 27px; bottom: 0px; left: 0px; color: #ffffff; background: #333; text-align: center; opacity: 0.7; padding-top: 15px; } .imageHolder .caption a:visited, a:link { color: #fff; text-decoration: none; } .imageHolder .caption a:hover { color: #fff; text-decoration: underline; } 
 <div class="caption-box"> <a href="#"> <div class="imageHolder"> <img src="http://lorempixel.com/output/animals-qc-640-480-7.jpg" /> <div class="caption"><a href="#">Title</a> </div> </div> </a> <a href="#"> <div class="imageHolder"> <img src="http://lorempixel.com/output/animals-qc-640-480-7.jpg" /> <div class="caption"><a href="#">Title</a> </div> </div> </a> <a href="#"> <div class="imageHolder"> <img src="http://lorempixel.com/output/animals-qc-640-480-7.jpg" /> <div class="caption"><a href="#">Title</a> </div> </div> </a> <a href="#"> <div class="imageHolder"> <img src="http://lorempixel.com/output/animals-qc-640-480-7.jpg" /> <div class="caption"><a href="#">Title</a> </div> </div> </a> <a href="#"> <div class="imageHolder"> <img src="http://lorempixel.com/output/animals-qc-640-480-7.jpg" /> <div class="caption"><a href="#">Title</a> </div> </div> </a> <a href="#"> <div class="imageHolder"> <img src="http://lorempixel.com/output/animals-qc-640-480-7.jpg" /> <div class="caption"><a href="#">Title</a> </div> </div> </a> </div> 

You are putting div inside an anchor element. 您正在将div放入锚元素中。 It is a rendering error: in fact IE9 does not allow to use block element inside a inline element , as for HTML4 specs. 这是一个渲染错误:实际上,对于HTML4规范,IE9不允许在inline element内使用block元素。

See this answer . 看到这个答案

HTML 4.01 specifies that <a> elements may only contain inline elements . HTML 4.01指定<a>元素只能包含内联元素 A <div> is a block element , so it may not appear inside an <a> . <div>是一个块元素 ,因此它可能不会出现在<a>内部。

Of course you are at liberty to style an inline element such that it appears to be a block, or indeed style a block so that it is rendered inline. 当然,您可以随意设置内联元素的样式,使其看起来像是一个块,或者也可以对一个块进行样式化,以使其内联。 The use of the terms inline and block in HTML refers to the relationship of the elements to the semantic structure of the document, whereas the same terms in CSS are related more to the visual styling of the elements. HTML中的内联和块术语的使用是指元素与文档语义结构之间的关系,而CSS中的相同术语更多地与元素的视觉样式相关。 If you make inline elements display in a blocky manner, that's fine. 如果使内联元素以块状显示,那很好。

However you should ensure that the structure of the document still makes sense when CSS is not present, for example when accessed via an assistive technology such as a screen reader - or indeed when examined by the mighty Googlebot." 但是,当不存在CSS时,例如通过屏幕阅读器等辅助技术进行访问时,或者确实由强大的Googlebot检查时,您应该确保文档的结构仍然有意义。”

Here is how IE9 sees your code: IE9看到您的代码的方式如下:

在此处输入图片说明

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

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