<html><head><meta name="keywords" content="博客,梁栋"/><meta name="author" content="梁栋"/><meta name="description" content="个人网站"/><meta http-equiv="Content-Type" content="text/html;charset=gbk"/><title>个人网站</title><style>body {margin : 0;padding 0;}.top_div {margin : 0;width :100%;height : 180px;background-color : yellow;}.top_main_div {width : 960px;height : 180px;background-color : blue;margin-left : 95px;float : left;}.top_log_div {width : 150px;height : 50px;background-color : white;float: right;text-indent : 20px;line-height : 50px;font-size : 20px;}.login {background : pink;padding : 0;margin-right : 20px;}.register {background : pink;padding : 0;}.menu_bar{background : green;width : 100%;height : 50px;}.menu {height : 50px;width : 700px;background : red;margin-left:95px;float : left;}.search_div {height : 50px;width : 100px;background : pink;float : left;}</style></head><body><div class="top_div"> <div class="top_main_div"> <div class="top_log_div"> <a class="login">登陆</a> <a class="register">注册</a> </div> </div></div><div class="menu_bar"> <div class="menu"></div> <div class="search_div"></div></div></body></html>
放在IE里是居中的,放在chrome,firefox里就偏左了,布局怎么解决浏览器兼容性的,求标准做法永久解除此类问题困扰。。
回复讨论(解决方案)
我在FF和ie8下看到的都是偏左的
你在定义top_main_div的样式时,不是按照居中显示定义的,而是按照1024*768的分辨率显示的,这样肯定有误差
<center class="top_div"> <div class="top_main_div"> <div class="top_log_div"> <a class="login">登陆</a> <a class="register">注册</a> </div> </div></center>
将最外层的 div 改成 center,然后修改相应的样式表,把float和margin-left去掉,即可居中显示了,但在 XHTML 1.0 Strict DTD 中好象不支持
恩。。。http://www.cnblogs.com/zhutianxiang/archive/2012/01/19/2320349.html
这个链接里有答案,要设置display : inline。
display : inline
.top_main_div {width : 960px;height : 180px;background-color : blue;margin-left : 95px;margin:0 auto;}
要居中用 marginleft 和 marginright要同时设成auto,而且不能是浮动的
<!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 name="keywords" content="博客,梁栋"/><meta name="author" content="梁栋"/><meta name="description" content="个人网站"/><meta http-equiv="Content-Type" content="text/html;charset=gbk"/><title>个人网站</title><style>* { margin: 0px auto; padding: 0px;}.top_div { width : 960px; height : 180px; background-color : yellow;}.top_main_div { width : 960px; height : 180px; background-color : blue; float : left;}.top_log_div { width : 150px; height : 50px; background-color : white; float: right; text-indent : 20px; line-height : 50px; font-size : 20px;}.login { background : pink; margin-right : 20px;}.register { background : pink;}.menu_bar{ background : green; width : 960px; height : 50px;}.menu { height : 50px; width : 700px; background : red; float : left;}.search_div { height : 50px; width : 100px; background : pink; float : left;}</style></head><body><div class="top_div"> <div class="top_main_div"> <div class="top_log_div"> <a class="login">登陆</a> <a class="register">注册</a> </div> </div></div><div class="menu_bar"> <div class="menu"></div> <div class="search_div"></div></div></body></html>
写css 要加上
nbsp;HTML>
....
实践多了自然就明白了。要像居中 body{margin:0px auto;} 外围的层.top_main_div{margin:0px auto;} 这个不算是bug兼容问题了,是你样式本身写法就有问题。
上面说的外围的层说错了,是新加一个最外围的层来包括所有的内部层,
学习了, 已经解决了, 谢谢大家.

HTML標籤和屬性的使用方法包括:1.基本用法:使用標籤如和,通過屬性如src和href添加必要信息。 2.高級用法:使用data-*自定義屬性實現複雜交互。 3.避免常見錯誤:確保屬性值用引號包圍。 4.性能優化:保持簡潔,使用標準屬性和CSS類名,確保圖像有alt屬性。掌握這些將提升網頁開發技能。

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

HTML的未來將朝著更加語義化、功能化和模塊化的方向發展。 1)語義化將使標籤更明確地描述內容,提升SEO和無障礙訪問。 2)功能化將引入新元素和屬性,滿足用戶需求。 3)模塊化將支持組件化開發,提高代碼復用性。

htmlattributesarecrucialinwebdevelopment forcontrollingBehavior,外觀和功能

alt屬性是HTML中標籤的重要部分,用於提供圖片的替代文本。 1.當圖片無法加載時,alt屬性中的文本會顯示,提升用戶體驗。 2.屏幕閱讀器使用alt屬性幫助視障用戶理解圖片內容。 3.搜索引擎索引alt屬性中的文本,提高網頁的SEO排名。

HTML、CSS和JavaScript在網頁開發中的作用分別是:1.HTML用於構建網頁結構;2.CSS用於美化網頁外觀;3.JavaScript用於實現動態交互。通過標籤、樣式和腳本,這三者共同構築了現代網頁的核心功能。

設置標籤的lang屬性是優化網頁可訪問性和SEO的關鍵步驟。 1)在標籤中設置lang屬性,如。 2)在多語言內容中,為不同語言部分設置lang屬性,如。 3)使用符合ISO639-1標準的語言代碼,如"en"、"fr"、"zh"等。正確設置lang屬性可以提高網頁的可訪問性和搜索引擎排名。

htmlattributeseresene forenhancingwebelements'functionalityandAppearance.TheyAdDinformationTodeFineBehavior,外觀和互動,使網站互動,響應式,visalalyAppealing.AttributesLikutesLikeSlikEslikesrc,href,href,href,類,類型,類型,和dissabledtransfransformformformformformformformformformformformformformformforment


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

WebStorm Mac版
好用的JavaScript開發工具

Dreamweaver CS6
視覺化網頁開發工具

記事本++7.3.1
好用且免費的程式碼編輯器

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。