【发布时间】:2016-02-27 16:42:01
【问题描述】:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<style>
.ribbon-left {left: 10px;top: 20px; width: 400px; height: 300px;position: absolute;}
.css-table {display: table;margin: 0;padding: 0;background-color: red;}
.css-row { display: table-row; }
.css-cell {display: table-cell;vertical-align: middle; }
.ribbon-left-middle {width: 80%;bottom: 0;padding-left: 5px;position: relative; }
.ribbon-left-middle-inner {top: 5px;position: absolute;}
</style>
</head>
<body>
<div class="ribbon-left">
<div class="css-table">
<div class="css-row">
<div class="css-cell ribbon-left-middle">
<div class="ribbon-left-middle-inner">
<div class="productElements">Product elements</div>
<div class="productDescription">Product description</div>
<div class="productUsage">Product usage</div>
</div>
</div>
</div>
</div>
</div>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<style>
.ribbon-left {left: 10px;top: 20px; width: 400px; height: 300px;position: absolute;}
.css-table {display: table;margin: 0;padding: 0;background-color: red;}
.css-row { display: table-row; }
.css-cell {display: table-cell;vertical-align: middle; }
.ribbon-left-middle {width: 80%;bottom: 0;padding-left: 5px;position: relative; }
.ribbon-left-middle-inner {top: 5px;position: absolute;}
</style>
</head>
<body>
<div class="ribbon-left">
<div class="css-table">
<div class="css-row">
<div class="css-cell ribbon-left-middle">
<div class="ribbon-left-middle-inner">
<div class="productElements">Product elements</div>
<div class="productDescription">Product description</div>
<div class="productUsage">Product usage</div>
</div>
</div>
</div>
</div>
</div>
这是我的例子。我已经为 css 表父 div 定义了红色背景颜色。为什么子div中的文本没有红色背景?背景不是传给孩子的吗?
相同的示例只是我有多个“css-cell” div,红色背景在那里。 我应该在这里改变什么?
【问题讨论】:
-
您可以将子元素的背景颜色设置为“继承”
-
你能接受答案吗?