CSS table border styling - css

I have a table where I'd like the row/table head to be red, but with a slightly rounded corner to be smoother than a straight edge, but I also need to space the width between the heading or the radius would be pointless. Only option I can think of is creating an empty th for a divider. But would prefer a CSS fix.
Code
.restaurant {
width: 80%;
background-color: #FFFFFF;
color: #000000;
border: 1px solid #FFFFFF;
z-index: -1;
}
.restaurant tr {
width: 100%;
background-color: #FFFFFF;
border: 1px solid #FFFFFF;
border-spacing: 5px;
z-index: -1;
}
.restaurant td {
height: 100%;
background-color: #FFFFFF;
color: #000000;
border: 1px solid #FFFFFF;
z-index: -1;
}
.restaurant th {
line-height: 15px;
background-color: #DE0000;
color: #FFFFFF;
border: 5px solid #FFFFFF
border-spacing: 10px;
border-radius: 4px;
}
html
<table class="restaurant">
<tr>
<td colspan="2">
<table class="restaurant-corners">
<tr>
<td width="10%">
<img src="/css/images/menu-corner-top-left.png" class="corners">
</td>
<td width="80%">
</td>
<td width="10%">
<img src="/css/images/menu-corner-top-right.png" class="corners" align="right">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<table class="restaurant-logo" cellspacing="0">
<tr>
<td colspan="3">
<center><img src="/css/uncletoms.png"></center>
</td>
</tr>
<tr>
<th width="80%">
<h2>Breakfast</h2>
</th>
<th width="20%">
<h2>Drinks</h2>
</th>
</tr>
</table>
Probably more information there then needed. But I wanted to make sure I didn't missing anything.

When designing a table with rounded corners, do not use border-collapse: collapse. OP's request for row to be red is vague...Red borders? Text? Background?...Need specifics. We will apply border-radius to the table's border and to the first and last <th> borders. See the comments in the Snippet:
section {
padding: 20px 10px;
width: 100%;
height: auto;
border-bottom: 3px ridge #FF6;
margin: 0 5px 20px;
}
table.x {
position: relative;
padding: 0;
box-shadow: 0 1px 9px 1px #ccc;
/* This will round the outside border on all 4 corners */
/* If you want only the head to have rounded corners uncomment *1* ruleset and remove or comment *2*/
/* border-top-left-radius: 6px;
border-top-right-radius: 6px;
*/
border-radius: 6px;
margin: 20px auto;
table-layout: fixed;
width: 50%;
height: 100%;
max-height: 550px;
}
.x th {
color: #FFF;
background: #2C7EDB;
padding: 10px;
text-align: center;
vertical-align: middle;
}
.x tr:nth-child(odd) {
background-color: #333;
color: #FFF;
}
.x tr:nth-child(even) {
background-color: #D3E9FF;
color: #333;
}
.x td {
border-style: solid;
border-width: 1px;
border-color: #264D73;
padding: 5px;
text-align: left;
vertical-align: top;
position: relative;
}
/* Next 2 rulesets are used to create rounded corners to the inner borders of the head */
/* Remove or comment the last 2 rulesets if you don't want the bottom corners rounded */
.x thead th:first-child {
border-top-left-radius: 6px;
}
.x thead th:last-child {
border-top-right-radius: 6px;
}
.x tbody tr:last-child td:first-child {
border-bottom-left-radius: 6px;
}
.x tbody tr:last-child td:last-child {
border-bottom-right-radius: 6px;
}
<section>
<table class="x">
<caption>table.x</caption>
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
</tbody>
</table>
</section>

Related

bug where the border of the table is not visible

