【发布时间】:2021-11-03 13:07:48
【问题描述】:
所以标签似乎从来没有很喜欢我。它总是给我带来麻烦,但事实证明他们的解决方案是显而易见的,而我只是愚蠢。但是这一次,我花了 4TH HOUR 试图找出可能出了什么问题(这正是我什至将 body content div 命名为“body”的原因,IK 这是不必要的哈哈)。代码如下:
<!DOCTYPE html>
<!--© Copyright LightVoid Studio-->
<html style="font-family: Helvetica, Cursive; color:white;">
<head>
<meta charset="UTF-8">
<title>LightVoid Studio</title>
</head>
<style>
.body {
background-color:#1A2B30;
}
</style>
<!--break-->
<body>
<div class="body">
<strong>
<p style="position:absolute;top:100px;left:20px;font-size:40px;">Hello</p>
<p style="position:absolute;top:140px;left:20px;">This is the official LightVoid Studio
website. If You're here for the first time, let's tell Ya what We're exactly doing. LightVoid
Studio is a relatively fresh Indie game studio that develops various software, such as games for Your computer.</p>
</div>
</body>
<!--break-->
</html>`
【问题讨论】:
-
也将样式放在 中,它可能会起作用,但是您的 p 标签是绝对位置实际上会将它们拉出 div.body 删除 p 元素的绝对位置,看看是否背景颜色正在处理 div。否则添加一个 position:relative 到 .body 类,这样孩子就相对于它。
-
如有疑问,请使用 HTML 验证器。浏览器旨在修复无效的 HTML,但它们不一定会按照您想要的方式进行。
-
<style>标签可以放在代码中的任何位置。问题是您将.body类的全部内容显示为绝对,因此它的高度将为0。如果您使用inspect 元素,您应该能够看到background-color样式已被应用。