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/
Related
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>
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>
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>
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>
I'm trying to create a simple 3x3 grid (using <table>) with all cells having a 1px border. If I simply use CSS to give all <td> elements a 1px border then the inner borders will stack and create 2px border so I'm treating each <td> differently. I have succeeded in doing it that way and used nth child to reduce the CSS. However, my question is why a certain logical way that uses even less CSS selectors doesn't work.
Here is my HTML
<!DOCTYPE html>
<html>
<head>
<title>3x3 grid</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<table>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</table>
</body>
</html>
Here is the CSS that works:
td{
border: 1px #000;
width:30px;
height: 30px;
text-align: center;
border-style: solid;
}
tr:nth-child(2) td{
border-top: 0px;
}
tr:nth-child(3) td{
border-top: 0px
}
td:nth-child(1){
border-right: 0px;
}
td:nth-child(3){
border-left: 0px;
}
table{
border-spacing: 0px;
border-collapse: separate;
}
Here is the CSS that uses one less selector and should work but somehow all upper cells end up with no top borders.
td{
border: 1px #000;
border-top: 0px;
width:30px;
height: 30px;
text-align: center;
border-style: solid;
}
tr:nth-child(1) td{
border-top: 1px;
}
td:nth-child(1){
border-right: 0px;
}
td:nth-child(3){
border-left: 0px;
}
table{
border-spacing: 0px;
border-collapse: separate;
}
I tested it with both Safari and Firefox. Also please tell me if there is a better way to do it.
The reason you have no top border on your td's is because you aren't declaring a border-style or border-color...
tr:nth-child(1) td{
border-top: 1px;
}
should be...
tr:nth-child(1) td{
border-top: 1px solid #000;
}
You could simplify this greatly by just using border-collapse: collapse
td{
border: 1px #000;
width:30px;
height: 30px;
text-align: center;
border-style: solid;
}
table{
border-collapse: collapse;
}
<table>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</table>
You can simply do that by below code only :
<style>
table {
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
}
</style>
I don't know why, but td's in first row have changed from solid to none. Try using:
tr:nth-child(1) td{
border-top: solid black 1px;
}
in CSS and should be right. http://jsfiddle.net/u1d1ctcy/