如何将大于整个页面 100% 的元素居中对齐?
我有一个宽度为 100% 的 div,并且隐藏了一个宽度为 3000px 的 div。我希望3000px的div左右均匀地被切断。我会使用背景位置:中心;然而,事情比这更复杂。 3000px div 包含 30 100px div。我尝试过在 3000px div 的左侧和右侧使用自动边距,但它不起作用。这是 css:
.bgAnimHolder{
width:100%;
height:500px;
overflow:hidden;
position:absolute;
z-index:1;
top:0px;
}
.row{
margin: 0 auto 0 auto;
height:500px;
width:3000px;
}
.row div{
width:100px;
float:left;
margin-top:0px;
}
无论屏幕分辨率如何,如何将 3000px div 放置在屏幕中间?我愿意使用 CSS 或 JavaScript,无论是解决问题所必需的。谢谢!
I have a div width a with of 100% and hidden overflow holding a div with a width of 3000px. I want the 3000px div to be cut off evenly on the left and right. I would use background-position:center; however, it's more complicated than that. The 3000px div is holding 30 100px divs. I have tried using auto margins on the left and right of the 3000px div, but it did not work. Here is the css:
.bgAnimHolder{
width:100%;
height:500px;
overflow:hidden;
position:absolute;
z-index:1;
top:0px;
}
.row{
margin: 0 auto 0 auto;
height:500px;
width:3000px;
}
.row div{
width:100px;
float:left;
margin-top:0px;
}
How can I arrange the 3000px div to be positioned in the middle of the screen, regardless of screen resolution? I am willing to use CSS or JavaScript, whichever is necessary to solve the problem. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 CSS 来做到这一点:
只需确保父级上有一个
position:absolute/relative
You can do it with CSS:
Just make sure the parent has a
position: absolute/relative
on it我可能不理解你的问题的根源,但你可以将容器的左边距和右边距设置为(相同的)负值。为了简洁/清晰,我的代码被简化。
I may not be understanding the root of your issue, but you can set the left and right margins of a container to (the same) negative values. My code is simplified for brevity/clarity.