For situations like this, I've found it beneficial to develop a custom plugin.
Modify the Tailwind configuration by adding a plugin and default values.
const plugin = require('tailwindcss/plugin')
// define default values
const screenKeys = Array.from({length: 20}, (_, i) => i*5)
const screenSizes = screenKeys.reduce((v, key) => Object.assign(v, {[key]: key}), {});
module.exports = {
// ...
plugins: [
plugin(function ({matchUtilities, theme}) {
matchUtilities(
{
'w-screen': width => ({
width: `${width}vw`
})
},
{ values: Object.assign(screenSizes, theme('screenSize', {})) }
),
matchUtilities(
{
'h-screen': height => ({
height: `${height}vh`
})
},
{ values: Object.assign(screenSizes, theme('screenSize', {})) }
)
})
],
}
This setup enables you to utilize the w-screen
or h-screen
utility with vw
or vh
values ranging from 0 to 95 in increments of 5 (0,5,10...95). Using w-screen
without specifying values will default to 100vw
(as currently implemented).
<div class="w-screen h-screen-35">
The default width screen behavior remains unchanged
</div>
<div class="w-screen-50 h-screen-[15]">
50vw width, 15vh from Just-In-Time compilation
No need to specify h-screen-[15vh], as the units are already known to be in vh
</div>
In your scenario, it would be w-screen-90 h-screen-90
You can enhance the configuration for reusable classes using the screenSize
key
module.exports = {
theme: {
extend: {
screenSize: {
33: 33 // just an example
}
},
},
}
Usage
<div class="w-screen-[22] h-screen-33">
33vh from user configuration, 22vw from Just-In-Time compilation
</div>
DEMO