I can't apply a round border on table cells - html

I'm building a very basic test website in HTML, and I'm learning how to put borders on table cells. I have a problem, I'm trying to round the borders in my table but I just get rounded cells (td and th), but not the table itself.
table,
th,
td {
text-align: center;
width: 30%;
border: 5px solid aqua;
border-collapse: collapse;
border-radius: 45px;
font-family: arial;
padding: 11px;
}
th {
color: white;
font-family: impact;
}
td {
color: yellow;
}
tr:nth-child(odd) {
background-color: darkblue;
}
<table align=c enter>
<tr>
<th>Choncho</th>
<th>Klokin</th>
<th>Fetuc</th>
</tr>
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>papas</td>
<td>refrescos</td>
<td>tingas</td>
</tr>
</table>
I even tried doing the following to see if there were any changes:
table {
border-radius: 45px;
}
the,
td {
text-align: center;
width: 30%;
border: 5px solid aqua;
font-family: arial;
padding: 11px;
}
But all the borders remain squares.

I think that has something to do with collapsing the border.
Try to remove this line
border-collapse: collapse;
table,
th,
td {
text-align: center;
width: 30%;
border: 5px solid aqua;
/* border-collapse: collapse; *//* remove this line */
border-radius: 45px;
font-family: arial;
padding: 11px;
}
th {
color: white;
font-family: impact;
}
td {
color: yellow;
}
tr:nth-child(odd) {
background-color: darkblue;
}
<table align=c enter>
<tr>
<th>Choncho</th>
<th>Klokin</th>
<th>Fetuc</th>
</tr>
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>papas</td>
<td>refrescos</td>
<td>tingas</td>
</tr>
</table>
Then use padding and margin to control the spacing if needed

Related

Trying to change background color of first column in table

Trying to use power automate to create tables and add styling to them in the body of an email. The last part of my project involves getting the first column of the table (name column) to have an orange background but I cannot seem to get the CSS working for this.
Style sheet:
<style>
table{
border: 2px solid #C1C1C1;
background-color: #FFFFFF;
width: 400px;
text-align: center;
border-collapse: collapse;
}
table td, th {
border: 1px solid #555555;
padding: 5px 10px;
}
table tbody td {
font-size: 12px;
font-weight: bold;
color: #000000;
}
table thead {
background: #737373;
}
table thead th {
font-size: 15px;
font-weight: bold;
color: #FFFFFF;
text-align: center;
}
table tr td:nth-child(1)
{
background-color: orange;
}
</style>
HTML output from PowerBI's HTML table action:
<table>
<thead>
<tr>
<th></th>
<th>Sunday^10/30/2022</th>
<th>Monday^10/31/2022</th>
<th>Tuesday^11/1/2022</th>
<th>Wednesday^11/2/2022</th>
<th>Thursday^11/3/2022</th>
th>Friday^11/4/2022</th>
<th>Saturday^11/5/2022</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td> <-- this column needs to be orange
<td>Rest Day</td>
<td>Vacation</td>
<td>Vacation</td>
<td>Office</td>
<td>Remote</td>
<td>Office</td>
<td>Rest Day</td>
</tr>
</tbody>
</table>
You can try something like this:
table {
border: 2px solid #C1C1C1;
background-color: #FFFFFF;
width: 400px;
text-align: center;
border-collapse: collapse;
}
table td,
th {
border: 1px solid #555555;
padding: 5px 10px;
}
table tbody td {
font-size: 12px;
font-weight: bold;
color: #000000;
}
table thead {
background: #737373;
}
table thead th {
font-size: 15px;
font-weight: bold;
color: #FFFFFF;
text-align: center;
}
tbody tr td:first-child {
background-color: orange;
}
<table>
<thead>
<tr>
<th></th>
<th>Sunday^10/30/2022</th>
<th>Monday^10/31/2022</th>
<th>Tuesday^11/1/2022</th>
<th>Wednesday^11/2/2022</th>
<th>Thursday^11/3/2022</th>
<th>Friday^11/4/2022</th>
<th>Saturday^11/5/2022</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>Rest Day</td>
<td>Vacation</td>
<td>Vacation</td>
<td>Office</td>
<td>Remote</td>
<td>Office</td>
<td>Rest Day</td>
</tr>
</tbody>
</table>
So you can use the nth-child, this is gonna be helpful
https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child?retiredLocale=de

