> For the complete documentation index, see [llms.txt](https://favelaware.gitbook.io/favelaware/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://favelaware.gitbook.io/favelaware/5-css/5.5.1-pseudo-classes-em-css.md).

# 5.5.1 Pseudo-classes em CSS

As pseudo-classes são palavras-chave adicionadas aos seletores para aplicar estilos a estados específicos de um elemento, como quando o usuário passa o mouse, um link é visitado,

#### 🔹 **1. Interação do Usuário**

Afetam os estilos de elementos com base na **interação do usuário**, como mouse ou clique.

| Pseudo-classe | Descrição                                   | Exemplo         |
| ------------- | ------------------------------------------- | --------------- |
| `:hover`      | Quando o mouse está sobre o elemento        | `a:hover`       |
| `:active`     | Quando o elemento está sendo clicado        | `button:active` |
| `:focus`      | Quando o elemento está em foco (input, etc) | `input:focus`   |

```css
cssCopiarEditarbutton:hover {
  background-color: #0055ff;
  color: white;
}
```

***

#### 🔹 **2. Posição em Listas**

Permitem estilizar elementos com base na **posição em uma lista ou grupo**.

| Pseudo-classe     | Descrição                                     | Exemplo            |
| ----------------- | --------------------------------------------- | ------------------ |
| `:first-child`    | Primeiro filho dentro do elemento pai         | `li:first-child`   |
| `:last-child`     | Último filho dentro do elemento pai           | `li:last-child`    |
| `:nth-child(n)`   | Seleciona o filho na posição **n**            | `li:nth-child(2)`  |
| `:nth-of-type(n)` | Seleciona o elemento do tipo na posição **n** | `p:nth-of-type(3)` |
| `:only-child`     | Quando é o **único filho**                    | `div:only-child`   |

```css
cssCopiarEditarul li:first-child {
  font-weight: bold;
}
```

***

#### 🔹 **3. Estados de Formulários**

Estilizam elementos com base em seu **estado funcional**.

| Pseudo-classe        | Descrição                         | Exemplo                   |
| -------------------- | --------------------------------- | ------------------------- |
| `:checked`           | Elemento marcado (checkbox/radio) | `input:checked`           |
| `:disabled`          | Elemento desativado               | `button:disabled`         |
| `:enabled`           | Elemento habilitado               | `input:enabled`           |
| `:required`          | Campo obrigatório                 | `input:required`          |
| `:optional`          | Campo não obrigatório             | `input:optional`          |
| `:valid`             | Campo com valor válido            | `input:valid`             |
| `:invalid`           | Campo com valor inválido          | `input:invalid`           |
| `:placeholder-shown` | Quando o placeholder está visível | `input:placeholder-shown` |

```css
cssCopiarEditarinput:focus {
  border: 2px solid blue;
}
```

***

#### 🔹 **4. Pseudo-classes Avançadas**

Permitem uma **seleção mais precisa e contextual**.

| Pseudo-classe    | Descrição                                        | Exemplo                    |
| ---------------- | ------------------------------------------------ | -------------------------- |
| `:not(selector)` | Exclui elementos que correspondem ao seletor     | `p:not(.destaque)`         |
| `:empty`         | Seleciona elementos sem filhos ou texto          | `div:empty`                |
| `:root`          | Seleciona o elemento raiz (`<html>`)             | `:root`                    |
| `:is()`          | Agrupa múltiplos seletores para otimização       | `:is(h1, h2, h3)`          |
| `:where()`       | Igual ao `:is`, mas com **zero especificidade**  | `:where(section, article)` |
| `:has()`         | (Novo) Seleciona elementos que **contêm outros** | `div:has(img)`             |

```css
cssCopiarEditarp:not(.importante) {
  color: gray;
}
```

> ⚠️ `:has()` ainda tem suporte limitado em alguns navegadores. Teste antes de usar em produção.

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://favelaware.gitbook.io/favelaware/5-css/5.5.1-pseudo-classes-em-css.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
