【发布时间】:2019-09-25 13:25:21
【问题描述】:
我有一个简单的 div,它应该位于屏幕的中心。相同的代码在 Chrome、Firefox 中有效,但在 IE11 和 Microsoft Edge 中的 html 周围会生成一个空格。
请提供除将溢出设置为隐藏之外的任何解决方法。我的内容可能会垂直溢出。
https://i.stack.imgur.com/ayi34.png
body {
margin: 0;
padding: 0;
}
.container {
position: relative;
width: 100%;
height: 100%;
background-color: blue;
}
.inner {
position: absolute;
width: 200px;
height: 300px;
background-color: red;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="container">
<div class="inner"></div>
</div>
【问题讨论】:
-
尝试在
*上添加 box-sizing :css-tricks.com/box-sizing -
@Riskbreaker 不起作用。
标签: html css internet-explorer