gpt4 book ai didi

html - margin : 0 auto; not working when linked to external css

转载 作者:太空宇宙 更新时间:2023-11-04 05:20:48 24 4
gpt4 key购买 nike

当我链接到我的外部样式表时,我的包装样式似乎被破坏了。如果我将样式粘贴到我的 index.html 的头部,它工作得很好,但在链接到 .css 时就不行了。所有其他 css 规则都可以完美地工作,只有包装器样式似乎被破坏了。

适用于包装器的唯一规则是将其置于浏览器中心,所以如果有其他合理的方法来实现这一点,我会洗耳恭听。

包装器 css:

#wrapper { 
width: 960px;
margin: 0 auto;
}

和 html(减去内容):

<body>
<div id="wrapper">
<div id="header">
</div>
<div id="nav">
</div>
<div id="content">
<div id="cont_left">
</div>
<div id="cont_right">
</div>
</div>
<div id="footer">
</div>
</div>
</body>

任何帮助或建议都会很棒。

编辑:这里是完整的 CSS:

#wrapper {
width: 960px;
margin: 0 auto;
}

#header {
width: 960px;
height: 144px;
background-image: url(../images/header.jpg);
background-repeat: repeat-x;
margin-bottom: -14px;
}

#logo {
margin-right: 48px;
margin-top: 33px;
float: right;
}

#logo a img {
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
}

#tagline {
margin-top: 90px;
margin-left: 48px;
float: left;
clear: both;
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
font-style: normal;
color: #CCC;
}

#nav {
width: 960px;
height: 48px;
background-image: url(../images/nav_bar.jpg);
background-repeat: repeat-x;
}

#nav_bar {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-style: normal;
font-weight: bold;
margin-left: -50px;
padding-top: 14px;
}

#nav_bar li {
display: inline;
padding-left: 58px;
}

#nav_bar li a {
text-decoration: none;
color: #999;
padding: 4px;
}

#nav_bar li a:hover {
color: #fff;
background-color: #666;
}

.current {
color: #CCC;
}

#content {
float: left;
width: 960px;
background-image: url(../images/content.jpg);
background-repeat: repeat-x;
}

#cont_left {
width: 40%;
margin: 48px;
float: left;
}

#cont_right {
width: 40%;
margin: 48px;
float: right;
}

#footer {
clear: both;
height: 48px;
width: 960px;
background-image: url(../images/footer.jpg);
background-repeat: repeat-x;
}

#footer_list {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #666;
font-style: normal;
text-align: center;
padding-top: 16px;
}

#footer_list li {
display: inline;
padding: 18px;
}

#footer_list li a {
text-decoration: none;
color: #666;
padding: 4px;
}

#footer_list li a:hover {
color: #000;
text-decoration: underline;
}

h1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 48px;
line-height: 20px;
font-weight: normal;
margin: 0px;
padding-top: 0px;
padding-bottom: 12px;
}

p {
font-family:Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 20px;
}

body {
background-image: url(../images/background.jpg);
background-repeat: repeat-x;
}

编辑添加:网站未上线,因此我无法提供链接,抱歉。仍处于早期开发阶段,卡在了这个问题上。

最佳答案

您使用的是什么浏览器?我刚刚在 IE8 中试过你的示例,它根本不会居中,除非我包含 XHTML 文档类型:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

不知道为什么,或者您是否有这个,但它可能会有所帮助。

关于html - margin : 0 auto; not working when linked to external css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6626782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com