
Adding Custom Styles in TailwindCSS
If you're using Tailwind CSS, you can apply custom styles using utility classes directly in your HTML output. Here's how to add Tailwind classes in PHP:
? Example with Tailwind Classes in PHP
$nameRow = '<a ' . $hrefAttr . ' class="text-blue-600 font-semibold hover:underline">' . htmlspecialchars($aRow['name']) . '</a>';
? Breakdown of Tailwind Classes Used:
text-blue-600
: Blue text colorfont-semibold
: Semi-bold fonthover:underline
: Underline on hover
? Conditional Tailwind Classes in PHP
$extraClass = $isActive ? 'bg-green-100' : 'bg-gray-100';$nameRow = '<a ' . $hrefAttr . ' class="p-2 rounded ' . $extraClass . '">' . htmlspecialchars($aRow['name']) . '</a>';
? Tip:
You don't use inline style="..."
with Tailwind. Just compose utility classes for layout, spacing, colors, fonts, etc.
Let me know if you're rendering inside a Blade view or want to reuse classes!