---
title: 条件付きスタイル
description: "Yamada UIは、条件に応じたスタイルを適用する機能を提供しています。"
---
## 概要
条件付きスタイルを使用することで、[擬似要素](https://yamada-ui.com/docs/styling/style-props.md#擬似要素)、[擬似クラス](https://yamada-ui.com/docs/styling/style-props.md#擬似クラス)、[セレクター](https://yamada-ui.com/docs/styling/style-props.md#セレクター)のスタイルを適用できます。
## 擬似要素
`::before`の擬似要素にスタイルを適用するには、`_before`を使用します。
```tsx
Box
```
:::note
利用可能な擬似要素は[こちら](https://yamada-ui.com/docs/styling/style-props.md#擬似要素)をご覧ください。
:::
## 擬似クラス
`:hover`の擬似クラスにスタイルを適用するには、`_hover`を使用します。
```tsx
Hover me
```
複数の値をまとめて適用することもできます。
```tsx
Hover me
```
複数の条件を組み合わせることもできます。
```tsx
Hover and focus me
```
:::note
利用可能な擬似クラスは[こちら](https://yamada-ui.com/docs/styling/style-props.md#擬似クラス)をご覧ください。
:::
## セレクター
`data-orientation`の属性に基づいてスタイルを適用するには、`_horizontal`もしくは`_vertical`を使用します。
```tsx
horizontal
```
:::note
利用可能なセレクターは[こちら](https://yamada-ui.com/docs/styling/style-props.md#セレクター)をご覧ください。
:::
### グループセレクター
親要素の状態または属性に基づいて要素にスタイルを適用するには、親要素にroleの`"group"`または`"data-group"`を追加して、子要素に`_group*`の条件付きスタイルを使用します。
```tsx
Hover me
```
:::note
利用可能なグループセレクターは[こちら](https://yamada-ui.com/docs/styling/style-props.md#セレクター)をご覧ください。
:::
### 兄弟セレクター
兄弟要素の状態または属性に基づいて要素にスタイルを適用するには、兄弟要素に`data-peer`を追加して、`_peer*`の条件付きスタイルを使用します。
```tsx
Focus the peer
Focus me!
```
:::note
利用可能な兄弟セレクターは[こちら](https://yamada-ui.com/docs/styling/style-props.md#セレクター)をご覧ください。
:::
### 任意のセレクター
任意のセレクターを使用する場合は、`css`を使用してスタイルを適用します。
```tsx
Closed
```