Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dan3460's avatar

Table formatting with Tailwind

Here is a problem that makes me crazy, and i know is probably because i have not studied css in detail. I'm creating a table, i made the background of the header row blue. Now i want to change the background of the row on the body section. The browser seems to ignore my class.

<table class="table w-full bg-white border-collapse">
        <thead>
            <tr class="bg-blue-400 border text-center px-8 py-4">
                <th>Route</th>
                <th>Departure</th>
                <th>Driver</th>
                <th>Truck</th>
                <th>Stops</th>
                <th>Cases</th>
                <th>Shorts</th>
                <th colspan="2">Built</th>
                <th colspan="2">Picked</th>
                <th colspan="2">Invoiced</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($routes as $route)
            <tr class="bg-blue-500 border text-center h-9 ">
                <td> {{$route->key}}</td>
                <td>
                    {{$route->planned_departure->toTimeString()}}
                </td>
                <td>N/A</td>
                <td>N/A</td>
                <td>{{$route->total_stops}}</td>
                <td>{{$route->planned_size1}}</td>
                <td>10</td>
                <td>
                    {{$route->planned_departure->addMinutes(-$builtTime)->toTimeString()}}
                </td>
                @if ($route->built)
                <td style="color: green">
                    <i class="fas fa-solid fa-check"></i>
                </td>
                @else
                <td style="color: red">
                    <i class="fa-solid fa-circle-xmark"></i>
                </td>
                @endif
                <td>
                    {{$route->planned_departure->addMinutes(-$pickedTime)->toTimeString()}}
                </td>
                @if ($route->picked)
                <td style="color: green">
                    <i class="fas fa-solid fa-check"></i>
                </td>
                @else
                <td style="color: red">
                    <i class="fa-solid fa-circle-xmark"></i>
                </td>
                @endif
                <td>
                    {{$route->planned_departure->addMinutes(-$invoicedTime)->toTimeString()}}
                </td>
                @if ($route->invoiced)
                <td style="color: green">
                    <i class="fas fa-solid fa-check"></i>
                </td>
                @else
                <td style="color: red">
                    <i class="fa-solid fa-circle-xmark"></i>
                </td>
                @endif
            </tr>
            @endforeach
        </tbody>
    </table>

in the Chrome developer tools i see that bg-blue-400 was applied to to the thead.tr:

.text-center {
    text-align: center;
}
.px-8 {
    padding-left: 2rem;
    padding-right: 2rem;
}
.py-4 {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.bg-blue-400 {
    --tw-bg-opacity: 1;
    background-color: rgb(96 165 250 / var(--tw-bg-opacity));
}
.border {
    border-width: 1px;
}

but not to the tbody.tr:


element.style {
}
.text-center {
    text-align: center;
}

.border {
    border-width: 1px;
}
.h-9 {
    height: 2.25rem;
}
0 likes
4 replies
Nakov's avatar
Nakov
Best Answer
Level 73

Are you using Tailwind v3.0 ? If so, then JIT is used, and if you never used bg-blue-500 before, you'll need to run npm run dev to re-compile the assets. Try adding the bg-blue-400 to your tr and see if that will work?

dan3460's avatar

@nakov you are correct. I should have red tailwind docs.

npm run dev solved it.

dan3460's avatar

Is there a way to pre-compile certain classes? I'm sending some of the classes from the controller, so Tailwind doesn't see them when i run npm.

Please or to participate in this conversation.