How to create a table with no outer border but inner borders only. Something like this one (See bottom right in the page). I know that I can create it manually like they did, I mean to give a class to each td but isn't out there a better way to realize this?
No they didn't do it that way, it's done in a nice way! :)
This removes the right border from the cells:
.sidebar-stats td:last-child, .sidebar-stats th:last-child {
border-right: 0 none;
}
(In the same way you can remove the bottom-border for the last row. You can use Firebug to analyse their CSS, helps a lot!)
Here's a solution that'll work in all browsers, but requires you to add a CSS class to the furthest right and bottom <td>'s in your table (vs having to give a class to each <td>)
<table>
<tr><td class="inner">text</td><td class="inner right">text</td></tr>
<tr><td class="inner bottom">text</td><td class="inner bottom right">text</td></tr>
</table>
.inner {
border-bottom: 1px solid #CCC;
border-right: 1px solid #CCC;
}
.right {
border-right: 0;
}
JSFiddle: http://jsfiddle.net/HS4nQ/3/
You can style the td elements to have borders, and then giver your table border:0, an make sure to add border-collapse:collapse to the table as well. It should look like this in the end:
table {
border:0;
border-collapse:collapse;
}
td {
border:1px gray solid;
border-collapse:collapse;
}
This is the :first-child variation:
http://jsfiddle.net/6Z7R9/
table.mytable > * > tr > th,
table.mytable > * > tr > td {
border-left: 10px solid red;
border-top: 10px solid red;
}
table.mytable > * > tr > th,
table.mytable > * > tr > td:first-child {
border-left: none;
}
table.mytable > *:first-child > tr:first-child > th,
table.mytable > *:first-child > tr:first-child > td {
border-top: none;
}
Related
I want to use a bootstrap 3 table with borders, eg using class="table table-bordered", so that I'll have borders between cells, but I don't want any borders on the outsides of the table.
I tried the following, and it seems to work well for the sides, but I can't think of a nice way to handle the potential top and bottom borders considering that thead and tfoot are optional elements. I was hoping to make something robust that would account for these scenarios, maximizing resuse potential.
.table-bordered.no-outside-borders {
border: none;
}
.table-bordered.no-outside-borders>thead>tr>td:first-child,
.table-bordered.no-outside-borders>thead>tr>th:first-child,
.table-bordered.no-outside-borders>tfoot>tr>td:first-child,
.table-bordered.no-outside-borders>tfoot>tr>td:first-child,
.table-bordered.no-outside-borders>tbody>tr>td:first-child,
.table-bordered.no-outside-borders>tbody>tr>th:first-child {
border-left: none;
}
.table-bordered.no-outside-borders>thead>tr>td:last-child,
.table-bordered.no-outside-borders>thead>tr>th:last-child,
.table-bordered.no-outside-borders>tfoot>tr>td:last-child,
.table-bordered.no-outside-borders>tfoot>tr>th:last-child,
.table-bordered.no-outside-borders>tbody>tr>td:last-child,
.table-bordered.no-outside-borders>tbody>tr>th:last-child {
border-right: none;
}
Is there a nice css solution here?
I had the same problem yesterday, the css code I used for this was:
.table-borderless tbody tr td, .table-borderless tbody tr th, .table-borderless thead tr th {
border: none;
max-height: 200px;
font-size: 20px;
border-right: 1px solid gray;
border-collapse: collapse;
}
.table.table-borderless {
border-right: 1px solid gray;
border-collapse: collapse;
max-height: 200px;
font-size: 20px;
}
This is the jsfiddle
http://jsfiddle.net/r323e/
it is very simple:
I want to put a border on the table tr so I tried this:
.table tr{
height: 30px;
border-bottom: 10px solid #000000;
}
The height property is applied but the border is not.
why please? and how to fix it.
Many thanks
Add display:block to your tr style.
.table tr{
display:block;
height: 30px;
border-bottom: 10px solid #000000;
}
you can define a tr class css like this
<tr class="border_bottom">
and in your css you can do this
tr.border_bottom td {
border-bottom:1pt solid black;
}
tried in your code and works..good luck!!
I had create table with help of bootstrap css. I want to remove padding of cell and bordercolor black to whole table only with bootstrap css. I don't want to create my own css.Only from boot strap classes I want to remove padding and provide border color black to whole table.
Thanx in advance.
plz help me.....
You can overwrite the class rule by adding !important attribute to desired property
like
.table{padding:0 !important}
.table-bordered td {
border: 1px solid #ddd !important;
}
.table tfoot > tr > td {
padding: 8px;
line-height: 1.428571429;
vertical-align: top;
border-top: 1px solid #dddddd;
}
.table thead > tr > th {
vertical-align: bottom;
border-bottom: 2px solid #dddddd;
}
How to change the color of the horizontal lines in a bootstrap table having class table-condensed ?
They are using border-bottom property for td and th - Reference.. so the selector you can use is
.table.table-condensed tr th {
border-bottom: 2px solid #f00; /* Change the color you want to set */
}
.table.table-condensed tr td {
border-bottom: 1px solid #f00; /* Change the color you want to set */
}
This will apply to all the tables, so it would be better if you assign a unique class or an id and change the selector accordingly.
If you want, you can also customize your Bootstrap here.
Do the following - lets say you want to make the horizontal lines red :
/* header */
.table > thead > tr > th {
border-bottom: 2px solid red;
}
/* rows */
.table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td {
border-top: 1px solid red;
}
see fiddle -> http://jsfiddle.net/XazR4/
Add a class to your table like <table class='table-condensed your_class'></table>
and in your css add
table.your_class {
border:1px solid red;
}
Change red to whatever color you want.
is there any way to apply to a table cells' both the separate and the collapsed border properties to have collapsed but separated? Thanks
EDIT: this is the wanted result:
Perhaps
table {
border-spacing: 1px 0;
}
The closest I can get is:
table {
border-collapse: separate;
border-spacing: 4px 0;
}
table td, table th {
border: 1px solid black;
}
Unfortunately, this will create a double-thick line between the rows. Negative values are not allowed in the border-spacing property, otherwise -1px would probably work.
You could make the other lines 2px wide if that is acceptable, then at least you wouldn't have differing border thicknesses:
table {
border-collapse: separate;
border-spacing: 4px 0;
}
table td, table th {
border-width: 1px 2px;
border-style: solid;
border-color: black;
}
table tr:first-child th,
table tr:first-child td {
border-top-width: 2px;
}
table tr:last-child th,
table tr:last-child td {
border-bottom-width: 2px;
}
This can be achieved without using extra div elements in the th & td cells. This solution works in Chrome, Firefox and IE8+.
CSS
table
{
border-collapse: separate;
border-spacing: 10px 0px;
}
td, th
{
padding: 10px;
border: 1px solid #000;
border-top: none;
}
table tr:first-child th
{
border-top: 1px solid #000;
}
Change table tr:first-child th to table tr:first-child td if the table's first row doesn't contain table header cells (TH).
See my jsfiddle here: Table with column spacing but collapsed row border
No, the border-collapse does not allow for separate defining of the horizontal and vertical. You can achieve it with extra markup (which, on a table, could end up being a lot of extra markup), so I don't advise it, but I will give the code for it:
Html:
<table>
<tr>
<th><div>Header 1</div></th>
<th><div>Header 2</div></th>
</tr>
<tr>
<td><div>Content 1</div></td>
<td><div>Content 2</div></td>
</tr>
<tr>
<td><div>Content 3</div></td>
<td><div>Content 4</div></td>
</tr>
</table>
And css:
table {border-collapse: collapse;}
th, td { border: 0; padding: 0;}
th div, td div {margin: 5px 0 0; border: 1px solid #ff0000; padding: 5px;}
Of course, you may want to use a class on the div or a child selector, some way of only targeting the div if you might have other div's in the table data. The margin controls your horizontal gap, and of course, your padding or border width can be whatever you want.
Is this what you're looking for?
table {
border: 1px solid black;
}
table td {
border: 1px solid red;
margin: 3px;
}
It doesn't use the border-collapse property, but it creates an outer table border with each <td> in its own separate border.