gpt4 book ai didi

css - 为什么容器在 body 的外面

转载 作者:行者123 更新时间:2023-11-28 10:40:07 25 4
gpt4 key购买 nike

为什么容器在body的外面?我希望内容具有所有正文的 100% 宽度,而不是正文和页眉。

<!DOCTYPE html>
<html>
<head>
<title>dsfsd</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="styl.css">
</head>
<body>
<div id="doc">
<header class="topbar"></header>
<div class="container"></div>
</div>
</body>
</html>

这是我的CSS:

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
}
#doc {
width: 100%;
height: 100%;
background: #f4f4f4;
}
.topbar {
width: 100%;
height: 48px;
background: #e0e0e0;
}
.container {
margin: 0 auto;
width: 960px;
height: 100%;
background: red;
}

请帮我解决这个问题。 :)

最佳答案

如果您希望您的容器宽度是主体的宽度,请将 .container 更改为 width:100%; 而不是给它一个 px宽度。如果那是你要问的。

关于css - 为什么容器在 body 的外面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23174888/

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