G Chrome 中的元素对齐与绝对位置
我想要红色方块与绿色方块完全重叠。 在 FF、IE 和 Opera 中一切正常,但在 Chrome 中红色方块向左对齐,而不是居中。 另外,我只能影响 #parent div 及其子元素,因为我制作了一个小书签,并且无法更改其他页面元素。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title></title>
<style type="text/css">
#center { text-align: center; }
#parent {
position: absolute;
display: inline;
}
#nested {
background-color: #c00;
width: 280px !important;
height: 210px !important;
}
</style>
</head>
<body>
<div id="center">
<div id="parent"><div id="nested"></div></div>
<div style="display: inline-block; width: 280px; height: 210px; background-color: #0c0;"></div>
</div>
</body>
</html>
请各位指教!
当我详细阐述 chrome 属性时,我发现当您将 #parent 的位置设置为绝对时,chrome 会强制显示阻塞。如何使其内联?
I want red square exactly overlap green one.
Everything works fine in FF, IE and Opera, but in Chrome red square aligning to the left, not center.
Also, I can affect only on #parent div and its children because I making a bookmarklet and I can't change other page elements.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title></title>
<style type="text/css">
#center { text-align: center; }
#parent {
position: absolute;
display: inline;
}
#nested {
background-color: #c00;
width: 280px !important;
height: 210px !important;
}
</style>
</head>
<body>
<div id="center">
<div id="parent"><div id="nested"></div></div>
<div style="display: inline-block; width: 280px; height: 210px; background-color: #0c0;"></div>
</div>
</body>
</html>
Please, advice!
When I elaborated on chrome properties, I found that chrome is forcing display to block when you set position to absolute for #parent. How to make it inline?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这在视觉上是您所要求的:
#parent
和#nested
的CSS。现场演示
I think this is visually what you asked for:
#parent
and#nested
.Live Demo