css селектор для элементов без класса - PullRequest
0 голосов
/ 28 февраля 2020
<th style="position: relative; top: 0px;">
    <div style="width: 48.003906px;" data-lngst="nullpx" data-ndx="2">123</div></th>
<th id="" class="abc_naem" nowrap="" style="position: relative; top: 0px;">
    <div style="width: 44.003906px;" data-lngst="nullpx" data-ndx="4">...</div>
<th style="position: relative; top: 0px;">
    <div style="width: 48.003906px;" data-lngst="nullpx" data-ndx="5">123</div></th>
<th id="" class="abc_phase" nowrap="" style="position: relative; top: 0px;">
    <div style="width: 44.003906px;" data-lngst="nullpx" data-ndx="3">...</div>

как выбрать все элементы 'th', используя css селекторы, которые не имеют имени класса? Все элементы th имеют одинаковые атрибуты, кроме имени класса, и мне нужны атрибуты без него. Я попытался th[classname=''], и это не сработало. Я перепробовал все варианты выбора css, такие как 'no-child' и c, но он всегда возвращает все th элементы

1 Ответ

1 голос
/ 28 февраля 2020

Если ваш HTML сформирован правильно, вы можете использовать :not() с селектором атрибута []. Пример th:not([class])

Пример:

th:not([class]) {
  color: red;
}
<table>
  <tr>
    <th style="position: relative; top: 0px;">
      <div style="width: 48.003906px;" data-lngst="nullpx" data-ndx="2">123</div>
    </th>
    <th id="" class="abc_naem" nowrap="" style="position: relative; top: 0px;">
      <div style="width: 44.003906px;" data-lngst="nullpx" data-ndx="4">123</div>
      <th style="position: relative; top: 0px;">
        <div style="width: 48.003906px;" data-lngst="nullpx" data-ndx="5">123</div>
      </th>
      <th id="" class="abc_phase" nowrap="" style="position: relative; top: 0px;">
        <div style="width: 44.003906px;" data-lngst="nullpx" data-ndx="3">123</div>
      </th>
  </tr>
</table>
...