Dan*_*Lin 6 html css inheritance
例如,我有一个字体颜色设置为紫色的div,div中的一些文本继承颜色,但有些不是,例如.在一张桌子里.
<div style="color: purple;">
<p>Some text</p> <!-- text here is purple -->
<table>
<tr>
<td>Table cell 1</td> <!-- text here is NOT purple -->
<td>Table cell 2</td> <!-- text here is NOT purple -->
</tr>
</table>
Another text <!-- text here is purple -->
</div>
Run Code Online (Sandbox Code Playgroud)
如果我用身体替换div,他们继承.TEST2
<body style="color: purple;">
<p>Some text</p> <!-- text here is purple -->
<table>
<tr>
<td>Table cell 1</td> <!-- text here is purple -->
<td>Table cell 2</td> <!-- text here is purple -->
</tr>
</table>
Another text <!-- text here is purple -->
</body>
Run Code Online (Sandbox Code Playgroud)
我想知道:
Leo*_*eon 18
这个"问题"是由于您没有声明doctype,导致浏览器以Quircks模式运行.
这样做的一个结果就是你在这里看到的结果:table元素获得的color: -webkit-text;样式覆盖了父div的继承.
添加:
<!DOCTYPE html>
Run Code Online (Sandbox Code Playgroud)
在文档的顶部将导致浏览器呈现您想要的页面.
| 归档时间: |
|
| 查看次数: |
4469 次 |
| 最近记录: |