gpt4 book ai didi

html - 为什么我添加了 css 后我的页面没有显示背景颜色

转载 作者:行者123 更新时间:2023-11-27 23:10:04 24 4
gpt4 key购买 nike

HTML代码:-

    <!DOCTYPE html>
<html>
<head>
<title>The block-chain website</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">

</div>

</body>
</html>

这是CSS代码:-

    *{
margin: 0px;
padding: 0px;
font-family: sans-serif;
}

.container{
width: 100%;
height: 100%;
background-color: #42455a;
}

我页面中的问题是具有该颜色的 div 没有出现在屏幕上。

最佳答案

未设置htmlbodywidthheight 属性。它们将由其中的内容自动设置。由于您只有一个没有内容的 div,因此定义 widthheight 属性不会使 bodyhtml 扩展为您根据父维度定义这些百分比。

只需定义htmlbodywidthheight:

*{
margin: 0px;
padding: 0px;
font-family: sans-serif;
}

.container{
width: 100%;
height: 100%;
background-color: #42455a;
}

html, body {
height: 100%;
width: 100%;
}

关于html - 为什么我添加了 css 后我的页面没有显示背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58578846/

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