I have a table of 3 by 3. I need a way to add a border for the bottom of every row tr
and give it a specific color.
First I tried the direct way, i.e.:
<tr style="border-bottom:1pt solid black;">
But that didn't work. So I added CSS like this:
tr {
border-bottom: 1pt solid black;
}
That still didn't work.
I would prefer to use CSS because then I don't need to add a style
attribute to every row.
I haven't added a border
attribute to the <table>
. I hope that that is not affecting my CSS.
There are lot of incomplete answers here. Since you cannot apply a border to
tr
tag, you need to apply it to thetd
orth
tags like so:Doing this will leave a small space between each
td
, which is likely not desirable if you want the border to appear as though it is thetr
tag. In order to "fill in the gaps" so to speak, you need to utilize theborder-collapse
property on thetable
element and set its value tocollapse
, like so:Use
Replace "thin solid" with CSS properties.
I found when using this method that the space between the td elements caused a gap to form in the border, but have no fear...
One way around this:
With the CSS:
<td style="border-bottom-style: solid; border-bottom: thick dotted #ff0000; ">
You can do the same to the whole row as well.
There is
border-bottom-style
,border-top-style
,border-left-style
,border-right-style
. Or simplyborder-style
that apply to all four borders at once.You can see (and TRY YOURSELF online) more details here
Display the row as a block.
and to display alternate colors simply:
Use
border-collapse:collapse
as Nathan wrote and you need to settd { border-bottom: 1px solid #000; }