CSS无法按预期方式呈现。谁能指出错误?

时间:2018-09-09 09:31:19

标签: html css

我有一个用于对div框进行样式设置的代码段。但是,css没有按预期呈现。谁能帮我指出错误。我已经为此创建了fiddle

下面是CSS代码。

div.orange {
  width: 1280px;
  height: 320;
  background-color: rgb(255, 102, 0);
}

div.white {
  width: 1280px;
  height: 320;
  background-color: rgb(255, 255, 255);
}

div.green {
  width: 1280px;
  height: 320;
  background-color: rgb(0, 255, 0);
}

下面是HTML代码

<div class="orange"></div>
<div class="white"></div>
<div class="green"></div>

3 个答案:

答案 0 :(得分:0)

将px添加到高度:

div.orange {
  width: 1280px;
  height: 320px;
  background-color: rgb(255, 102, 0);
}

div.white {
  width: 1280px;
  height: 320px;
  background-color: rgb(255, 255, 255);
}

div.green {
  width: 1280px;
  height: 320px;
  background-color: rgb(0, 255, 0);
}

答案 1 :(得分:0)

高度规则必须具有一个度量单位,例如 px

div.orange {
  width: 1280px;
  height: 320px;
  background-color: rgb(255, 102, 0);
}

div.white {
  width: 1280px;
  height: 320px;
  background-color: rgb(255, 255, 255);
}

div.green {
  width: 1280px;
  height: 320px;
  background-color: rgb(0, 255, 0);
}

答案 2 :(得分:-1)

因此,第一个问题:您是否在HTML文件中导入了CSS文件? 如果不是这样的话:

<link rel="stylesheet" type="text/css" media="screen" href="style.css" />

第二件事是,您不得写:

div.green { your properties }

这是正常的方式:

.green { your properties }