Rumah  >  Soal Jawab  >  teks badan

Peraturan CSS digunakan tanpa kelas, mengapa?

<p>Saya mentakrifkan peraturan CSS: </p> <pre class="brush:php;toolbar:false;">.info-specs h2, h3, h4, h5 { saiz fon: 1.5em; text-transform: tiada; }</pre> <p>Ini seharusnya hanya berfungsi untuk h5 dalam elemen dengan kelas "info-specs". Walau bagaimanapun, selepas diperiksa, saya mendapati bahawa elemen h5 lain juga menggunakan peraturan ini. kenapa? Berikut ialah contoh: </p> <p> <pre class="snippet-code-css lang-css prettyprint-override"><code>.info-specs h2, h3, h4, h5 { saiz fon:5em; text-transform: tiada; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code><h5>mytest </h5></code></pre> </p>
P粉795311321P粉795311321381 hari yang lalu459

membalas semua(1)saya akan balas

  • P粉308089080

    P粉3080890802023-09-05 11:21:47

    Penerjemah CSS penyemak imbas akan mencari apa sahaja dalam h3h4h5 元素,并且仅查找 h2< /code> 它将查看它是否在 .info-specs. Pemilih koma atau berkumpulan menganggap semua yang dipisahkan dengan koma sebagai pilihan berasingan.

    Penyelesaian yang mungkin untuk masalah anda ialah:

    /* These select for any h2, h3, h4 and h5 within .info-specs */
    
    .info-specs h2,
    .info-specs h3,
    .info-specs h4,
    .info-specs h5
    {
      text-decoration: underline;
    }
    
    /* These select for ant h2, h3, h4 and h5 that are direct chldren of .info-specs */
    .info-specs > h2,
    .info-specs > h3,
    .info-specs > h4,
    .info-specs > h5
    {
      color: red;
    }
    <div class="info-specs">
      <p>In this example the headings within inf-specs will all be underlined but only the headings that are direct children of info-specs will be coloured red.</p>
      <h2>Heading 2</h2>
      <h3>Heading 3</h3>
      <div>
        <h3>Heading 3 in another div</h3>
      </div>
      <h4>Heading 4</h4>
      <h5>Heading 5</h5>
    </div>

    balas
    0
  • Batalbalas