table{border:1px solid #000;} doesn't seem to work without the border=1 statement.
In the same way as changing <input width=30> into input{width:400px;}, I would like to use <table> and declare the border in css only. Is that possible?
Update
my mistake was using
table{border-width:1px;}
instead of e.g.
table{border:1px solid #000;}
--which works fine.
Use this CSS:
table {
border-collapse: collapse
}
td {
border: 1px solid #000
}
Live Demo
border-collapse: collapse is important; without it you get doubled borders, like this.
Absolutely - that is the preferred way. You might have to style td as well as tr.
Try this in CSS
table
{
border:1px solid black;
}
then you can use it in HTML
<table>
....
</table>
yes, but if you use table, it will affect ALL tables in your html.
I suggest doing:
<table class="myTable"> and then .myTable { /*css*/ }
Your style should be:
table td { border: 1px solid #000000; }
See a working example here.
If you are using, <th> for headers, with the code below, you will not get borders around our headers:
td { border: 1px solid #000000; }
you will need to also add:
th { border: 1px solid #000000; }
Regards,
Related
Here is what I have in CSS:
table.defaultTable
{
border-style: Solid;
border-width: thin;
text-align: center;
border: 1px;
}
This is what it the table looks like:
As you can see, the cells inside the table do not have a solid border around them.
table.defaultTable td
{
border: 1px solid black;
}
This will put a border around each cell in your defaultTable. However, there will be space between them. To remove that space, you also need the following:
table.defaultTable { border-collapse: collapse; }
http://jsfiddle.net/YH46T/1/
Try to use rule
table td{
border: 1px solid black;
}
Of course you can use class or id selectors on table for separation of rule influence. But main idea is set border to the table's cells, not the header, because for header you should use th elements.
If you want to add a border simply add the line border: 1px solid #000; to your css.
td{
border: 1px solid #000;
}
I would acheive this by using adjacent selectors, like so:
table {
border: 1px solid #000;
}
tr {
border-top: 1px solid #000;
}
tr + tr {
border-top: 1px solid red;
}
td {
border-left: 1px solid #000;
}
td + td {
border-left: 1px solid red;
}
You could try it with
border-collapse: separate;
See here: http://www.w3schools.com/cssref/pr_border-collapse.asp
Another way could be to define a class "cell-border" (or similar) and give that class a border property.
You need to set the border property on cells. Setting it on the table element sets only a border on the table as a whole. A minimal rule would be
th, td { border: solid }
In general, a table can have two kinds of cells, headers cells th and data cells td. In a table that presents tabular data, rather than acts as a layout tool only, there is usually a row of header cells that specify column headers.
I am having an issue with a table border not displaying correctly. Below is a fiddle recreating the issue.
This Fiddle produces expected results in FF and Chrome but not in IE9 and IE10.
Only css that is being applied is a border-collapse: collapse and
td{
border:1px solid;
}
The second table row should have a border along the entire bottom however the border is missing on the second table cell. Can be seen in this image.
This issue disappears once part of the table is highlighted but the expected result is that the border should be there in the first place. Sometimes the fiddle must be updated for the issue to appear.
Is this a known IE issue or is there more styling that must be applied?
I had a similar problem and your solution above worked for me with a slight change. (I used primefaces)
Following code worked
.ui-datatable tbody>tr>td {
border-top: 1.1px solid;
}
Following code didn't work
.ui-datatable tbody>tr>td {
border-top: 1px solid;
}
Best solution that I could find:
table{border-top:1px solid #000;}
tr{border-left:1px solid #000;border-bottom:1px solid #000;}
td{border-right:1px solid #000;}
Example here
Checked in both IE9 and IE10
Since this is caused by border-collapse: collapse it can also be solved by placing the borders in the correct places manually and using border-collapse: separate.
table {
border-collapse: separate;
border-spacing: 0;
}
td {
border-bottom:1px solid;
border-right:1px solid;
}
tr > td:first-child {
border-left: 1px solid;
}
table tr:first-child td {
border-top: 1px solid;
}
This doesn't work in IE7 and below because they don't support neither border-spacing nor :first-child.
For me this worked:
<table cellspacing="0" and cellpadding="0"> ... </table>
I found using position: static; on the th/td works well.
table {
border-collapse: collapse;
border: none;
}
tr {
border: none;
}
th, td {
position: static;
border: 1px solid #000;
}
I have created this very simple fiddle to reproduce the issue. I does what's expected in firefox but not in chrome. Is there a workaround to achieve the same purpose ?
Here is the HTML code:
<table cellpadding="1">
<thead>
<tr>
<th>Adskldj</th>
<th>dfsdfd</th>
</tr>
</thead>
<tbody>
<tr><th>Adskldj</th><th>dfsdfd</th></tr>
<tr><th>Adskldj</th><th>dfsdfd</th></tr>
<tr><th>Adskldj</th><th>dfsdfd</th></tr>
<tr><th>Adskldj</th><th>dfsdfd</th></tr>
</tbody>
</table>
And the CSS
table {
border-collapse:collapse;
}
td, th {
border-top: 1px solid #888;
border-bottom: 1px solid #888;
padding: 30px;
}
thead {
background-color: #DDD;
box-shadow:inset 0 0 10px #000000;
}
I believe that box-shadow needs to be on a block level element. Hence it not working on a thead.
I have tried to find the spec, but still. Block Level.
I've had success using the CSS3 fancy-ness by bypassing table tags and using css display properties instead, making a class for each native table-element and applying it to a <div> or other element.
CSS such as:
.row{
display:table-row;
}
.cell{
display:table-cell;
}
etc.
This allows some nice effects that are not possible using regular tables.
I try to put a border-bottom at the table-rows but they don't show up. Why is that?
http://www.mysecretathens.gr/Sera/dates.html
I think my code is pretty simple putting a class to ther tr element.
<tr class="line">
table tr.line {border-bottom: 1px solid #B4B5B0;}
You can try this:
tr.line td{
border-bottom: 1px solid #B4B5B0;
}
You can't put borders on tr elements. You have to put them on td
Change your style to:
tr.line td{ border-bottom: 1px solid #B4B5B0;}
Add "border-collapse: collapse" style to your table element and that should bring up the row borders
Do it on the table cells, it works for all browsers.
table tr.line td {border-bottom: 1px solid #B4B5B0;}
if you have a single table on the page, you may try;
td{
border-bottom: solid 1px #B4B5B0;
}
or if you have multiple tables, use class, like;
.your_table_class td{
border-bottom: solid 1px #B4B5B0;
}
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.
Add border-collapse:collapse to your table rule:
table {
border-collapse: collapse;
}
Example
table {
border-collapse: collapse;
}
tr {
border-bottom: 1pt solid black;
}
<table>
<tr><td>A1</td><td>B1</td><td>C1</td></tr>
<tr><td>A2</td><td>B2</td><td>C2</td></tr>
<tr><td>A2</td><td>B2</td><td>C2</td></tr>
</table>
Link
I had a problem like this before. I don't think tr can take a border styling directly. My workaround was to style the tds in the row:
<tr class="border_bottom">
CSS:
tr.border_bottom td {
border-bottom: 1px solid black;
}
Use border-collapse:collapse on table and border-bottom: 1pt solid black; on the tr
Use
border-collapse:collapse as Nathan wrote and you need to set
td { border-bottom: 1px solid #000; }
There are lot of incomplete answers here. Since you cannot apply a border to tr tag, you need to apply it to the td or th tags like so:
td {
border-bottom: 1pt solid black;
}
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 the tr tag. In order to "fill in the gaps" so to speak, you need to utilize the border-collapse property on the table element and set its value to collapse, like so:
table {
border-collapse: collapse;
}
You can use the box-shadow property to fake a border of a tr element. Adjust Y position of box-shadow (below represented as 2px) to adjust thickness.
tr {
-webkit-box-shadow: 0px 2px 0px 0px rgba(0,0,0,0.99);
-moz-box-shadow: 0px 2px 0px 0px rgba(0,0,0,0.99);
box-shadow: 0px 2px 0px 0px rgba(0,0,0,0.99);
}
I tried adding
table {
border-collapse: collapse;
}
alongside the
tr {
bottom-border: 2pt solid #color;
}
and then commented out border-collapse to see what worked. Just having the tr selector with bottom-border property worked for me!
No Border CSS ex.
No Border Photo live
CSS Border ex.
Table with Border photo live
Use
table{border-collapse:collapse}
tr{border-top:thin solid}
Replace "thin solid" with CSS properties.
Display the row as a block.
tr {
display: block;
border-bottom: 1px solid #000;
}
and to display alternate colors simply:
tr.oddrow {
display: block;
border-bottom: 1px solid #F00;
}
Another solution to this is border-spacing property:
table td {
border-bottom: 2px solid black;
}
table {
border-spacing: 0px;
}
<table>
<tr>
<td>ABC</td>
<td>XYZ</td>
</table>
If you don't want to
enforce border collapse on the table
use the TD elements styling
You can use the ::after selector to add borders to TR :
table tbody tr {
position : relative; # to contain the ::after element within the table-row
}
table tbody tr td {
position : relative; # needed to apply a z-index
z-index : 2; # needs to be higher than the z-index on the tr::after element
}
table tbody tr::after {
content : '';
position : absolute;
z-index : 1; # Add a z-index below z-index on TD so you can still select data from your table rows :)
top : 0px;
left : 0px;
width : 100%;
height : 100%;
border : 1px solid green; # Style your border here, choose if you want a border bottom, top, left, etc ...
}
It is a simple trick that I used in a scenario where I had to put spaces between table-rows so I wasn't able to add a border collapse on the table, the end result :
Hope it helps :)
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:
<tr>
<td>
Example of normal table data
</td>
<td class="end" colspan="/* total number of columns in entire table*/">
/* insert nothing in here */
</td>
</tr>
With the CSS:
td.end{
border:2px solid black;
}
<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 simply border-style that apply to all four borders at once.
You can see (and TRY YOURSELF online) more details here
Several interesting answers. Since you just want a border bottom (or top) here are two more. Assuming you want a blue border 3px thick. In the style section you could add
.blueB {background-color:blue; height:3px} or
hr {background-color:blue; color:blue height:3px}
In the table code either
<tr><td colspan='3' class='blueB></td></tr> or
<tr><td colspan='3'><hr></td></tr>
No CSS border bottom:
<table>
<thead>
<tr>
<th>Title</th>
</tr>
<tr>
<th>
<hr>
</th>
</tr>
</thead>
</table>
You can't put a border on a tr element. This worked for me in firefox and IE 11:
<td style='border-bottom:1pt solid black'>
HTML
<tr class="bottom-border">
</tr>
CSS
tr.bottom-border {
border-bottom: 1px solid #222;
}