css - 不能居中的div

标签 css html center

我无法将 id="a"的 div 居中 on this site

我什么都试过了。如果有人需要我,我可以将我的代码复制并粘贴到 jsFiddle 中。

最佳答案

我假设您想将元素置于浏览器窗口的中心。如果是这样,您需要将元素包装在“容器”DIV 中。然后设置一个widthmargin: 0 auto;就可以了。

<div id="container">
  //Page elements here
</div>

CSS

#container {
  width: 960px;
  margin: 0 auto;
}

关于css - 不能居中的div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9649254/

相关文章:

html - 第三级居中菜单下拉导航问题

css - 按钮中心 CSS

html - 如何滚动父div中的subdivs

javascript - Bootstrap woff2 字体未正确加载

css - 如何将自定义字体添加到 Rails 应用程序

javascript - 在 Android 手机中关闭 Chrome 的建议栏

css - <p> 标签中的文本在移动设备上溢出屏幕左侧

html - .css 中的样式不起作用。怎么了?

html - 如何从文本区域的文本输入中删除下划线?

html - 居中行内 block 保持文本左对齐