I want to add rounded corners to my table in a react component using tailwind. I have tried using rounded-lg
or any other rounded class to the component but it isn’t working. What can I do?
"use client";
import { useTimeContext } from "@/context/TimeContext";
import formatTime from "@/utils/formatTime";
import { useEffect } from "react";
export default function LapTable() {
const { stoppedTime, laps, setLaps } = useTimeContext();
useEffect(() => {
if (stoppedTime !== 0) {
setLaps((prevLaps: any) => [...prevLaps, stoppedTime]);
}
}, [stoppedTime, setLaps]);
return (
<div className="mt-5 mb-10 w-[540px]">
<table className="w-full border-collapse border-gray-400 text-center rounded-lg">
<thead>
<tr className="bg-gray-200">
<th className="border border-gray-400 px-4 py-2 w-1/2">Lap</th>
<th className="border border-gray-400 px-4 py-2 w-1/2">Time</th>
</tr>
</thead>
<tbody>
{laps.map((lapTime, index) => (
<tr key={index}>
<td className="border border-gray-400 px-4 py-2 w-1/2">{index + 1}</td>
<td className="border border-gray-400 px-4 py-2 w-1/2">{formatTime(lapTime)}</td>
</tr>
))}
</tbody>
</table>
</div>
);
}
2
Answers
You can additionally add
border outline outline-1 outline-gray-400 overflow-hidden
classes to make this workSince your table has a border, It will not give the desired effect by simply adding the
rounded-lg
to the<table>
. To clip the border to rounded corners, you will have to useoverflow-hidden
class on the container div.Then you can apply
rounded-lg
to the<table>
element for the overall shape.