我有一个问题,我创建了一个主 div 并使用中心标签使其出现在页面的中心并且它在 Firefox 中工作正常但在 IE 中即使在使用中心标签后它仍然出现在左侧,我也尝试了边距=自动。请提出建议。
最佳答案
margin: 0 auto;
是实现此目的的最佳方式。
元素不能有float:;
。
该元素不能显示为inline-block
或inline
元素。
元素必须显示为 block
元素并且具有定义的宽度。
CSS
.container {
display: block;
width: 960px;
margin: 0 auto;
}
HTML
<div class="container">
whee, i'm a centered div!
</div>
您的整个页面代码:
<!DOCTYPE html>
<html>
<head>
<title>My Page Title</title>
<style type="text/css">
.container {
display: block;
width: 960px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="container">
whee, i'm a centered div!
</div>
</body>
</html>
关于html - IE中如何让主div出现在中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7467121/