居中嵌套div [英] Centering nested divs

查看:187
本文介绍了居中嵌套div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再次遇到以div为中心的问题...

Once again I'm having issues centering divs...

http://www.srcf.ucam.org/~sas98/project.php

我如何

推荐答案

集中< div class =main> ; c c c $ $ c>,而不是 #main - 您的HTML和CSS在这一点上不同意):

To center <div class="main"> (and it is a class - that means it's .main, not #main - your HTML and CSS do not agree with each other on this point):


  • 添加 margin:0 auto; width:1020px .main 1020px 是正确的号码。

  • 您还需要删除 width:100% code>从正文,否则您的居中将不准确。

  • 您还应删除 overflow:hidden 从 body ,或在您的网页上无法滚动。

  • Add margin: 0 auto; width: 1020px to .main. 1020px is the right number to use here.
  • You also need to remove width: 100% from body, or your centering will not be precisely correct.
  • You should also remove overflow: hidden from body, or scrolling is impossible on your page.

最后,添加正确的doctype作为第一行,或者您的网页位于 Quirks Mode ,你会特别遇到Internet Explorer的大问题:

Lastly, add a proper doctype as the very first line, or your page is in Quirks Mode and you'll in particular have big problems with Internet Explorer:

<!DOCTYPE html>

我不确定您的页脚应该做什么。

I'm not sure what your footer is supposed to be doing.

这篇关于居中嵌套div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