首页 > 解决方案 > 如何使用 :not() 选择器选择表?

问题描述

我有一个div有一个段落和一个表格的。

我想font-size使用选择器更改段落的:not()

我尝试了以下操作,但无法使用此选择器选择表格元素。

div :not(table){font-size:5px;}/*not working*/

<div><p>....</p><table>....</table></div>

https://codepen.io/nur49/pen/eYBvOZG

标签: htmlcss

解决方案


您要选择不是表格的 div 的子项,因此您可以在 div 上使用 > 选择器

div > :not(table)

这是片段:

body{
      width: 100%;
      background-color: #7df3e0;
      font-size: 24pt;
    }

div > :not(table){
      font-size: 5px;
      
}
<div>
      <p>paragraph</p>
      <table border="1">
        <thead>
          <tr class="trr">
          <th>Roll</th>
          <th>Name</th>
          <th>GPA</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th>01</th>
            <th>Nur</th>
            <th>5.0</th>
          </tr>
          <tr>
            <th>02</th>
            <th><a href="https://www.prothomalo.com">prothomalo</a></th>
            <th>5.0</th>
          </tr>
          <tr>
            <th>03</th>
            <th>Nur</th>
            <th>5.0</th>
          </tr>
          <tr>
            <th>04</th>
            <th>Nur</th>
            <th>5.0</th>
          </tr>
        </tbody>
      </table>
   </div>


推荐阅读