How can I make a button and textbox elements inside the table cell to get the full height?

I have table and inside this table button and textbox.
Here the code:
#dvStockCard{
border-style: solid;
border-width: thin;
padding: 12px 5px 5px 5px;
}
.title {
font-size: small;
border-top: 2px solid #686868;
color:#383838;
padding: 8px calc(100% - 10ch) 0px 0px;
}
/*----table styles----*/
#dvStockCard table{
font-family: sans-serif;
font-weight: 600;
border-collapse: collapse;
width: 100%;
font-size: x-small;
}
#dvStockCard table tr{
border-bottom: 2px solid lightgray;
color: #707070;
}
#dvStockCard table td {
padding: 8px;
}
#dvStockCard table tr td:nth-child(2) {
text-align: right;
}
/*------values styles------*/
.val{
font-size: small;
color: black;
}
#lastPrice{
font-family: 'Palatino Linotype';
font-size: 160%;
color:black;
}
#change{
font-family: 'Palatino Linotype';
font-size: 160%;
color:green;
}
.halfWidth{
position: relative;;
width:50%;
}
/*-------helpers styles--------*/
.spaceTop-10{
margin-top:10px
}
.spaceBottom-10{
margin-bottom:10px
}
.fullWidth{
width:100%;
}
.fullHeight{
height:100%;
}
<div id="dvStockCard">
<div class="title spaceBottom-10">My data cart</div>
<table>
<tr>
<td id="lastPrice">no price</td>
<td id="change">1234324t</td>
</tr>
<tr>
<td>Range</td>
<td id="range" class="val">No Rnge</td>
</tr>
<tr>
<td>Open</td>
<td id="open" class="val">555</td>
</tr>
<tr>
<td>Volume</td>
<td id="volume" class="val">DM</td>
</tr>
<tr>
<td>Market Cap</td>
<td id="marketCap" class="val">Non</td>
</tr>
<tr>
<td></td>
<td id="timestamp">As of 12:00 AM</td>
</tr>
<tr>
<td style="width:50%;"><input type="text" class="fullWidth fullHeight"></td>
<td style="width:50%"><input type="button" value="Get" class="fullWidth fullHeight"></td>
</tr>
</table>
</div>
My question is how can I make a button and textbox inside the table cell in the table above to get the full height of the row(I tried height:100%)?
Couple of things:
You have already defined 8px of padding under #dvStockCard table td{...} that's why you had default padding for all. Considering you need that padding I have overridden the td padding for last row.
Use border-collapse: collapse; for the row and padding & margin to 0 for td. Now you can use your desired height for that row.
#dvStockCard {
border-style: solid;
border-width: thin;
padding: 12px 5px 5px 5px;
}
.title {
font-size: small;
border-top: 2px solid #686868;
color: #383838;
padding: 8px calc(100% - 10ch) 0px 0px;
}
/*----table styles----*/
#dvStockCard table {
font-family: sans-serif;
font-weight: 600;
border-collapse: collapse;
width: 100%;
font-size: x-small;
}
#dvStockCard table tr {
border-bottom: 2px solid lightgray;
color: #707070;
}
#dvStockCard table td {
padding: 8px;
}
#dvStockCard table tr td:nth-child(2) {
text-align: right;
}
/*------values styles------*/
.val {
font-size: small;
color: black;
}
#lastPrice {
font-family: 'Palatino Linotype';
font-size: 160%;
color: black;
}
#change {
font-family: 'Palatino Linotype';
font-size: 160%;
color: green;
}
.halfWidth {
position: relative;
;
width: 50%;
}
/*-------helpers styles--------*/
.spaceTop-10 {
margin-top: 10px
}
.spaceBottom-10 {
margin-bottom: 10px
}
.trClass {
border-collapse: collapse;
}
.trClass td {
height: 40px;
padding: 0 !important;
/* need this because you already used 8px to the td*/
margin: 0 !important;
/* need this because you already used 8px to the td*/
}
.fullWidth {
width: 100%;
}
.fullHeight {
height: 100%;
}
<div id="dvStockCard">
<div class="title spaceBottom-10">My data cart</div>
<table>
<tr>
<td id="lastPrice">no price</td>
<td id="change">1234324t</td>
</tr>
<tr>
<td>Range</td>
<td id="range" class="val">No Rnge</td>
</tr>
<tr>
<td>Open</td>
<td id="open" class="val">555</td>
</tr>
<tr>
<td>Volume</td>
<td id="volume" class="val">DM</td>
</tr>
<tr>
<td>Market Cap</td>
<td id="marketCap" class="val">Non</td>
</tr>
<tr>
<td></td>
<td id="timestamp">As of 12:00 AM</td>
</tr>
<tr class="trClass">
<td style="width:50%;"><input type="text" class="fullWidth fullHeight"></td>
<td style="width:50%"><input type="button" value="Get" class="fullWidth fullHeight"></td>
</tr>
</table>
</div>
You could try wrapping it up in a container and later set it to 100% height. If not, you could try setting the height in px, you go trying different measurements until you see which one fills your desire. I hope I could help you

