<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>
What I see under FF and ie8 are left-leaning
You are defining The style of top_main_div is not defined according to the centered display, but is displayed according to the resolution of 1024*768. There must be errors
<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>
is not supported in XHTML 1.0 Strict DTD. . . http://www.cnblogs.com/zhutianxiang/archive/2012/01/19/2320349.html
There is an answer in this link, you need to set display: inline.
display : inline
.top_main_div {width : 960px;height : 180px;background-color : blue;margin-left : 95px;margin:0 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>
When writing css, add
....
More practice Naturally you will understand. It should be like centered body{margin:0px auto;} and outer layer .top_main_div{margin:0px auto;}. This is not a bug compatibility issue, but a problem with the way you write the style itself.
The peripheral layer mentioned above is wrong. A new outermost layer is added to include all internal layers.
I learned it and have solved it. Thank you everyone.