i don't understand why border of first tbody tr's td is not visible.
i think there is no reason border is not visible.
what i fugure out is this.
if natural height of th is higher than height i fixed for th, first tbody tr's td is visible.
if there is no code th{height: xxpx; }, first tbody tr's td is visible.
.table {
border-spacing: 0;
border-collapse: collapse;
}
.table.summary-style
{
font-size: 11px;
width: 100%;
table-layout: fixed;
text-align: center;
color: #666;
border-bottom: 1px solid #666;
background: #fff;
}
.table.summary-style caption
{
font-size: 0;
line-height: 0;
display: none;
overflow: hidden;
clip: rect(1px 1px 1px 1px);
/* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
width: 0;
height: 0;
margin: 0;
padding: 0;
opacity: 0;
}
.table.summary-style thead th
{
font-size: 16px;
line-height: 1;
position: relative;
box-sizing: border-box;
height: 38px;
padding: 5px 4px;
text-align: center;
vertical-align: middle;
color: #666;
background: #ddd;
}
.table.summary-style > tbody > tr > td
{
font-size: 13px;
line-height: 1.38;
box-sizing: border-box;
height: 36px;
padding: 4px 10px;
text-align: left;
vertical-align: middle;
color: #666;
border-top: 1px solid #666;
background: #fff;
}
<table class="table summary-style">
<thead>
<tr>
<th scope="col">title</th>
<th scope="col">title</th>
<th scope="col">title</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">No Data.</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
</tbody>
</table>
This is happening because position: relative; on .table.summary-style thead th causes that row of elements to appear 'above' the borders of other elements. This is despite the fact that box-sizing: border-box; has been used, as the borders of the table elements have been collapsed together. The solution is to either remove position: relative; on the first row or remove border-collapse: collapse; from .table.
.table {
border-spacing: 0;
border-collapse: collapse;
}
.table.summary-style
{
font-size: 11px;
width: 100%;
table-layout: fixed;
text-align: center;
color: #666;
border-bottom: 1px solid #666;
background: #fff;
}
.table.summary-style caption
{
font-size: 0;
line-height: 0;
display: none;
overflow: hidden;
clip: rect(1px 1px 1px 1px);
/* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
width: 0;
height: 0;
margin: 0;
padding: 0;
opacity: 0;
}
.table.summary-style thead th
{
font-size: 16px;
line-height: 1;
box-sizing: border-box;
height: 38px;
padding: 5px 4px;
text-align: center;
vertical-align: middle;
color: #666;
background: #ddd;
}
.table.summary-style > tbody > tr > td
{
font-size: 13px;
line-height: 1.38;
box-sizing: border-box;
height: 36px;
padding: 4px 10px;
text-align: left;
vertical-align: middle;
color: #666;
border-top: 1px solid #666;
background: #fff;
}
<table class="table summary-style">
<thead>
<tr>
<th scope="col">title</th>
<th scope="col">title</th>
<th scope="col">title</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">No Data.</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
</tbody>
</table>
Try:
table,
td,
th {
border-collapse: collapse;
padding: 0.5em 1em;
border: 2px solid black;
}
.table.summary-style {
font-size: 11px;
width: 100%;
table-layout: fixed;
text-align: center;
color: #666;
border-bottom: 1px solid #666;
background: #fff;
}
.table.summary-style caption {
font-size: 0;
line-height: 0;
display: none;
overflow: hidden;
clip: rect(1px 1px 1px 1px);
/* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
width: 0;
height: 0;
margin: 0;
padding: 0;
opacity: 0;
}
.table.summary-style thead th {
font-size: 16px;
line-height: 1;
position: relative;
box-sizing: border-box;
height: 38px;
padding: 5px 4px;
text-align: center;
vertical-align: middle;
color: #666;
background: #ddd;
}
.table.summary-style>tbody>tr>td {
font-size: 13px;
line-height: 1.38;
box-sizing: border-box;
height: 36px;
padding: 4px 10px;
text-align: left;
vertical-align: middle;
color: #666;
border-top: 1px solid #666;
background: #fff;
}
<table class="table summary-style">
<thead>
<tr>
<th scope="col">title</th>
<th scope="col">title</th>
<th scope="col">title</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">No Data.</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
</tbody>
</table>

Inner border-radius on a table cell

I'm trying to create a photo frame with a HTML table and some CSS.
I want to add an inner border-radius to it, but I can't find a way to color "edges" (spaces between "normal border" and "border with radius").
Here's a fiddle that showcases my problem. The objective is to color the edges of the center cell, without coloring it (it must be transparent to show what's underneath, the table background color in the example).
table {
border-spacing: 0;
background-color: aqua;
}
td {
border: solid 1px red;
padding: 50px;
background-color: red;
}
td.middle {
border-radius: 50px;
border: 1px solid green;
background-color: transparent;
}
tr:first-child td { border-top-style: solid; }
tr td:first-child { border-left-style: solid; }
<table>
<tr>
<td>1.1</td>
<td>1.2</td>
<td>1.3</td>
</tr>
<tr>
<td>2.1</td>
<td class="middle">2.2</td>
<td>2.3</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
<td>3.3</td>
</tr>
</table>
you need to consider a new element inside your td
if there gonna be an image , you won't need that span inside your div
table {
border-spacing: 0;
background-color: aqua;
}
td {
border: solid 1px red;
padding: 50px;
background-color: red;
}
td.middle {
padding: 0px;
}
#center_frame{
width: 100px;
height: 100px;
margin: auto;
border-radius: 50px;
border: 1px solid green;
border: solid 1px red;
background-color: lightblue;
text-align: center;
}
#center_frame span {
line-height: 100px;
}
tr:first-child td { border-top-style: solid; }
tr td:first-child { border-left-style: solid; }
<table>
<tr>
<td>1.1</td>
<td>1.2</td>
<td>1.3</td>
</tr>
<tr>
<td>2.1</td>
<td class="middle">
<div id="center_frame"><span>2.2</span></div>
</td>
<td>2.3</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
<td>3.3</td>
</tr>
</table>
Use radial-gradient for this
table {
border-spacing: 0;
background-color: aqua;
}
td {
border: solid 1px red;
padding: 50px;
background-color: red;
}
td.middle {
background:radial-gradient(farthest-side,transparent 99%,red 100%);
}
tr:first-child td {
border-top-style: solid;
}
tr td:first-child {
border-left-style: solid;
}
<table>
<tr>
<td>1.1</td>
<td>1.2</td>
<td>1.3</td>
</tr>
<tr>
<td>2.1</td>
<td class="middle">2.2</td>
<td>2.3</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
<td>3.3</td>
</tr>
</table>
For a custom radius you will need 4 gradient:
table {
border-spacing: 0;
background-color: aqua;
}
td {
border: solid 1px red;
padding: 50px;
background-color: red;
}
td.middle {
background:
radial-gradient(farthest-side at bottom left, transparent 98%,red 100%) top right,
radial-gradient(farthest-side at bottom right,transparent 98%,red 100%) top left,
radial-gradient(farthest-side at top left, transparent 98%,red 100%) bottom right,
radial-gradient(farthest-side at top right,transparent 98%,red 100%) bottom left;
background-size:25% 25%; /* adjust this to control the radius (from 0% to 50% or pixel value) */
background-repeat:no-repeat;
}
tr:first-child td {
border-top-style: solid;
}
tr td:first-child {
border-left-style: solid;
}
<table>
<tr>
<td>1.1</td>
<td>1.2</td>
<td>1.3</td>
</tr>
<tr>
<td>2.1</td>
<td class="middle">2.2</td>
<td>2.3</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
<td>3.3</td>
</tr>
</table>

