Apply CSS Style to child elements(将 CSS 样式应用于子元素)
问题描述
我只想将样式应用于具有特定类的 DIV 内的表:
注意:我宁愿为子元素使用 CSS 选择器.
为什么 #1 有效而 #2 无效?
1:
2:
HTML:
我做错了什么?
这段代码div.test th, td, caption {padding:40px 100px 40px 50px;}
" 将规则应用于所有除了 all 之外,
元素和 所有 th
元素包含在具有名为 test
的类的 div
元素中tdcaption
元素.
它不同于一个divtd
、th
和caption
元素> 具有 test
类的元素".为此,您需要更改选择器:
'>
' 不受某些旧浏览器的完全支持(我在看着你,Internet Explorer).
I want to apply styles only to the table inside the DIV with a particular class:
Note: I'd rather use a css-selector for children elements.
Why does the #1 works and #2 doesn't?
1:
2:
HTML:
What am I doing wrong?
This code "div.test th, td, caption {padding:40px 100px 40px 50px;}
" applies a rule to all th
elements which are contained by a div
element with a class named test
, in addition to all td
elements and all caption
elements.
It is not the same as "all td
, th
and caption
elements which are contained by a div
element with a class of test
". To accomplish that you need to change your selectors:
'>
' isn't fully supported by some older browsers (I'm looking at you, Internet Explorer).
这篇关于将 CSS 样式应用于子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!