Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 背景色css属性在表中不起作用_Html_Css_Web - Fatal编程技术网

Html 背景色css属性在表中不起作用

Html 背景色css属性在表中不起作用,html,css,web,Html,Css,Web,以下是html和CSS代码: 表,th,td{ 边框:1px纯蓝色; 边界塌陷:塌陷; } 运输署{ 文本对齐:居中; } td{padding:10px; 颜色:#cc7722; } 桌子{ 边界间距:5px; 背景颜色:黄绿色; 字体大小:粗体; 宽度:100% } #你好{ 颜色:红色; } .嗨{ 背景颜色:蓝色; } 员工数据 员工姓名 部门 薪水 维巴夫 CSE 10000 将类移动到th是否满足了您的需要 表,th,td{ 边框:1px纯蓝色; 边界塌陷:塌陷; } 运输署{

以下是html和CSS代码:

表,th,td{
边框:1px纯蓝色;
边界塌陷:塌陷;
}
运输署{
文本对齐:居中;
}
td{padding:10px;
颜色:#cc7722;
}
桌子{
边界间距:5px;
背景颜色:黄绿色;
字体大小:粗体;
宽度:100%
}
#你好{
颜色:红色;
}
.嗨{
背景颜色:蓝色;
}

员工数据
员工姓名
部门
薪水
维巴夫
CSE
10000

将类移动到th是否满足了您的需要

表,th,td{
边框:1px纯蓝色;
边界塌陷:塌陷;
}
运输署{
文本对齐:居中;
}
td{padding:10px;
颜色:#cc7722;
}
桌子{
边界间距:5px;
背景颜色:黄绿色;
字体大小:粗体;
宽度:100%
}
#你好{
颜色:红色;
}
.嗨{
背景颜色:蓝色;
}

员工数据
员工姓名
部门
薪水
维巴夫
CSE
10000

不能在表格中使用div进行样式设置。只需将该类应用于tr本身

html


员工数据
员工姓名
部门
薪水
维巴夫
CSE
10000

您的表中不应该有div,而是必须这样做:

<tr class="hi">

我认为您想要做的是更改
背景,您可以通过删除
并将类赋予
标记轻松完成此操作。详情如下:

<table>
      <caption id="hello">Employee Data</caption>
      <tr class="hi">
        <th>Employee Name</th>
        <th>Department</th>
        <th>Salary</th>
      </tr>
      <tr>
        <td>Vaibhav</td>
        <td>CSE</td>
        <td>10000</td>
      </tr>
</table>

如果将
div
用作单元格值以外的任何值,则会出现行为不正常的浏览器

将标题行定义环绕在
thead
标记周围,并设置相应的样式。然后别忘了将车身包裹在
t车身上

表格,
th,
运输署{
边框:1px纯蓝色;
边界塌陷:塌陷;
}
运输署{
文本对齐:居中;
}
运输署{
填充:10px;
颜色:#cc7722;
}
桌子{
边界间距:5px;
背景颜色:黄绿色;
字体大小:粗体;
宽度:100%
}
#你好{
颜色:红色;
}
.嗨{
背景颜色:蓝色;
}

员工数据
员工姓名
部门
薪水
维巴夫
CSE
10000

如果可能更改html,则可以使用AD、tbody组合来设置桌面和主体的不同颜色

范例

<style>
thead {color:green;}
tbody {background:blue;}
tfoot {color:red;}

table, th, td {
border: 1px solid black;
}
</style>


   <table>
  <thead>
  <tr>
     <th>Month</th>
     <th>Savings</th>
  </tr>
  </thead>
  <tfoot>
  <tr>
      <td>Sum</td>
      <td>$180</td>
  </tr>
  </tfoot>
  <tbody>
  <tr>
     <td>January</td>
     <td>$100</td>
  </tr>
  <tr>
      <td>February</td>
      <td>$80</td>
  </tr>
  </tbody>
</table>

thead{颜色:绿色;}
tbody{背景:蓝色;}
tfoot{color:red;}
表,th,td{
边框:1px纯黑;
}
月
储蓄
总和
$180
一月
$100
二月
$80
t车身
中的所有
tr
均为蓝色背景


否则,您必须分别为
tr
th
使用样式

添加
div
内部
th,td
它不会在外部工作

表,th,td{
边框:1px纯蓝色;
边界塌陷:塌陷;
}
运输署{
文本对齐:居中;
}
td{padding:10px;
颜色:#cc7722;
}
桌子{
边界间距:5px;
背景颜色:黄绿色;
字体大小:粗体;
宽度:100%
}
#你好{
颜色:红色;
}
.嗨{
背景颜色:蓝色;
}

员工数据
员工姓名
部门
薪水
维巴夫
CSE
10000

div不允许作为tr元素的子元素。您只能将div放入th或tr元素中。可能是因为HTML无效。没有理由让否决您的人这么做。你的回答是正确的。我在投票。
table,th,td{
  border:1px solid blue;
  border-collapse:collapse;
}
td{
  text-align:center;
}
td{padding:10px;
  color:#cc7722;
}
table{
  border-spacing:5px;
  background-color:yellowgreen;
  font-weight:bold;
  width:100%
}
#hello{
  color:red;
}
.hi{
  background-color:blue;
}
<style>
thead {color:green;}
tbody {background:blue;}
tfoot {color:red;}

table, th, td {
border: 1px solid black;
}
</style>


   <table>
  <thead>
  <tr>
     <th>Month</th>
     <th>Savings</th>
  </tr>
  </thead>
  <tfoot>
  <tr>
      <td>Sum</td>
      <td>$180</td>
  </tr>
  </tfoot>
  <tbody>
  <tr>
     <td>January</td>
     <td>$100</td>
  </tr>
  <tr>
      <td>February</td>
      <td>$80</td>
  </tr>
  </tbody>
</table>