1. 背景
  2. background-position

背景

background-position

要素の背景画像の位置を制御するためのユーティリティ。

クラススタイル
bg-top-left
background-position: top left;
bg-top
background-position: top;
bg-top-right
background-position: top right;
bg-left
background-position: left;
bg-center
background-position: center;
bg-right
background-position: right;
bg-bottom-left
background-position: bottom left;
bg-bottom
background-position: bottom;
bg-bottom-right
background-position: bottom right;
bg-position-(<custom-property>)
background-position: var(<custom-property>);
bg-position-[<value>]
background-position: <value>;

基本的な例

要素の背景画像の位置を制御するには、bg-centerbg-rightbg-top-left などのユーティリティを使用します。

これらの例にホバーして、画像の全体像を確認してください。

bg-top-left

bg-top

bg-top-right

bg-left

bg-center

bg-right

bg-bottom-left

bg-bottom

bg-bottom-right

<div class="bg-[url(/img/mountains.jpg)] bg-top-left"></div>
<div class="bg-[url(/img/mountains.jpg)] bg-top"></div>
<div class="bg-[url(/img/mountains.jpg)] bg-top-right"></div>
<div class="bg-[url(/img/mountains.jpg)] bg-left"></div>
<div class="bg-[url(/img/mountains.jpg)] bg-center"></div>
<div class="bg-[url(/img/mountains.jpg)] bg-right"></div>
<div class="bg-[url(/img/mountains.jpg)] bg-bottom-left"></div>
<div class="bg-[url(/img/mountains.jpg)] bg-bottom"></div>
<div class="bg-[url(/img/mountains.jpg)] bg-bottom-right"></div>

カスタム値の使用

以下を使用してください bg-position-[<value>] 構文 を設定するには背景位置完全にカスタムな値に基づいて

<div class="bg-position-[center_top_1rem] ...">
<!-- ... -->
</div>

CSS 変数の場合は、以下も使用できます。 bg-position-(<custom-property>) 構文

<div class="bg-position-(--my-bg-position) ...">
<!-- ... -->
</div>

これは単なる省略形です bg-position-[var(<custom-property>)] これは var() 関数を自動的に追加します。

レスポンシブデザイン

プレフィックスa background-position ユーティリティ ユーティリティを適用するmd:のようなブレークポイントバリアントでmedium 画面サイズ以上

<div class="bg-center md:bg-top ...">
<!-- ... -->
</div>

バリアントの使用方法の詳細については、バリアントのドキュメントをご覧ください。

Copyright © 2025 Tailwind Labs Inc.·商標ポリシー