用div+css解決出現水平捲軸問題_經驗交流

來源:互聯網
上載者:User
十分鬱悶的問題,看下我原來寫的代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> <style type="text/css"> body{width:990px;} #head{height:95px;width:990px;} </style> </head> <body> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
居然出現了水平捲軸,問題是我定義的寬度才950px啊!最後還是在網友的協助下,發現了原因:

1 可以直接把body的css改為:
body{width:990px; margin:0; padding:0;}
2 可以添加:

* {margin:0;padding:0;}添加後運行效果:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> <style type="text/css"> * {margin:0;padding:0;} body{width:990px;} #head{height:95px;width:990px;} </style> </head> <body> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
  • 相關文章

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.