Using CSS to make table's outer border color different from cells' border color
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;
}
It's a little bit repetitive, but it acheives the effect you're after by setting the top and left borders of the first row and column respectively, then overwriting the 'internal' rows and cells with red.
This won't of course work in IE6 as it doesn't understand the adjacent selectors.
http://jsfiddle.net/JaF5h/36/
How to make outer border of table to be of a colour different from inner in HTML?
There are two possible solutions here (from what I can see):
Wrap the table (with standard or silver border) in a div with a blue border.
Insert the table (with standard or silver border) in another table's cell. Give the "outer" table a blue border.
I think the first option is much better.
CSS outside table border of different color than inside borders between table cells
I've added an extra line to your table for the purposes of this demonstration...
<table>
<caption>Caption:</caption>
<thead>
<tr>
<th style="width: 65%;" class="first">A</th>
<th class="center" style="width: 5%;">B</th>
<th style="width: 15%;">C</th>
<th style="width: 15%;" class="last">D</th>
</tr>
</thead>
<tbody>
<tr>
<td class="first">aaa</td>
<td>bbb</td>
<td>ccc</td>
<td class="last">ddd</td>
</tr>
<tr class="final">
<td class="first">aaa</td>
<td>bbb</td>
<td>ccc</td>
<td class="last">ddd</td>
</tr>
</tbody>
</table>
And here is the CSS.
table {
width: 100%;
margin-top: 1em;
border-collapse: collapse;
}
th, td {
vertical-align: middle;
border: 1px solid #888;
padding: .2em .4em;
}
table > thead > tr > th {
border-top: 1px solid #111;
}
tr.final > td {
border-bottom: 1px solid #111;
}
.first {
border-left: 1px solid #111;
}
.last {
border-right: 1px solid #111;
}
Added jsfiddle link for previewing the code
How to change the border color of bootstrap table using inline css
Using only style="border-color:white;"
sets the table border to white but they are being overwritten by the th
and td
styles.
You have to set it for every th
and td
too. If you are using only only Inline css then that will be time consuming. The easier way would be to include the styles in css and use direct-child sign (>
) to give the style preference. Like this.
table.table-bordered > thead > tr > th{
border:1px solid blue;
}
Here is a working snippet :
table.table-bordered{ border:1px solid blue; margin-top:20px; }table.table-bordered > thead > tr > th{ border:1px solid blue;}table.table-bordered > tbody > tr > td{ border:1px solid blue;}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"><div class="container"> <table class="table table-bordered"> <thead> <tr> <th>Firstname</th> <th>Lastname</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>Doe</td> <td>john@example.com</td> </tr> </tbody> </table></div>
HTML outer and inner table with different border color using CSS
The selector
table.CommonTableStyle1 table, th, td
doesn't work properly, because there is no table in the table with class "CommonTableStyle1".
I think you meant to do this:
table.CommonTableStyle1 th, table.CommonTableStyle1 td
See fiddle
Also, the bottommost selector did work, but not in the way you may think. The th, td
part had the same specificity as the one above, so it would take this style for all th
s and td
s, because this one came later. But it's OK now, since we've made the specificity of the above one larger.
Related Topics
Changing Jsf Prefix to Suffix Mapping Forces Me to Reapply the Mapping on CSS Background Images
Drawing Border Colors During a CSS Transition
Is There Such a Thing as an "All Inclusive Sibling" CSS Selector
Calc() Not Working Within Media Queries
Webkit Support for Gradient Transitions
Parent Element Backdrop-Filter Does Not Apply for Its Child
Select Nth-Child Across Multiple Parents
How to Use the New Affix Plugin in Twitter's Bootstrap 2.1.0
Anyway to Prevent the Blue Highlighting of Elements in Chrome When Clicking Quickly
Css: 100% Font Size - 100% of What
Are CSS Selectors Case-Sensitive
Turning Off Twitter Bootstrap Navbar Transition Animation
How to Render Multiple Columns with Markdown in Github Readme
How to Add Border Radius on Table Row