【问题标题】:DIV Background color not showing with body colorDIV 背景颜色不与正文颜色一起显示
【发布时间】:2014-02-26 07:13:43
【问题描述】:

我已将正文背景颜色设置为浅灰色#D6D6D6并且我希望有一个显示背景颜色为浅蓝色#2390bb但是,这不起作用,div 不显示淡蓝色。任何想法为什么?非常感谢,这是代码;

HTML;

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<style>
body {
background-color: #D6D6D6;
}
</style>
</head>
<body>
<!--TOP COLOR BG-->
<div id="bg-top"></div>

</body>
</html>

CSS;

#bg-top {
background-color: #2390bb;
}

这是我想要的表示;

【问题讨论】:

  • 您的问题是... div 没有内容... 没有宽度/高度... 所以蓝色不显示
  • 啊,谢谢,知道如何消除边缘的缝隙吗?

标签: css html colors background


【解决方案1】:

按照我的评论:

您的问题是 div 没有内容...没有宽度/高度...因此不显示蓝色。

在 css 中使用它来避免边缘的间隙:

#bg-top {
  background-color: #2390bb;
  position:absolute; 
  top:0;
  left:0;
  width: 100%;
  height: 200px;
}

如果对您有帮助,请将答案标记为解决方案!

【讨论】:

    猜你喜欢
    • 2010-12-19
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 2012-04-02
    • 1970-01-01
    相关资源
    最近更新 更多