Table of Contents
回复讨论(解决方案)
{dede:global.cfg_webname/} " >{dede:global.cfg_webname/} 
Home Web Front-end HTML Tutorial IE下面网页居中显示的问题_html/css_WEB-ITnose

IE下面网页居中显示的问题_html/css_WEB-ITnose

Jun 21, 2016 am 09:42 AM

ie 居中

页面在Chrome和FF下是居中的,但在IE各个版本下面都是靠左显示的,
<!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">
Copy after login

.center{margin:0px auto;}
Copy after login

这两个都加上了,请问各位大侠还有什么需要注意的地方?


回复讨论(解决方案)

body, html{width:100%;height:100%;}
.center{margin:0px auto;}

body, html{width:100%;height:100%;}
.center{margin:0px auto;}
加上了第一句了,还是不行啊!

相关CSS文件如下:

/*---------- base ---------*/
*{padding:0px;margin:0px;}
html{background:#FFF;}
body{font:12px Verdana,Arial,Tahoma; line-height: 1.8em; color:#999999;}
img{border:none;}

button {
border: 1px solid #CCCCCC;
padding: 5px;
cursor:pointer;
}
a{color:#666666;text-decoration:none;}
a:hover{ background-color:#8D900B; color:#ffffff}
.header a:hover,.pagelist a:hover,.favorite a:hover,.pic a:hover,a.pic:hover{ color:#8D900B; background-color:#ffffff}
ul,li{list-style:none;}
input,select,button{font:12px Verdana,Arial,Tahoma;vertical-align:middle;}
h1, h2, h3, h4, h5, h6 {font-family: "Microsoft YaHei";font-size: 100%;font-weight: normal;}
/*---------- stock ---------*/
.center{margin:0px auto;}
.w960{width:960px;}
.wrapbox {margin: 0 auto;width: 960px;clear:both;}
.mainbox{ width:630px; float:left; overflow:hidden}
.sidebox{ width:300px; float:right; overflow:hidden}
.fl{ float:left}
.fr{ float:right}
.mt1{margin-top:8px;}
.mt2{margin-top:16px;}
.clear{overflow:hidden; clear:both; height:1px; line-height:1px;}
.fs-12{font-size:12px;}
.fc-f60{color:#F60;}
.fc-f90{color:#F90;}
.clr{clear:both;}
.ipt-txt{line-height:15px;padding:4px 5px;border-width:1px;border-style:solid;border-color:#ccc;font-size:12px;margin-right:2px;}
.nb{line-height:20x;padding:1px 2px;border-width:1px;border-style:solid;border-color:#666 #BBB #BBB #666;font-size:12px;margin-right:2px}
.btn-1{padding: 0px;width:56px;height:24px;border:none;background:url(../images/comm-bt.gif) no-repeat;line-height:25px;letter-spacing:1px;cursor:pointer;overflow:hidden;color:#585858;}
.btn-2{width:70px;height:25px;border:none;background:url(../images/btn-bg2.gif) left top no-repeat;line-height:25px;overflow:hidden;color:#444;margin-right:2px;cursor:pointer;}
.header{width:100%;overflow:hidden; margin-bottom: 10px;}
.header_top{background: url("../images/topbar.png") repeat-x scroll 0 -8px transparent;clear: both;height: 28px;line-height:26px;}
.header_top .welcome{float:left;padding-left:10px;height:26px;line-height:26px; }
.header_top a.rss{}
.header_top .toplinks{ float:right;height:26px;line-height:26px;}
.header_top .toplinks a{margin:0 2px;}
.header_top .toplinks span{margin-left:15px;}
.header .top{ /**background:url("../images/line.gif") repeat-x scroll left bottom transparent;**/ border-bottom:1px solid #FAEFE3; height:96px;position: relative;overflow: hidden;}
.logo {height: 85px;width:345px;position:absolute;left:0;top:0}
.logo h1 a {background: url("../images/logo.gif") no-repeat scroll 0 0 transparent;display: block;height: 85px;overflow: hidden;text-indent: -9999em;width: 345px;}
.hi{ float:left}
.userface{ float:right; margin-top:5px;}
.userface img{ border:1px solid #dddddd; padding:1px;}
.userface a:hover{ background:none;}
.userface a:hover img{ border:1px solid #8D900B}
.mylink{ float:left}
.mylink li{ float:left}

把你的HTML的完整代码贴上来呀

要不然你试试这个:
body{ text-align:center; }
.center{ margin:0 auto; text-align:left; }

要不然你试试这个:
body{ text-align:center; }
.center{ margin:0 auto; text-align:left; }
这个倒是居中了,但所有文本也居中了

再为不需要居中的设置text-align:left;不就行了?

很多标签啊,都要设岂不是太麻烦了?

很多标签啊,都要设岂不是太麻烦了?
你把完整的HTML代码贴出来呀,你之前贴的不完整

引用 8 楼 crazyzyc 的回复:很多标签啊,都要设岂不是太麻烦了?
你把完整的HTML代码贴出来呀,你之前贴的不完整

这个是Header.html的代码

<!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"><?=$headtitle?>
Copy after login

哦,你这个代码里找不到.center啊,
估计应该是由JS或PHP动态生成的。
你能把动态生成的代码贴上来吗?(可以通过浏览器的开发者工具得到动态生成的HTML)

刚看了下,浏览器的浏览源文件里也没有.center,我把.center改成 body,还是不行,应该改哪里啊?

你到底要哪部分居中?至少哪个要居中的DIV,要设置width比如996px,然后加margin:0 auto;要不全部都默认width 100%,当然不会居中罗。

相对文件必须要有个宽度

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Building the Structure of Web Pages HTML: Building the Structure of Web Pages Apr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML vs. CSS and JavaScript: Comparing Web Technologies HTML vs. CSS and JavaScript: Comparing Web Technologies Apr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML: Is It a Programming Language or Something Else? HTML: Is It a Programming Language or Something Else? Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

See all articles