Reputation: 21
I want to convert my css to tailwind but when I find many sources, there is no solution. Here is My css
.selector {
background-size: contain, cover;
}
and If anyone have clue or solution for another property please feel free to comment the solution 🙏🏻
Upvotes: 0
Views: 1289
Reputation: 3885
from the docs https://tailwindcss.com/docs/background-size
you can use multiple using bg-[]
syntax
like this
<div class="bg-[length:contain,cover]"></div>
also, make sure you are in the NPM package tailwind.
and there isn't any space between the brackets.
length:
is important for making the tailwind you are referring tosize
, because bg can be color, image, or any other thing.
Upvotes: 2
Reputation: 14313
You need to extend default background-sizes with your own. First argument is class name and second one is desired CSS property
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
backgroundSize: {
'contain-cover': 'contain, cover', // here
}
},
},
plugins: [],
}
and use it like bg-contain-cover
(you may name it as you wish and use like bg-your-custom-bg-size-name
)
Upvotes: 1
Reputation: 2676
You cannot use contain
and cover
at the same time in CSS that is why it is also not possible in tailwind. Choose one, either bg-contain
or bg-cover
. Here are examples of what it does: https://tailwindcss.com/docs/background-size
Upvotes: 1