Heim  >  Artikel  >  Web-Frontend  >  CSS:基本语法及派生选择器_html/css_WEB-ITnose

CSS:基本语法及派生选择器_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:52:591400Durchsuche

本文介绍css基本语法及派生选择器。

代码整理自w3school:http://www.w3school.com.cn

(一)基础部分:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="Content-Language" content="zh-cn"><style type="text/css">h1,h2,h3 {color:red;background-color:#ccc}li strong {font-style:italic;}</style><title>CSS基础</title>  <h1>h1,h2,h3 级标题为CSS样式指定为灰底红字<h1>  <h2>h1,h2,h3 级标题为CSS样式指定为灰底红字<h2>  <h3>h1,h2,h3 级标题为CSS样式指定为灰底红字<h3>  <h4>h4级标题没有被指定样式<h3>  <hr>  <!--派生选择器-->  <h4>派生选择器允许你根据文档的上下文关系来确定某个标签的样式。  </h4>
</h3>
</h4>
</h3>
</h3>
</h2>
</h2>
</h1>
</h1><p><strong>我是粗体字,不是斜体字,因为我不在列表当中,所以这个规则对我不起作用</strong></p>  <ol>    <li><strong>我是斜体字。这是因为 strong 元素位于 li 元素内。</strong></li>    <li>我是正常的字体。</li>  </ol>
效果图:

(二)样式的“覆盖”规则

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="Content-Language" content="zh-cn">  <style type="text/css">    strong {color: red;}    h2 {color: red;}    h2 strong {color: blue;}  </style><title>CSS基础-样式的“覆盖”规则</title>  <p>The strongly emphasized word in this paragraph is <strong>red</strong>.</p>  <h2>This subhead is also red.</h2>  <h2>The strongly emphasized word in this subhead is <strong>blue</strong>.</h2>

效果图:


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn