Backgrounds
Utilities for controlling the position of an element's background image.
Class | Styles |
---|---|
bg-bottom | background-position: bottom; |
bg-center | background-position: center; |
bg-left | background-position: left; |
bg-left-bottom | background-position: left bottom; |
bg-left-top | background-position: left top; |
bg-right | background-position: right; |
bg-right-bottom | background-position: right bottom; |
bg-right-top | background-position: right top; |
bg-top | background-position: top; |
bg-(position:<custom-property>) | background-position: var(<custom-property>); |
bg-[<value>] | background-position: <value>; |
Use utilities like bg-center
, bg-right
, and bg-left-top
to control the position of an element's background image:
Hover over these examples to see the full image
bg-left-top
bg-top
bg-right-top
bg-left
bg-center
bg-right
bg-left-bottom
bg-bottom
bg-right-bottom
<div class="bg-[url(/img/mountains.jpg)] bg-left-top"></div><div class="bg-[url(/img/mountains.jpg)] bg-top"></div><div class="bg-[url(/img/mountains.jpg)] bg-right-top"></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-left-bottom"></div><div class="bg-[url(/img/mountains.jpg)] bg-bottom"></div><div class="bg-[url(/img/mountains.jpg)] bg-right-bottom"></div>
Use the bg-[<value>]
syntax to set the background position based on a completely custom value:
<div class="bg-[center_top_1rem] ..."> <!-- ... --></div>
For CSS variables, you can also use the bg-(position:<custom-property>)
syntax:
<div class="bg-(position:--my-bg-position) ..."> <!-- ... --></div>
This is just a shorthand for bg-[position:var(<custom-property>)]
that adds the var()
function for you automatically.
Prefix a background-position
utility with a breakpoint variant like md:
to only apply the utility at medium screen sizes and above:
<div class="bg-center md:bg-top ..."> <!-- ... --></div>
Learn more about using variants in the variants documentation.
Tailwind CSS 中文网(本网站)的目标是为中文开发者提供准确、及时的 Tailwind CSS 中文文档
Tailwind CSS 中文文档由本网站维护人员共同翻译,采用 MIT 开源协议发布
本网站与 tailwindcss.com 及 Tailwind Labs Inc. 并无从属关系
Tailwind 商标由 Tailwind Labs Inc. 所有
京ICP备15031610号-8