Just add the class. Not by width or height, but by number of characters.
As close as possible to normal markup
Skeleton display is performed only when there are no children.
Just add the class of ss-text-[n]
.
{/* Skeleton displayed only if empty */}
<p className="text-base text-gray-600 ss-text-[71]">{text}</p>
<!-- ❌ -->
<div class="h-4 w-full bg-gray-200"></div>
<-- 😍 -->
<p class="ss-text-[24]"></p>
<!-- ❌ -->
<div class="h-4 max-w-[360px] bg-gray-200 mb-2.5"></div>
<div class="h-4 max-w-[360px] bg-gray-200 mb-2.5"></div>
<div class="h-4 max-w-[360px] bg-gray-200 mb-2.5"></div>
<div class="h-4 max-w-[80px] bg-gray-200"></div>
<-- 😍 -->
<p class="text-base text-gray-600 ss-text-[71]"></p>
Install the plugin from npm:
npm install -D tailwindcss-skeleton-screen
Then add the plugin to your tailwind.config.js file:
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
skeletonScreen: {
color: '#d0d0d0', // optional
borderRadius: "4px" // optional
}
}
},
plugins: [
require('tailwindcss-skeleton-screen')
]
};
class | |
---|---|
ss-object | Display skeleton with background-color |
ss-text-[n] | Display skeleton for n characters |
ss-text-[n/n/n] | The number of characters per line can be specified by separating each line with a "slash (/)". |