Skip to content

Commit 507ac9d

Browse files
thecrypticaceRobinMalfait
authored andcommitted
Add bg-{top,bottom}-{left,right} utilities (#17378)
We’re using this naming for `mask-*` and `mask-radial-at-*` position utilities and we want to be consistent. The old ones for `background-position` will stay but are deprecated --------- Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
1 parent bb6a923 commit 507ac9d

File tree

5 files changed

+56
-15
lines changed

5 files changed

+56
-15
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- _Experimental_: Add `wrap-anywhere`, `wrap-break-word`, and `wrap-normal` utilities ([#12128](https://github.com/tailwindlabs/tailwindcss/pull/12128))
2121
- _Experimental_: Add `@source inline(…)` ([#17147](https://github.com/tailwindlabs/tailwindcss/pull/17147))
2222
- _Experimental_: Add `@source not` ([#17255](https://github.com/tailwindlabs/tailwindcss/pull/17255))
23+
- Added new `bg-{top,bottom}-{left,right}` utilities ([#17378](https://github.com/tailwindlabs/tailwindcss/pull/17378))
2324

2425
### Fixed
2526

2627
- Fix symlink issues when resolving `@source` directives ([#17391](https://github.com/tailwindlabs/tailwindcss/pull/17391))
2728

29+
### Changed
30+
31+
- Deprecated `bg-{left,right}-{top,bottom}` utilities ([#17378](https://github.com/tailwindlabs/tailwindcss/pull/17378))
32+
2833
## [4.0.17] - 2025-03-26
2934

3035
### Fixed

packages/tailwindcss/src/__snapshots__/intellisense.test.ts.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,8 @@ exports[`getClassList 1`] = `
21562156
"bg-blend-screen",
21572157
"bg-blend-soft-light",
21582158
"bg-bottom",
2159+
"bg-bottom-left",
2160+
"bg-bottom-right",
21592161
"bg-center",
21602162
"bg-clip-border",
21612163
"bg-clip-content",
@@ -2326,8 +2328,6 @@ exports[`getClassList 1`] = `
23262328
"bg-inherit/95",
23272329
"bg-inherit/100",
23282330
"bg-left",
2329-
"bg-left-bottom",
2330-
"bg-left-top",
23312331
"bg-linear-0",
23322332
"bg-linear-0/oklab",
23332333
"bg-linear-0/oklch",
@@ -2529,10 +2529,10 @@ exports[`getClassList 1`] = `
25292529
"bg-repeat-x",
25302530
"bg-repeat-y",
25312531
"bg-right",
2532-
"bg-right-bottom",
2533-
"bg-right-top",
25342532
"bg-scroll",
25352533
"bg-top",
2534+
"bg-top-left",
2535+
"bg-top-right",
25362536
"bg-transparent",
25372537
"bg-transparent/0",
25382538
"bg-transparent/5",

packages/tailwindcss/src/compat/legacy-utilities.ts

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ export function registerLegacyUtilities(designSystem: DesignSystem) {
1919
])
2020
}
2121

22+
// Legacy `background-position` utilities for compatibility with v4.0 and earlier
23+
designSystem.utilities.static('bg-left-top', () => [decl('background-position', 'left top')])
24+
designSystem.utilities.static('bg-right-top', () => [decl('background-position', 'right top')])
25+
designSystem.utilities.static('bg-left-bottom', () => [
26+
decl('background-position', 'left bottom'),
27+
])
28+
designSystem.utilities.static('bg-right-bottom', () => [
29+
decl('background-position', 'right bottom'),
30+
])
31+
2232
designSystem.utilities.functional('max-w-screen', (candidate) => {
2333
if (!candidate.value) return
2434
if (candidate.value.kind === 'arbitrary') return

packages/tailwindcss/src/utilities.test.ts

+31-5
Original file line numberDiff line numberDiff line change
@@ -10208,20 +10208,26 @@ test('bg', async () => {
1020810208
'bg-scroll',
1020910209

1021010210
// background-position
10211-
'bg-center',
1021210211
'bg-top',
10213-
'bg-right-top',
10214-
'bg-right-bottom',
10212+
'bg-top-left',
10213+
'bg-top-right',
1021510214
'bg-bottom',
10216-
'bg-left-bottom',
10215+
'bg-bottom-left',
10216+
'bg-bottom-right',
1021710217
'bg-left',
10218-
'bg-left-top',
10218+
'bg-right',
10219+
'bg-center',
1021910220
'bg-[50%]',
1022010221
'bg-[120px]',
1022110222
'bg-[120px_120px]',
1022210223
'bg-[length:120px_120px]',
1022310224
'bg-[position:120px_120px]',
1022410225
'bg-[size:120px_120px]',
10226+
// Legacy versions in v4.0 and earlier
10227+
'bg-right-top',
10228+
'bg-right-bottom',
10229+
'bg-left-bottom',
10230+
'bg-left-top',
1022510231

1022610232
// background-repeat
1022710233
'bg-repeat',
@@ -10634,6 +10640,14 @@ test('bg', async () => {
1063410640
background-position: bottom;
1063510641
}
1063610642
10643+
.bg-bottom-left {
10644+
background-position: 0 100%;
10645+
}
10646+
10647+
.bg-bottom-right {
10648+
background-position: 100% 100%;
10649+
}
10650+
1063710651
.bg-center {
1063810652
background-position: center;
1063910653
}
@@ -10650,6 +10664,10 @@ test('bg', async () => {
1065010664
background-position: 0 0;
1065110665
}
1065210666
10667+
.bg-right {
10668+
background-position: 100%;
10669+
}
10670+
1065310671
.bg-right-bottom {
1065410672
background-position: 100% 100%;
1065510673
}
@@ -10662,6 +10680,14 @@ test('bg', async () => {
1066210680
background-position: top;
1066310681
}
1066410682
10683+
.bg-top-left {
10684+
background-position: 0 0;
10685+
}
10686+
10687+
.bg-top-right {
10688+
background-position: 100% 0;
10689+
}
10690+
1066510691
.bg-no-repeat {
1066610692
background-repeat: no-repeat;
1066710693
}

packages/tailwindcss/src/utilities.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2391,15 +2391,15 @@ export function createUtilities(theme: Theme) {
23912391
staticUtility('bg-local', [['background-attachment', 'local']])
23922392
staticUtility('bg-scroll', [['background-attachment', 'scroll']])
23932393

2394-
staticUtility('bg-center', [['background-position', 'center']])
23952394
staticUtility('bg-top', [['background-position', 'top']])
2396-
staticUtility('bg-right-top', [['background-position', 'right top']])
2397-
staticUtility('bg-right', [['background-position', 'right']])
2398-
staticUtility('bg-right-bottom', [['background-position', 'right bottom']])
2395+
staticUtility('bg-top-left', [['background-position', 'left top']])
2396+
staticUtility('bg-top-right', [['background-position', 'right top']])
23992397
staticUtility('bg-bottom', [['background-position', 'bottom']])
2400-
staticUtility('bg-left-bottom', [['background-position', 'left bottom']])
2398+
staticUtility('bg-bottom-left', [['background-position', 'left bottom']])
2399+
staticUtility('bg-bottom-right', [['background-position', 'right bottom']])
24012400
staticUtility('bg-left', [['background-position', 'left']])
2402-
staticUtility('bg-left-top', [['background-position', 'left top']])
2401+
staticUtility('bg-right', [['background-position', 'right']])
2402+
staticUtility('bg-center', [['background-position', 'center']])
24032403

24042404
staticUtility('bg-repeat', [['background-repeat', 'repeat']])
24052405
staticUtility('bg-no-repeat', [['background-repeat', 'no-repeat']])

0 commit comments

Comments
 (0)