使元素在 IE7 中垂直居中显示
我可以让它在除 IE7 之外的所有浏览器中运行。
HTML
<span class="verticalMiddle"></span>
<span class="jArrow inlineWrapper"></span>
<h2 class="inlineWrapper">What is depression?</h2>
CSS
.inlineWrapper {
width: 606px;
margin-left: 10px;
vertical-align: middle;
display: inline-block;
}
.verticalMiddle {
vertical-align: middle;
height: 50px;
width: 0;
display: inline-block;
}
.jArrow {
background: url(http://www.healthquestlongbeach.com/images/library/faq/arrow.png) no-repeat left top;
height: 20px;
width: 22px;
}
h2.inlineWrapper {
width: 563px;
margin-right: 13px;
}
小提琴: http://jsfiddle.net/RfRrG/5/
问题是 h2
被推下购买 .verticalMiddle {height: 50px;}
,但由于某种原因仅在 IE7 中(但不是.jArrow
由于某些奇怪的原因)。
我可以通过添加来解决这个问题
.inlineWrapper {display:inline;}
,但是它会在其他浏览器中破坏它。为什么文本被推下以及如何正确对齐它?
I can get this to work in all browsers but IE7.
HTML
<span class="verticalMiddle"></span>
<span class="jArrow inlineWrapper"></span>
<h2 class="inlineWrapper">What is depression?</h2>
CSS
.inlineWrapper {
width: 606px;
margin-left: 10px;
vertical-align: middle;
display: inline-block;
}
.verticalMiddle {
vertical-align: middle;
height: 50px;
width: 0;
display: inline-block;
}
.jArrow {
background: url(http://www.healthquestlongbeach.com/images/library/faq/arrow.png) no-repeat left top;
height: 20px;
width: 22px;
}
h2.inlineWrapper {
width: 563px;
margin-right: 13px;
}
Fiddle: http://jsfiddle.net/RfRrG/5/
The problem is that the h2
is being pushed down buy the .verticalMiddle {height: 50px;}
, but for some reason only in IE7 (but not .jArrow
for some odd reason).
I can fix this problem by adding
.inlineWrapper {display:inline;}
But then it breaks it in the other browsers. Why is the text getting pushed down and how can I align it correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IE7 中的
display: inline-block
仅适用于自然内联的元素。幸运的是,有一个简单的解决方法。将其替换
为:
在大多数情况下,您还必须 添加
zoom: 1
,但在您的情况下不是必需的。*
是一个“安全黑客” 仅在 IE7 及更低版本中应用该属性。display: inline-block
in IE7 only works on elements that are naturally inline.Fortunately, there's an easy workaround. Replace this:
with this:
In most instances you must also add
zoom: 1
, but it's not required in your case.*
is a "safe hack" that applies the property in only in IE7 and lower.