Backgrounds
用于控制元素背景图像位置的功能类。
| 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-(<custom-property>) | background-position: var(<custom-property>); |
bg-[<value>] | background-position: <value>; |
使用 bg-center、bg-right 和 bg-left-top 等功能类来控制元素背景图像的位置:
将鼠标悬停在这些示例上可以看到完整图像
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-(<custom-property>) syntax:
<div class="bg-(--my-bg-position) ..."> <!-- ... --></div>This is just a shorthand for bg-[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.