Home  >  Article  >  Web Front-end  >  What are the elements in the excluded section of css selector

What are the elements in the excluded section of css selector

下次还敢
下次还敢Original
2024-04-06 02:42:161034browse

:not() selector can be used to exclude elements under specific conditions, its syntax is :not(selector) {style rule}. Examples: :not(p) excludes all non-paragraph elements, li:not(.active) excludes inactive list items, :not(table) excludes non-table elements, div:not([data-role="primary"]) Exclude div elements with non-primary roles.

What are the elements in the excluded section of css selector

Selector to exclude some elements in CSS

:not() selector is used to exclude elements that match specific conditions element. Here's how to use the :not() selector:

<code class="css">:not(selector) {
  /* 样式规则 */
}</code>

where:

  • :not is the selector type.
  • selector is the selector of the element to exclude.

Example:

To exclude all elements that are not paragraphs, you can use the following selector:

<code class="css">:not(p) {
  color: red;
}</code>

Other examples:

  • Exclude elements with specific class names: li:not(.active)
  • Exclude elements that are not in the table: :not(table)
  • Exclude elements with specific attributes: div:not([data-role="primary"])

The above is the detailed content of What are the elements in the excluded section of css selector. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn