如何获得显示:IE中的表格单元支持?任何纯javascript或jQuery解决方法?

Jit*_*yas 2 javascript css xhtml jquery

如何display:table-cell在IE中获得支持?我需要最轻的解决方案.

小智 7

最快(但不干净)的解决方案是在条件注释中用表包装容器,就像这样

<!--[if lte IE 7 ]><table><td><![endif]-->
<div>                   
 <!-- your markup here -->
</div>
<!--[if lte IE 7 ]></td></table><![endif]--> 
Run Code Online (Sandbox Code Playgroud)

可以接受单个页面,但绝对要大规模避免

否则你可以详细说明为什么要尝试定义一个显示:table-cell.如果这与获得文本的垂直对齐有些相关,您可以查看这段代码

http://jsfiddle.net/fcalderan/985e4/

- 编辑(评论后)

如果您希望获得底部对齐,您还可以设置position : relative为图像容器,然后position: absolute; bottom: 0;设置为图像

- 编辑2(评论后)

我们还在等你的代码.无论如何,产生的CSS将是

#imagecontainer {   /* or whatever image container you have */
  position: relative;
}

#imagecontainer img {
  position: absolute;
  bottom : 0;
  left: 50%; 
  margin-left:-n/2px; /* where 'n' is width of your image */
}
Run Code Online (Sandbox Code Playgroud)

  • 请编辑你的问题,并提供你的标记片段:)我的第一个建议仍然有效,但也许我们可以避免这个伎俩 (2认同)