|
| 1 | +<p align="center"> |
| 2 | + <a href="https://tailwindcss.com/" target="_blank"><img width="200" src="https://tailwindcss.com/img/tailwind.svg"></a><br> |
| 3 | + A utility-first CSS framework for rapidly building custom user interfaces. |
| 4 | +</p> |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +<br> |
| 9 | + |
| 10 | +# Tailwind CSS `box-sizing` utilities |
| 11 | + |
| 12 | +This is a Tailwind CSS plugin that adds utilities to modifiy the [CSS Box Model](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model) property: `box-sizing`. It's useful to override defaults coming from [Preflight](https://tailwindcss.com/docs/preflight/) or [normalize.css](https://github.com/necolas/normalize.css/) or any other [CSS reset](https://meyerweb.com/eric/tools/css/reset/). |
| 13 | + |
| 14 | +Maintained by: [Joan Piedra](https://joanpiedra.com) → [@neojp](https://twitter.com/neojp) |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +Install as a node module with either `npm` or `yarn` on your command line |
| 19 | + |
| 20 | +```bash |
| 21 | +# Install via npm |
| 22 | +npm install --save-dev @neojp/tailwindcss-box-sizing-utilities |
| 23 | + |
| 24 | +# Install via yarn |
| 25 | +yarn add --dev @neojp/tailwindcss-box-sizing-utilities |
| 26 | +``` |
| 27 | + |
| 28 | +Add this module as a plugin on your [Tailwind configuration file](https://tailwindcss.com/docs/configuration#plugins) (`tailwind.config.js`). |
| 29 | + |
| 30 | +```js |
| 31 | +module.exports = { |
| 32 | + plugins: [ |
| 33 | + require('@neojp/tailwindcss-box-sizing-utilities') |
| 34 | + ] |
| 35 | +}; |
| 36 | +``` |
| 37 | + |
| 38 | +### Variants |
| 39 | + |
| 40 | +Note that this plugin allows the usage of variants through the key `boxSizing` and will default to your global variant setting. |
| 41 | + |
| 42 | +```js |
| 43 | +module.exports = { |
| 44 | + variants: { |
| 45 | + boxSizing: ['responsive'] |
| 46 | + } |
| 47 | +}; |
| 48 | +``` |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +Use the Tailwind utility classes provided by this plugin. |
| 53 | + |
| 54 | +```html |
| 55 | +<div class="border-box"></div> |
| 56 | +<div class="content-box"></div> |
| 57 | +``` |
| 58 | + |
| 59 | +## About overriding browsers' default `box-sizing` |
| 60 | + |
| 61 | +There is a debate about whether `border-box` is better than `content-box`, and how it should be used by default across projects and browsers. Hence it's been included in several popular CSS libraries as a hard-set default. **Preflight** is one of them. |
| 62 | + |
| 63 | +The browsers' default `box-sizing` value is `content-box`. |
| 64 | + |
| 65 | +Overriding the default to `border-box` with **Preflight** or any other CSS reset can do wonders for your project's code, but it can and probably will wreak havoc to third-party code, plugins, and widgets that expect it to be `content-box`. |
| 66 | + |
| 67 | +This utility should help remediate this scenario: |
| 68 | + |
| 69 | +```html |
| 70 | +<div class="content-box"> |
| 71 | + <!-- insert third-party code here --> |
| 72 | +</div> |
| 73 | +``` |
| 74 | + |
| 75 | +My personal preference is to avoid **Preflight**, and just use the `.border-box` utility classes as needed. |
| 76 | + |
| 77 | +## Output |
| 78 | + |
| 79 | +Tailwind will be outputed as follows. |
| 80 | + |
| 81 | +```css |
| 82 | +.border-box { box-sizing: border-box; } |
| 83 | +.content-box { box-sizing: content-box; } |
| 84 | +``` |
| 85 | + |
| 86 | +## Contributing |
| 87 | + |
| 88 | +Feel free to [submit an issue](https://github.com/neojp/tailwindcss-box-sizing-utilities/issues) or a [pull request](https://github.com/neojp/tailwindcss-box-sizing-utilities/pulls), and send me a message on Twitter ([@neojp](https://twitter.com/neojp)) about it. |
| 89 | + |
| 90 | +## License |
| 91 | +This project has been licensed under [the Hippocratic License](https://firstdonoharm.dev/). |
0 commit comments