Table not being styled properly

I've got a table that I'm trying to style. I wanted to have a bottom-border underneath the thead and each tr but no matter what I put, it just won't apply. I even tried setting a color for the thead but that wouldn't give either. Any ideas what I'm doing wrong?
.border-bottom {
border-collapse: collapse;
border-bottom: 2px solid #CCD5DE;
}
table {
width: 100%;
max-height: 500px;
overflow: scroll;
}
thead {
color: red;
}
th {
font-weight: 700;
font-size: 20px;
letter-spacing: 1px;
text-align: left;
padding-top: 20px;
padding-bottom: 20px;
}
td {
font-weight: 400;
font-size: 18px;
letter-spacing: .75px;
text-align: left;
padding-top: 20px;
padding-bottom: 20px;
}
<div class="spaced-div">
<table>
<thead class="bottom-border">
<tr>
<th>Date</th>
<th>Stock</th>
<th>Quantity</th>
<th>Price</th>
<th>Fees</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
<tr class="border-bottom">
<td>March 21, 2020</td>
<td>DMC</td>
<td>1,330</td>
<td>5.71</td>
<td>23.54</td>
<td>7,617.84</td>
</tr>
</tbody>
</table>
</div>
There are two major issues here,
1) Css property border-collapse: collapse; should be under table element like,
table {
width: 100%;
max-height: 500px;
overflow: scroll;
border-collapse: collapse;
}
2) Make sure you are having the same class name .border-bottom for both thead and tbody tr .
.border-bottom {
border-bottom: 2px solid #CCD5DE;
}
table {
width: 100%;
max-height: 500px;
overflow: scroll;
border-collapse: collapse;
}
thead {
color: red;
}
th {
font-weight: 700;
font-size: 20px;
letter-spacing: 1px;
text-align: left;
padding-top: 20px;
padding-bottom: 20px;
}
td {
font-weight: 400;
font-size: 18px;
letter-spacing: .75px;
text-align: left;
padding-top: 20px;
padding-bottom: 20px;
}
<div class="spaced-div">
<table>
<thead>
<tr class="border-bottom">
<th>Date</th>
<th>Stock</th>
<th>Quantity</th>
<th>Price</th>
<th>Fees</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
<tr class="border-bottom">
<td>March 21, 2020</td>
<td>DMC</td>
<td>1,330</td>
<td>5.71</td>
<td>23.54</td>
<td>7,617.84</td>
</tr>
</tbody>
</table>
</div>

How to fix gap on HTML table with rounded corners?

