Skip to content

Commit 78d1c50

Browse files
authored
Reset borders, padding, and margin universally (#13189)
* Reset borders, padding, and margin universally Noticed iframes have a default border we weren't resetting, feels safest to just remove borders across the board and reintroduce them for form controls. We were also resetting padding on an element by element basis but I can't think of any elements we are actually trying to avoid resetting padding on, so just reset it everywhere. This also removes the left margin on file buttons that separates the button from the meta data about the currently selected file but I think this is fine, let the user decide how much space to put there intentionally like we do with other things. * Include ::first-letter Supports margin/padding/border (but not box-sizing) so should be in reset list. * Update changelog --------- Co-authored-by: Adam Wathan <[email protected]>
1 parent d863de7 commit 78d1c50

File tree

3 files changed

+32
-67
lines changed

3 files changed

+32
-67
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Ensure `scale-*` utilities support percentage values ([#13182](https://github.com/tailwindlabs/tailwindcss/pull/13182))
1313
- Prevent `content-none` from being overridden when conditionally styling `::before`/`::after` ([#13187](https://github.com/tailwindlabs/tailwindcss/pull/13187))
14+
- Remove default borders from `iframe` elements ([#13189](https://github.com/tailwindlabs/tailwindcss/pull/13189))
1415

1516
### Changed
1617

packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -402,16 +402,18 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
402402
}
403403
404404
@layer base {
405-
*, :after, :before, ::backdrop {
405+
*, :after, :before, ::backdrop, :first-letter {
406406
box-sizing: border-box;
407+
border: 0 solid;
408+
margin: 0;
409+
padding: 0;
407410
}
408411
409412
::file-selector-button {
410413
box-sizing: border-box;
411-
}
412-
413-
* {
414+
border: 0 solid;
414415
margin: 0;
416+
padding: 0;
415417
}
416418
417419
html, :host {
@@ -430,7 +432,6 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
430432
431433
hr {
432434
color: inherit;
433-
border: 0 solid;
434435
border-top-width: 1px;
435436
height: 0;
436437
}
@@ -494,8 +495,6 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
494495
font-variation-settings: inherit;
495496
color: inherit;
496497
background: none;
497-
border: 1px solid;
498-
padding: 0;
499498
}
500499
501500
::file-selector-button {
@@ -504,18 +503,18 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
504503
font-variation-settings: inherit;
505504
color: inherit;
506505
background: none;
506+
}
507+
508+
input:where(:not([type="button"], [type="reset"], [type="submit"])), select, textarea {
507509
border: 1px solid;
508-
padding: 0;
509510
}
510511
511512
button, input:where([type="button"], [type="reset"], [type="submit"]) {
512513
appearance: button;
513-
border: 0;
514514
}
515515
516516
::file-selector-button {
517517
appearance: button;
518-
border: 0;
519518
}
520519
521520
:-moz-focusring {
@@ -546,24 +545,10 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
546545
display: list-item;
547546
}
548547
549-
fieldset {
550-
border: 0;
551-
padding: 0;
552-
}
553-
554-
legend {
555-
padding: 0;
556-
}
557-
558548
ol, ul, menu {
559-
padding: 0;
560549
list-style: none;
561550
}
562551
563-
dialog {
564-
padding: 0;
565-
}
566-
567552
textarea {
568553
resize: vertical;
569554
}

packages/tailwindcss/preflight.css

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
/*
2-
Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
2+
1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
3+
2. Remove default margins and padding
4+
3. Reset all borders.
35
*/
46

57
*,
68
::after,
79
::before,
810
::backdrop,
11+
::first-letter,
912
::file-selector-button {
10-
box-sizing: border-box;
11-
}
12-
13-
/*
14-
Remove any default margins.
15-
*/
16-
17-
* {
18-
margin: 0;
13+
box-sizing: border-box; /* 1 */
14+
margin: 0; /* 2 */
15+
padding: 0; /* 2 */
16+
border: 0 solid; /* 3 */
1917
}
2018

2119
/*
@@ -65,7 +63,6 @@ body {
6563
hr {
6664
height: 0; /* 1 */
6765
color: inherit; /* 2 */
68-
border: 0 solid; /* 3 */
6966
border-top-width: 1px; /* 3 */
7067
}
7168

@@ -180,9 +177,7 @@ table {
180177

181178
/*
182179
1. Inherit the font styles in all browsers.
183-
2. Reset the default inset border style to solid.
184-
3. Remove the default background color.
185-
4. Remove default padding.
180+
2. Remove the default background color.
186181
*/
187182

188183
button,
@@ -195,20 +190,26 @@ textarea,
195190
font-feature-settings: inherit; /* 1 */
196191
font-variation-settings: inherit; /* 1 */
197192
color: inherit; /* 1 */
198-
border: 1px solid; /* 2 */
199-
background: transparent; /* 3 */
200-
padding: 0; /* 4 */
193+
background: transparent; /* 2 */
194+
}
195+
196+
/*
197+
Reset the default inset border style for form controls to solid.
198+
*/
199+
200+
input:where(:not([type='button'], [type='reset'], [type='submit'])),
201+
select,
202+
textarea {
203+
border: 1px solid;
201204
}
202205

203206
/*
204-
1. Correct the inability to style the border radius in iOS Safari.
205-
2. Make borders opt-in.
207+
Correct the inability to style the border radius in iOS Safari.
206208
*/
207209
button,
208210
input:where([type='button'], [type='reset'], [type='submit']),
209211
::file-selector-button {
210-
appearance: button; /* 1 */
211-
border: 0; /* 2 */
212+
appearance: button;
212213
}
213214

214215
/*
@@ -260,19 +261,6 @@ summary {
260261
display: list-item;
261262
}
262263

263-
/*
264-
Remove the default border and spacing for fieldset and legend elements.
265-
*/
266-
267-
fieldset {
268-
border: 0;
269-
padding: 0;
270-
}
271-
272-
legend {
273-
padding: 0;
274-
}
275-
276264
/*
277265
Make lists unstyled by default.
278266
*/
@@ -281,15 +269,6 @@ ol,
281269
ul,
282270
menu {
283271
list-style: none;
284-
padding: 0;
285-
}
286-
287-
/*
288-
Remove the default padding from dialog elements.
289-
*/
290-
291-
dialog {
292-
padding: 0;
293272
}
294273

295274
/*

0 commit comments

Comments
 (0)