[英]Centered div with percent width shrinks under certain circumstances
I have a site that places content inside a div with the following styling: 我有一个网站,将内容放置在具有以下样式的div中:
.container {
padding-top: 40px; /*This is to leave space for a floating*/
margin-left: auto;
margin-right: auto;
width: 75%;
background-color: white;
box-shadow: 0px 0px 10px hsla(0, 0%, 0%, 0.5);
}
This works fine on two pages but on a third one, the div shrinks to about half it's normal width, and I cant figure out why. 这可以在两页上正常工作,但在第三页上,div缩小到正常宽度的一半左右,我不知道为什么。 The only obvious difference is that this page contains a list while the others are just paragraphs, but removing the list doesn't fix the problem. 唯一明显的区别是此页面包含一个列表,而其他页面仅是段落,但是删除列表并不能解决问题。 Here are two pens, the page that works and the one that doesn't . 这里有两笔,该网页的作品 ,并且在一个没有 。 The images are missing on the pens but the effect is the same. 笔上没有图像,但效果相同。
Thanks in advance! 提前致谢!
我不明白您为什么要使用position: absolute
body
position: absolute
,但如果将其取出,您的问题就解决了...
You have position:absolute
in body. 您的position:absolute
身体position:absolute
。 In your working examples the text is wide enough so that your its achieving full width but in 3rd example text is small so there is a problem. 在您的工作示例中,文本足够宽,以至于您可以实现全宽,但是在第三个示例中,文本很小,因此存在问题。
You need to assign width:100%
in body or if there is no use just remove it. 您需要在主体中分配width:100%
,或者如果没有用,则将其删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.