I have no access to change core HTML, only CSS, but the tables I am working with have a weird gap in the corners that I am trying to fix.
.tabular-container {
border: 2px solid #0093c9;
border-radius: 8px;
overflow: hidden;
box-sizing: border-box;
}
.heading-row {
background: #0093c9;
font-weight: bold;
}
table {
font-family: Arial;
width: 100%;
border-collapse: collapse;
background: white;
overflow-x: hidden;
}
th,
td {
padding: 10px;
text-align: left;
}
<div class="tabular-container">
<table class="">
<thead class="">
<tr class="heading-row">
<th colspan="2">Rounded corners table</th>
</tr>
</thead>
<tbody>
<tr class="tabular__row">
<td>kk</td>
<td>kk</td>
</tr>
<tr class="tabular__row">
<td colspan="2">This is a sample table only</td>
</tr>
</tbody>
</table>
</div>
Does turning the whole table and div background into the color and the tbody back to white do the trick?
.tabular-container {
background: #0093c9;
}
table {
font-family: Arial;
width: 100%;
border-collapse: collapse;
background: white;
overflow-x: hidden;
background: #0093c9;
}
tbody{
background: white;
}
.tabular-container {
border: 2px solid #0093c9;
border-radius: 8px;
overflow: hidden;
box-sizing: border-box;
background: #0093c9;
}
.heading-row th{
font-weight: bold;
}
table {
font-family: Arial;
width: 100%;
border-collapse: collapse;
background: white;
overflow-x: hidden;
background: #0093c9;
}
th,
td {
padding: 10px;
text-align: left;
}
tbody{
background: white;
}
<div class="tabular-container">
<table class="">
<thead class="">
<tr class="heading-row">
<th colspan="2">Rounded corners table</th>
</tr>
</thead>
<tbody>
<tr class="tabular__row">
<td>kk</td>
<td>kk</td>
</tr>
<tr class="tabular__row">
<td colspan="2">This is a sample table only</td>
</tr>
</tbody>
</table>
</div>
Simple, set: border-radius:0; on your table.
The browser is trying to set the radius of the table's corners to match, but is getting a rounding error. By using radius:0 you are forcing the browser to 'clip' the corner instead.

Border color + font color in HTML?

How should I give color to a table tr along with a separate border color.
Here is my class properties in style.css.
table tr {
background: #9a9a9a;
border-color: #000000;
font-size: 21px;
color: #fff;
font-weight: bold;
}
<table>
<tr>
<td>Cell1</td>
<td>Cell2</td>
</tr>
</table>
I need to give black color to the border and font color as white with background color as dark grey.
How to do this?
You need to apply border on td
tr td {
background: #9a9a9a;
border:1px solid #000000;
font-size: 21px;
color: #fff;
font-weight: bold;
}
border will apply from all 4 sides. you can change border sides with
border-top, border-bottom, border-left, border-right
Border is not allowed for table rows, but only for whole tables or table cells. However, you can use the outline property to draw a border. It only doesn't count towards the box model and you cannot set individual sides in terms of color, style or width.
To select a specific row, use a pseudo-class on the tr.
td {
padding: 1em 2em;
}
tr:hover {
background: #666;
outline: 1px solid black;
color: white;
}
<table cellspacing="0">
<tr><td>1</td><td>2</td></tr>
<tr><td>3</td><td>4</td></tr>
</table>
#table {
border-collapse: collapse;
border-spacing: 0;
text-align: center;
width: 100%;
}
#table th {
text-transform: uppercase;
font-family: Helvetica;
font-weight: bold;
border-bottom: 2px solid #107DBA;
padding-bottom: 5px;
}
#table tr:nth-child(even) {
background: #e7e7e7;
border-bottom: 4px solid #ccc;
}
#table td {
padding: 9px 2px;
text-transform: capitalize;
font-size: 15px;
font-family: Tahoma;
}
<table id="table">
<tr>
<th>firstname</th>
<th>lastname</th>
</tr>
<tr>
<td>john</td>
<td>doe</td>
</tr>
<tr>
<td>sara</td>
<td>cein</td>
</tr>
<tr>
<td>hamid</td>
<td>hagh</td>
</tr>
<tr>
<td>maryam</td>
<td>temori</td>
</tr>
</table>