写的代码多了,就会发现,自己越来越无知了,总以为html css很简单,已经掌握的很熟练了,其实我还差的很多。 平时没有用过css的这种写法 .a.b{display:block;} 上网一查才明白。
代码如下:
<p class="important warning">This paragraph is a very important warning.</p>我们假设 class 为 important 的所有元素都是粗体,而 class 为 warning 的所有元素为斜体,class 中同时包含 important 和 warning 的所有元素还有一个银色的背景 。就可以写作:
代码如下:
.important {font-weight:bold;}.warning {font-weight:italic;}.important.warning {background:silver;}代码如下:
.important.urgent {background:silver;}不出所料,这个选择器将只匹配 class 属性中包含词 important 和 urgent 的 p 元素。因此,如果一个 p 元素的 class 属性中只有词 important 和 warning,将不能匹配。不过,它能匹配以下元素:
代码如下:
<p class="important urgent warning">This paragraph is a very important and urgent warning.</p>