简体   繁体   English

html外的空白

[英]White space outside the html

I have a simple div which is supposed to be at the centre of the screen.我有一个简单的 div,它应该位于屏幕的中心。 The same code works in Chrome, Firefox but a white space is generated around the html in IE11 and Microsoft Edge.相同的代码在 Chrome、Firefox 中有效,但在 IE11 和 Microsoft Edge 中的 html 周围会生成一个空格。

Please provide any workarounds other than setting the overflow to hidden.请提供除将溢出设置为隐藏之外的任何解决方法。 I have content which might overflow vertically.我的内容可能会垂直溢出。

https://i.stack.imgur.com/ayi34.png 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>

Use flexbox, here is an example that I tested in IE11 so it should work for all your supported browsers.使用 flexbox,这是我在 IE11 中测试的示例,因此它应该适用于所有受支持的浏览器。 I added a margin for the max size so the red box doesn't take up the entire screen, you can remove that if you don't care about that.我为最大尺寸添加了一个边距,因此红色框不会占据整个屏幕,如果您不在乎,可以将其删除。 I also converted your height and width into min-height and min-width in case you wanted the default smallest size.如果您想要默认的最小尺寸,我还将您的高度和宽度转换为最小高度和最小宽度。

 body { margin: 0; padding: 0; height: 100%; }.container { width: 100%; height: 100%; background-color: blue; display: flex; align-content: center; align-items: center; justify-content: center; }.inner { min-width: 200px; min-height: 300px; background-color: red; margin: 4em; }
 <div class="container"> <div class="inner"> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum </p> </div> </div>

The code snippet you provided doesn't reproduce the issue.您提供的代码段不会重现该问题。 It only shows the red div .它只显示红色div Do you want the inner red div in the center of the outside blue div ?你想要在外部蓝色div中心的内部红色div吗? I make a demo and it works in IE 11 and Edge, you could check it:我做了一个演示,它可以在 IE 11 和 Edge 中运行,你可以检查一下:

 body { margin: 0; padding: 0; }.container { text-align: center; width: 100%; height: 100%; background-color: blue; }.inner { display: inline-block; vertical-align: middle; width: 200px; height: 300px; background-color: red; margin: 4em; }
 <div class="container"> <div class="inner"></div> </div>

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

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