zoukankan      html  css  js  c++  java
  • 派生选择器

    派生选择器

    通过依据元素在其位置的上下文关系来定义样式,你可以使标记更加简洁。

    在 CSS1 中,通过这种方式来应用规则的选择器被称为上下文选择器(contextual selectors),这是由于他们依赖于上下文关系来应用或者避免某项规则。在 CSS2 中,他们被称为派生选择器,但是无论你如何称呼它们,它们的作用都是相同的。

    派生选择器允许你根据文档的上下文关系来确定某个标签的样式。通过合理地使用派生选择器,我们可以使 HTML 代码变得更加整洁。

    比方说,你希望列表中的 strong 元素变为斜体字,而不是通常的粗体字,可以这样定义一个派生选择器:

    li strong {
    font-style: italic;
    font-weight: normal;
    }

    请注意标记为 <strong> 的红色代码的上下文关系:

    <p><strong>我是粗体字,不是斜体字,因为我不在列表当中,所以这个规则对我不起作用</strong></p>
    <ol>
    <li><strong>我是斜体字。这是因为strong元素位于li元素内。</strong></li>
    <li>我是正常的字体。</li>
    </ol>

    在上面的例子中,只有 li 元素中的 strong 元素的样式为斜体字,无需为 strong 元素定义特别的 class 或 id,代码更加简洁。

    再看看下面的 CSS 规则:

    strong {
    color: red;
    }
    h2 {
    color: red;
    }
    h2 strong {
    color: blue;
    }

    下面是它施加影响的 HTML:

    <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>
    
  • 相关阅读:
    faster with MyISAM tables than with InnoDB or NDB tables
    w-BIG TABLE 1-toSMALLtable @-toMEMORY
    Indexing and Hashing
    MEMORY Storage Engine MEMORY Tables TEMPORARY TABLE max_heap_table_size
    controlling the variance of request response times and not just worrying about maximizing queries per second
    Variance
    Population Mean
    12.162s 1805.867s
    situations where MyISAM will be faster than InnoDB
    1920.154s 0.309s 30817
  • 原文地址:https://www.cnblogs.com/cxd4321/p/1228307.html
Copyright © 2011-2022 走看看