tbody border is not flush with table header

I am having trouble making tbody border not extending over the width of thead. Is there a way to fix it? Thanks
PS: There are other problems like the empty ".cell" div not sizing properly, however I'm not sure if you can post multi-issue questions. So let's focus on the issue above.
table {
box-sizing: border-box;
border-collapse: collapse;
margin-bottom: 2000px;
}
th {
background-color: white;
position: sticky;
top: 0;
padding: 0;
border: 0;
}
.cell {
box-sizing: border-box;
display: inline-block;
height: 100%;
width: 100%;
padding: 15px;
background-color: red;
}
th:first-of-type > .cell {
border-radius: 5px 0 0 0;
}
th:last-of-type > .cell {
border-radius: 0 5px 0 0;
}
td {
border: 1px solid blue;
background-color: #fff;
padding: 15px;
}
tbody {
border: 2px solid green;
box-sizing: border-box;
}
<table>
<thead>
<tr>
<th><div class="cell"></div></th>
<th><div class="cell">aaaaaa</div></th>
<th><div class="cell">aaaa</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>aaa</td>
<td>aaaaaa</td>
<td>aaaa</td>
</tr>
<tr>
<td>aaa</td>
<td>aaaaaa</td>
<td>aaaa</td>
</tr>
<tr>
<td>aaa</td>
<td>aaaaaa</td>
<td>aaaa</td>
</tr>
</tbody>
</table>
I'm assuming the rounded corners are the reason why you are placing <div> within the <th>. If you want rounded corners then you need to use the following styles:
table { border-collapse:separate; border-spacing:0; border: 0; }
The demo has some additional changes that can be adjusted.
Demo
table {
border-collapse: separate;
border-spacing: 0;
margin-bottom: 2000px;
border: 0;
}
thead {
position: sticky;
top: 0;
}
th {
border: 1px solid red;
background-color: red;
padding:15px;
}
th:first-of-type {
border-top-left-radius: 6px;
}
th:last-of-type {
border-top-right-radius: 6px;
}
td {
border: 1px solid blue;
background-color: #fff;
padding: 15px;
}
<table>
<thead>
<tr>
<th></th>
<th>aaaaaa</th>
<th>aaaa</th>
</tr>
</thead>
<tbody>
<tr>
<td>aaa</td>
<td>aaaaaa</td>
<td>aaaa</td>
</tr>
<tr>
<td>aaa</td>
<td>aaaaaa</td>
<td>aaaa</td>
</tr>
<tr>
<td>aaa</td>
<td>aaaaaa</td>
<td>aaaa</td>
</tr>
</tbody>
</table>

