I need to create a table with two columns and the first column, the cells only have a bottom border, where the cells in the second column have borders all around with round corner for the top and bottom.
My code looks like this, and work in Explorer, but in Firefox and Chrome it gives me round corner border plus normal corners:
table {
border-collapse: collapse;
width: 50%;
font-family: Proxima Nova, Arial;
}
.h1 {
/*Head cell red*/
text-align: center;
border: 1px solid #D81541;
border-radius: 20px 20px 0px 0px;
background-color: #D81541;
color: white;
font-size: 1.5em;
font-weight: bold;
width: 60%;
}
.td1 {
/*right column cells*/
border: 1px solid #6D6E70;
text-align: left;
width: 60%;
}
.td2 {
/*left column cells bold*/
border-bottom: 1px solid #6D6E70;
font-weight: bold;
vertical-align: top;
}
.td3 {
/*last cell right column*/
border: 1px solid #6D6E70;
border-radius: 0px 0px 20px 20px;
text-align: left;
width: 60%;
}
.td4 {
/*last cell left column*/
vertical-align: top;
font-weight: bold;
}
<table>
<tr>
<td class="td2"></td>
<td class="h1">My top corners should be round</td>
</tr>
<tr>
<td class="td2">bla</td>
<td class="td1">blabla</td>
</tr>
<tr>
<td class="td4">last row</td>
<td class="td3">my bottom corners should be round</td>
</tr>
</table>
Just remove border-collapse: collapse; from .table & add border-spacing:0 to it
Check the snippet. with thanks to #Abhitalks for his previous fiddle.
table {
border-spacing: 0;
width: 50%;
font-family: Proxima Nova, Arial;
}
.h1 {
/*Head cell red*/
text-align: center;
border: 1px solid #D81541;
border-radius: 20px 20px 0px 0px;
background-color: #D81541;
color: white;
font-size: 1.5em;
font-weight: bold;
width: 60%;
}
.td1 {
/*right column cells*/
border: 1px solid #6D6E70;
text-align: left;
width: 60%;
}
.td2 {
/*left column cells bold*/
border-bottom: 1px solid #6D6E70;
border-top: 1px solid #6D6E70;
font-weight: bold;
vertical-align: top;
}
.td3 {
/*last cell right column*/
border: 1px solid #6D6E70;
border-radius: 0px 0px 20px 20px;
text-align: left;
width: 60%;
}
.td4 {
/*last cell left column*/
vertical-align: top;
font-weight: bold;
border-top: 1px solid #6D6E70;
}
.td5 {
/*left column first cells*/
border-bottom: 1px solid #6D6E70;
font-weight: bold;
vertical-align: top;
}
<table>
<tr>
<td class="td5"></td>
<td class="h1">My top corners should be round</td>
</tr>
<tr>
<td class="td2">bla</td>
<td class="td1">blabla</td>
</tr>
<tr>
<td class="td4">last row</td>
<td class="td3">my bottom corners should be round</td>
</tr>
</table>
Have you tried this?
td
{
border-radious:0px;
}
Related
I've tried all the solutions I can find but the closest I can get to a uniform row height is editing the height of my table headers, the table data rows won't change their height, no matter what I change.
My HTML:
<div class="fields">
<table>
<tr>
<th>Year</th>
<th id="clickable" onclick="openPopup('f2')">Yield/Year</th>
<th id="clickable" onclick="openPopup('f3')">Yield/Year*3</th>
<th id="clickable" onclick="openPopup('f4')">Yield/Year*3*4</th>
</tr>
<tr>
<td>1</td>
<td>387.58</td>
<td>1162.74</td>
<td>4650.96</td>
</tr>
</table>
</div>
My CSS:
.fields table {
width: auto;
table-layout: fixed;
border-collapse: collapse;
white-space: nowrap;
}
.fields td {
font-family: Arial, sans-serif;
color: #213B54;
font-size: 16px;
border-right: 2px solid #213B54;
border-bottom: 2px solid #213B54;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
}
.fields th {
font-family: Arial, sans-serif;
font-size: 16px;
border-right: 2px solid #213B54;
border-bottom: 2px solid #213B54;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 2px;
padding-right: 2px;
text-align: center;
background-color: #9bdcdf;
color: #067A9F;
overflow: hidden;
text-overflow: ellipsis;
width: 75px;
height: 10px;
}
All you should have to do is write a style that targets tr, optionally with classes to differentiate between your header and data rows.
EDIT: By the way, I just noticed that you have the same ID on multiple elements. IDs should uniquely identify a single element. To apply styles to multiple elements, you should use classes.
table {
width: auto;
table-layout: fixed;
border-collapse: collapse;
white-space: nowrap;
}
td {
font-family: Arial, sans-serif;
color: #213B54;
font-size: 16px;
border-right: 2px solid #213B54;
border-bottom: 2px solid #213B54;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
}
th {
font-family: Arial, sans-serif;
font-size: 16px;
border-right: 2px solid #213B54;
border-bottom: 2px solid #213B54;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 2px;
padding-right: 2px;
text-align: center;
background-color: #9bdcdf;
color: #067A9F;
overflow: hidden;
text-overflow: ellipsis;
width: 75px;
height: 10px;
}
tr.table-header {
height: 50px;
}
tr.table-data {
height: 100px;
}
<table>
<tr class="table-header">
<th>Year</th>
<th id="clickable" onclick="openPopup('f2')">Yield/Year</th>
<th id="clickable" onclick="openPopup('f3')">Yield/Year*3</th>
<th id="clickable" onclick="openPopup('f4')">Yield/Year*3*4</th>
</tr>
<tr class="table-data">
<td>1</td>
<td>387.58</td>
<td>1162.74</td>
<td>4650.96</td>
</tr>
</table>
I have some text in a table cell in a table row that I'm trying to have the text span.
The text keeps on stopping in place.
This is what I currently have:
However this is what I want:
I want the text to span all way.
How would I implement this?
This is my code:
.normal-cell-styling-left-second {
width: 350px;
padding-top: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #E6E6E6;
}
.normal-cell-styling-middle-second {
width: 425px;
padding-left: 60px;
padding-top: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #E6E6E6;
}
.normal-cell-styling-right-second {
width: 700px;
padding-top: 20px;
padding-left: 200px;
padding-bottom: 20px;
border-bottom: 1px solid #E6E6E6;
}
.gray-dynamic {
display: inline-block;
background-color: #F6F8FA;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
border-radius: 4px;
margin-top: 5px;
margin-bottom: 5px;
font-weight: normal;
font-size: 16px;
font-family: 'PureHeadlineRegular', Sans-serif;
line-height: 19px;
color: #212121;
}
.image-placeholder5 {
display: inline-block;
width: 196px;
height: 36px;
background-color: #F1F1F1;
}
<table>
<tr>
<td className="normal-cell-styling-left-second">
<span class="gray-dynamic">
SHADOW_SPREAD_0
</span>
</td>
<td className="normal-cell-styling-middle-second">
0 0 0px 0 rgba(0,0,0,0.12) <br></br>0 0px 0px 0 rgba(0,0,0,0.24)
</td>
<td className="normal-cell-styling-right-second">
<div className="image-placeholder5"></div>
</td>
</tr>
<table>
Just put it in a span like your SHADOW_SPREAD
.normal-cell-styling-left-second {
width: 350px;
padding-top: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #E6E6E6;
}
.normal-cell-styling-middle-second {
width: 425px;
padding-left: 60px;
padding-top: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #E6E6E6;
}
.normal-cell-styling-right-second {
width: 700px;
padding-top: 20px;
padding-left: 200px;
padding-bottom: 20px;
border-bottom: 1px solid #E6E6E6;
}
.gray-dynamic {
display: inline-block;
background-color: #F6F8FA;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
border-radius: 4px;
margin-top: 5px;
margin-bottom: 5px;
font-weight: normal;
font-size: 16px;
font-family: 'PureHeadlineRegular', Sans-serif;
line-height: 19px;
color: #212121;
}
.image-placeholder5 {
display: inline-block;
width: 196px;
height: 36px;
background-color: #F1F1F1;
}
<table>
<tr>
<td className="normal-cell-styling-left-second">
<span class="gray-dynamic">
SHADOW_SPREAD_0
</span>
</td>
<td className="normal-cell-styling-middle-second">
<span class="gray-dynamic">
0 0 0px 0 rgba(0,0,0,0.12) <br>0 0px 0px 0 rgba(0,0,0,0.24)
</span>
</td>
<td className="normal-cell-styling-right-second">
<div className="image-placeholder5"></div>
</td>
</tr>
<table>
Modify the css
.table thead tr th td {
white-space:nowrap
}
Then use white-space-no-wrap in the table data style
<td style="white-space:nowrap;" className="normal-cell-styling-middle-second"> 0 0 0px 0 rgba(0,0,0,0.12) <br></br>0 0px 0px 0 rgba(0,0,0,0.24) </td>
Not sure, but it looks like there is a few things about table styling you are not familiar with :
vertical-align can be used on a cell to tell if the content is to centered, aligned on top or bottom without using padding or line-height for an average alignment. https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align (look farther down about table cells )
border-collapse or border-spacing can be used to avoid gaps in between cells border. see https://developer.mozilla.org/en-US/docs/Web/CSS/border-collapse & https://developer.mozilla.org/en-US/docs/Web/CSS/border-spacing might look similar but involves different behavior when drawing borders on a table.
table-layout:fixed can be used to set a fixed width to the table and the cells so they do not shrink/expand anymore. ( height cannot be set on a fixed value, table will not show scrollbars) this is the one thing to know about the table (or display:table / table-cell / ... properties) rendering behavior.
white-space can be used anywhere and you might know more about it https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
Here is a snippet that could be closer to what you expect, do not hesitate to clarify your needs and misunderstandings of myself.
table{
border-spacing:0;/* or border-collapse:collapse; */
}
.normal-cell-styling-left-second {
width: 350px;
border-bottom: 1px solid ;
vertical-align:top;
}
.normal-cell-styling-middle-second {
width: 425px;
padding-left: 60px;/* needed ?*/
border-bottom: 1px solid ;
white-space:nowrap;
}
.normal-cell-styling-right-second {
border-bottom: 1px solid ;
}
.gray-dynamic {
display: inline-block;
background-color: #F6F8FA;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
border-radius: 4px;
margin-top: 5px;
margin-bottom: 5px;
font-weight: normal;
font-size: 16px;
font-family: 'PureHeadlineRegular', Sans-serif;
line-height: 19px;
color: #212121;
}
.image-placeholder5 {
display: inline-block;
width: 196px;
height: 36px;
background-color: #F1F1F1;
}
<table>
<tr>
<td class="normal-cell-styling-left-second">
<span class="gray-dynamic">
SHADOW_SPREAD_0
</span>
</td>
<td class="normal-cell-styling-middle-second">
0 0 0px 0 rgba(0,0,0,0.12) <br>0 0px 0px 0 rgba(0,0,0,0.24)
</td>
<td class="normal-cell-styling-right-second">
<div class="image-placeholder5"></div>
</td>
</tr>
<table>
I'm trying to style a table using only SASS/CSS. I've set the width of my table to be 100%. However, when I set the font-size of the th element to 0.8em, My table fails to take all of the width it's allowed (Notice that the columns do not reach the border line on the right). How can I fix this using CSS, given that I don't control the HTML?
SASS/CSS
table {
color: black;
background-color: white;
border-color: black;
border-style: solid;
border-width: 0 1px 1px 1px;
border-radius: 5px;
border-collapse: collapse;
border-spacing: 0;
display: block;
overflow: auto;
width: 100%;
thead {
th {
color: white;
background-color: black;
font-weight: bold;
font-size: 0.8em;
padding: 5px 10px;
vertical-align: bottom;
}
th:first-child {
border-top-left-radius: 5px;
}
th:last-child {
border-top-right-radius: 5px;
}
}
tbody {
td {
border-top: 1px solid gray;
padding: 5px 10px;
vertical-align: top;
}
tr:nth-child(2n) {
background-color: lightgray;
}
}
}
<table>
<thead>
<tr>
<th>Method</th>
<th>Runtime</th>
<th align="right">Mean</th>
<th align="right">Ratio</th>
<th align="right">Gen 0/1k Op</th>
<th align="right">Allocated Memory/Op</th>
</tr>
</thead>
<tbody>
<tr>
<td>Baseline</td>
<td>Clr</td>
<td align="right">1.833 us</td>
<td align="right">1.00</td>
<td align="right">2.0542</td>
<td align="right">6.31 KB</td>
</tr>
</tbody>
</table>
Here is what I think you want, I just removed border-collapse, display:block (this make the table default CSS), here is a codepen with SCSS and a working snippet is here too:
table {
color: black;
background-color: white;
border-color: black;
border-style: solid;
border-width: 0 1px 1px 1px;
border-radius: 5px;
border-collapse: separte;
border-spacing: 0;
display: table;
overflow: auto;
width: 100%;
}
table thead th {
color: white;
background-color: black;
font-weight: bold;
font-size: 0.8em;
padding: 5px 10px;
vertical-align: bottom;
}
table thead th:first-child {
border-top-left-radius: 5px;
}
table thead th:last-child {
border-top-right-radius: 5px;
}
table tbody td {
border-top: 1px solid gray;
padding: 5px 10px;
vertical-align: top;
}
table tbody tr:nth-child(2n) {
background-color: lightgray;
}
<table>
<thead>
<tr>
<th>Method</th>
<th>Runtime</th>
<th align="right">Mean</th>
<th align="right">Ratio</th>
<th align="right">Gen 0/1k Op</th>
<th align="right">Allocated Memory/Op</th>
</tr>
</thead>
<tbody>
<tr>
<td>Baseline</td>
<td>Clr</td>
<td align="right">1.833 us</td>
<td align="right">1.00</td>
<td align="right">2.0542</td>
<td align="right">6.31 KB</td>
</tr>
</tbody>
</table>
remove display:block from table
#container,tr{
width:100%;
}
html,body{
width:100%;
}
#container{
border-radius:15px;
background-color:black;
}
table {
color: black;
background-color: white;
border-color: black;
border-style: solid;
border-width: 0 1px 1px 1px;
border-radius: 5px;
border-collapse: collapse;
border-spacing: 0;
overflow: auto;
width: 98%;
margin:0 auto;
}
th {
color: white;
background-color: black;
font-weight: bold;
font-size: 0.8em;
padding: 5px 10px;
vertical-align: bottom;
}
th:first-child {
border-top-left-radius: 5px;
}
th:last-child {
border-top-right-radius: 5px;
}
td {
border-top: 1px solid gray;
padding: 5px 10px;
vertical-align: top;
}
tr:nth-child(2n) {
background-color: lightgray;
}
<html>
<body>
<div id='container'>
<table>
<thead>
<tr>
<th>Method</th>
<th>Runtime</th>
<th align="right">Mean</th>
<th align="right">Ratio</th>
<th align="right">Gen 0/1k Op</th>
<th align="right">Allocated Memory/Op</th>
</tr>
</thead>
<tbody>
<tr>
<td>Baseline</td>
<td>Clr</td>
<td align="right">1.833 us</td>
<td align="right">1.00</td>
<td align="right">2.0542</td>
<td align="right">6.31 KB</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
I want to get rid of the horizontal line in the middle. Basically, I want the table to have the outer borders and a vertical divider in the middle. How do I achieve this?
JS Fiddle - https://jsfiddle.net/kac69ovn/
table {
width: 85%;
border-collapse: collapse;
margin-left: 4%;
border: 1px solid black;
}
th {
text-align: left;
width: 50%;
border: 1px solid black;
padding: 5px 11px;
}
td {
text-align: left;
width: 50%;
border: 1px solid black;
padding: 5px 11px;
}
<table>
<tbody>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Lorem Ipsum is simply dummy text of the printing and </td>
<td>It is a long established fact that a </td>
</tr>
</tbody>
</table>
Thanks in advance!
Keep the full border on your table, but stick to border-left and border-right for your th and td elements.
table {
width: 85%;
border-collapse: collapse;
margin-left: 4%;
border: 1px solid black;
}
th, td {
text-align: left;
width: 50%;
border-right: 1px solid black;
border-left: 1px solid black;
padding: 5px 11px;
}
<table>
<tbody>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Lorem Ipsum is simply dummy text of the printing and </td>
<td>It is a long established fact that a </td>
</tr>
</tbody>
</table>
You can fiddle with the borders:
Set border-top: none for the tds
Set border-bottom: none for the th
Add this to prevent horizontal line when there are multiple trs:
tr:not(:last-child) td {
border-bottom: none;
}
See demo below:
table {
width: 85%;
border-collapse: collapse;
margin-left: 4%;
/*border: 1px solid black;*/
}
th {
text-align: left;
width: 50%;
border: 1px solid black;
border-bottom: none; /* ADDED */
padding: 5px 11px;
}
td {
text-align: left;
width: 50%;
border: 1px solid black;
border-top: none; /* ADDED */
padding: 5px 11px;
}
tr:not(:last-child) td { /* ADDED */
border-bottom: none;
}
<table>
<tbody>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Lorem Ipsum is simply dummy text of the printing and </td>
<td>It is a long established fact that a </td>
</tr>
<tr>
<td>Lorem Ipsum is simply dummy text of the printing and </td>
<td>It is a long established fact that a </td>
</tr>
</tbody>
</table>
th, td {border: none; border-right: 1px solid black;}
I think this is what your looking for:
table {
width: 85%;
border-collapse: collapse;
margin-left: 4%;
border: 1px solid black;
}
th {
text-align: left;
width: 50%;
border: 1px solid black;
padding: 5px 11px;
border-bottom: None;
}
td {
text-align: left;
width: 50%;
border: 1px solid black;
padding: 5px 11px;
border-top: None;
}
updated
https://jsfiddle.net/kac69ovn/1/
table {
width: 85%;
border-collapse: collapse;
margin-left: 4%;
border: 1px solid black;
}
th {
text-align: left;
width: 50%;
border-right: 1px solid black;
padding: 5px 11px;
}
td {
text-align: left;
width: 50%;
border-right: 1px solid black;
padding: 5px 11px;
}
I have a simple table using tr:nth-child(odd) to alternate background for rows in a table.
HTML
/*-----------#602 SAO Styles-----------------------------*/
/*---------SAO Global------------*/
.sao-pricing-table table {
border-collapse: collapse;
width: 80%;
margin: 0 auto;
background: #ffffff;
}
.sao-pricing-table table td {
height: 20px;
}
table.sao-table {
border-collapse: collapse;
}
/*-----Basic Title Cells---------*/
.sao-top-1 {
border: 0px;
background: #FFFFFF;
height: 40px;
width: 40%;
}
.sao-top-2 {
font-size: 16px;
text-shadow: 2px 4px 3px rgba(0, 0, 0, 0.3);
color: #FFFFFF;
border: 0px solid #a8b5b9;
background-color: #003869;
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
height: 40px;
width: 30%;
}
.sao-top-2-title {
font-size: 110%;
}
.sao-top-2-type {
font-size: 120%;
}
.sao-top-2-price {
font-size: 100%;
}
/*------Gold Title Cells------*/
.sao-top-3 {
font-size: 16px;
text-shadow: 2px 4px 3px rgba(0, 0, 0, 0.3);
color: #FFFFFF;
border: 0px solid #a8b5b9;
background-color: #F2A405;
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
height: ;
width: 30%;
}
.sao-top-3-title {
font-size: 110%;
}
.sao-top-3-type {
font-size: 130%;
}
.sao-top-3-price {
font-size: 100%;
}
/*----Regular Cells-----*/
#sao-table table {
border-collapse: collapse;
width: 100%;
}
th,
td {
padding: 0.25rem;
text-align: center !important;
border: 1px solid #ccc;
height: 20%;
}
tr.sao-zebra:nth-child(odd) {
background: #23282D !important;
}
.sao-feature {
text-align: left !important;
}
/* Checkmark Style-----*/
.sao-checkmark {
font-size: 125%;
color: #F2A405;
text-shadow: 2px 4px 3px rgba(0, 0, 0, 0.2);
}
<div class="sao-pricing-table">
<table class="sao-table">
<thead>
<tr>
<th class="sao-top-1">
</th>
<th class="sao-top-2">
<span class="sao-top-2-title">Some Text</span>
<span class="sao-top-2-type">More Text</span>
<span class="sao-top-2-price">Even More Text</span>
</th>
<th class="sao-top-3">
<span class="sao-top-3-title">Some Text</span>
<span class="sao-top-3-type">More Text</span>
<span class="sao-top-3-price">Even More Text</span>
</th>
</tr>
</thead>
<tbody>
<tr>
<th class="sao-feature">Text</th>
<td class="sao-detail">Text</td>
<td class="sao-detail">Text</td>
</tr>
<tr>
<th class="sao-feature">Text</th>
<td class="sao-detail">Text</td>
<td class="sao-detail">Text</td>
</tr>
as is stands, the table has 3 columns. The nth-child pseudo selector is causing every other column to be black, not every other row. What have I done wrong? Edit: the example for row span that was suggested doesn't include the nth-child selector so I'm failing to see how its the same. Can someone fill me in?
You have a space in your selector where there shouldn't be one, just before :nth-child
tr.sao-zebra:nth-child(odd) {
background: #23282D;
}