html - 将 div 放置在屏幕中央的 CSS 布局

标签 html css

关于 css 布局:

#container{
width:979px;
height:590px;
margin-left:auto; //works
margin-right:auto; //works
margin-top:auto; //doesn't work
margin-bottom:auto; //doesn't work
}

因此,我希望将#container 放置在屏幕中央。
我也试过:margin:auto - 没有结果。

最佳答案

比如:

#container{
width:979px;
height:590px;
position:absolute;
left:50%;
top:50%;
margin:-295px 0 0 -490px;
}

关于html - 将 div 放置在屏幕中央的 CSS 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11582231/

相关文章:

html - 选择框的高度在 ie7 问题中增长

html - 如何使用 CSS 对齐居中文本?

javascript - 使用 Javascript 显示隐藏的 CSS 类 - 表单元素

html - 图像周围的边框和阴影不起作用

html - br 在 ul 中无效

Jquery img on.load 仅在硬刷新页面时有效

html - 使用 Bootstrap 在 Div 中添加水平和垂直响应填充

html - 行高导致滑动 url 效果中断

css - 使用数据 URI 而不是 Sprite 图像有什么缺点?

jquery - 网站背景广告