Border radius doesn't work at table

The border-radius at table work only on background and border remain straight.
This is my css
.table_mem, .th_mem, .tr_mem, .td_mem{
border: 1px solid #000000;
border-radius: 20px;
border-collapse: collapse;
text-align: center;
padding: 7px;
}
.th_mem{ background-color: #9e9e9e;}
.tr_mem{ background-color: #e5e5e5; transition: .5s;}
.tr_mem:hover{ background-color: #bfbfbf; }
Someone can say me a solution?
The borders are straight because of collapsing, simple set border-collapse to separate:
body { padding-top: 1em; }
.table_mem,
.table_mem thead th,
.table_mem tbody tr,
.table_mem tbody td {
border: 1px solid #000000 !important;
border-radius: 20px;
border-collapse: separate;
text-align: center;
padding: 7px;
}
.table_mem thead th {
background-color: #9e9e9e;
}
.table_mem tbody tr {
background-color: #e5e5e5;
transition: .5s;
}
.table_mem tbody tr:hover {
background-color: #bfbfbf;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<table class="table table_mem">
<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>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary#example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july#example.com</td>
</tr>
</tbody>
</table>
</div>
jsfiddle: https://jsfiddle.net/azizn/kkv9guhx/

Trouble changing the style on a table within a div statement

I created a table in HTML5 and used CSS to make it pretty. Then I decided to add a scroll bar and used webkit to change the style of that. Now after I used a div to get my scroll bar working it seems like my CSS code for the tbody,tr,thead,etc. are not working. I was wondering what I am doing wrong. I am positive that I am not calling the html table attributes correctly. I am very new to html5 and css but would really like to learn more.
Here is my code:
UPDATED 7/11/2013 9:36pm
CSS CODE
::-webkit-scrollbar {
width: 12px;
color:crimson;
background-color: black;
border-radius: 10px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
background-color:black;
}
::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
background-color:gray;
}
.mytablecontainer #mytable{
width:500px;
border-collapse:separate;
background:crimson;
border-radius: 15px;
}
.mytablecontainer tbody {
overflow: auto;
height: 150px;
float: left;
width: 100%;
}
.mytablcontainer #mytable td {
text-align:center;
background:gray;
border-bottom:5px solid black;
border-radius: 15px;
}
.mytablecontainer #mytable th {
font-weight:bold;
text-align:center;
background:crimson;
border-bottom:5px solid black;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
float: left;
width: 100%;
}
.mytablecontainer #mytable tr {
width: 100%;
display: table;
}
HTML5 CODE
<div class="mytablecontainer">
<table id="mytable">
<thead>
<tr>
<span>
Playlist
</span>
</tr>
</thead>
<tbody>
<tr>
<td> <span>
LINK 1
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 2
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 3
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 4
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 5
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 6
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 7
</span>
</td>
</tr>
</tbody>
</table>
</div>
.mytablcontainer #mytable.td {} remove "." dot before td and correct the spelling of your class
.mytablecontainer #mytable td {}
Demo
you do not need to call each time your main div selector try this css
::-webkit-scrollbar {
width: 12px;
color:crimson;
background-color: black;
border-radius: 10px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
background-color:black;
}
::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
background-color:gray;
}
.mytablecontainer #mytable{
width:500px;
border-collapse:separate;
background:crimson;
border-radius: 15px;
}
#mytable tbody {
overflow: auto;
height: 150px;
float: left;
width: 100%;
}
#mytable td {
text-align:center;
background:gray;
border-bottom:5px solid black;
border-radius: 15px;
}
#mytable th {
font-weight:bold;
text-align:center;
background:crimson;
border-bottom:5px solid black;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
float: left;
width: 100%;
}
#mytable tr {
width: 100%;
display: table;
}
for multiple attribute use this:
#mytable table, #mytable th, #mytable td {
border: 1px solid black;
border-collapse: collapse;
}

Resources