Is there a way to expand bootstrap card dynamically? - html

So I have table inside bootstrap card:
<div class="card col-5">
<div class="card-body">
<div class="table-view">
<div class="box table fixed-table-body">
<table id="request_data"
class="dataTable no-footer table table-hover table-border" role="grid" style="overflow: visible;">
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
</thead>
</table>
</div>
</div>
The table fits into the card but when the screen is resized the table should fit into the card but it expands out, I tried writing #media QUERIES but nothing is working, if someone could please help out.
Thankyou.

There should be a table-responsive class available in Bootstrap that you can use on a wrapping element around the table.
You could try something like this in your code:
<div class="table-responsive">
<table id="request_data"
class="dataTable no-footer table table-hover table-border" role="grid" style="overflow: visible;">
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
</thead>
</table>
</div>
Here's some more information about it:
https://getbootstrap.com/docs/5.0/content/tables/

You would have to make the tables responsive via viewports, I have added css for your reference. However, the codepen links below have the working code:
table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
table caption {
font-size: 1.5em;
margin: .5em 0 .75em;
}
table tr {
background-color: #f8f8f8;
border: 1px solid #ddd;
padding: .35em;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 0;
}
table caption {
font-size: 1.3em;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: .625em;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: .8em;
text-align: right;
}
table td::before {
/*
* aria-label has no advantage, it won't be read inside a table
content: attr(aria-label);
*/
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
border-bottom: 0;
}
}
Some useful resources are as follows:
https://codepen.io/AllThingsSmitty/pen/MyqmdM
https://codepen.io/ismailbaskin/pen/KgAGRr
https://codepen.io/MartijnCuppens/pen/JMyOgv
Ps. Please note that these are for references only and is not my piece of work.

Related

table header colspan fix location scrollable

I'm having the issue where my colspan header is going behind my default header when I scroll down on my table. How do I fix this?
Also, it appears that on page load, the top of the scroll bar is higher than the top of the table, so when I scroll down the whole table moves up a bit. Not sure why that is.
I've attached some images down below. (P.S. This is for intro to web dev class, keep it simple if you can).
.opendata {
overflow: hidden;
overflow-y: scroll;
height: 500px;
font-size: 14px;
}
.sticky-header {
position: sticky;
top: 0;
border: 1px solid #000000;
}
table {
border-collapse: separate;
border-spacing: 0;
margin-left: auto;
margin-right: auto;
width: auto;
}
th,
td {
padding: 8px 15px;
border: 1px solid #000000;
}
th {
background: #a0a0a0;
}
td {
background: #e0e0e0;
}
<div class="opendata">
<table id='table'>
<thead>
<tr class="sticky-header">
<th colspan="4" style="font-size: x-large; color: white; text-align: center; background: rgb(6, 60, 122);">
E V I C T I O N S</th>
</tr>
<tr class="sticky-header">
<th>Date</th>
<th>Address</th>
<th>Borough</th>
<th>Zip Code</th>
</tr>
</thead>
<tbody>
</div>

How to create Responsive HTML, CSS table?

I want to create a responsive table only with HTML & CSS that has a icon button aligned to right side when on responsive view as similar to the bellow image. The bellow code renders a responsive table, however the icon is also aligned on the next line. I want it to be aligned on right side as in image. any one Please help on this.
table {
border: 1px solid #ccc;
border-radius: 5px;
/* border-collapse: collapse; */
margin: 0;
padding: 0;
width: 50%;
table-layout: fixed;
}
table tr {
background-color: white;
border: 1px solid #ddd;
padding: 10px;
}
table th,
table td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}
table th {
font-size: 15px;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 0;
width: 100%
}
table thead {
border: none;
/* clip: rect(0 0 0 0); */
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 1px solid #ddd;
display: block;
/* margin-bottom: .625em; */
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: 13px;
text-align: right;
}
table td::before {
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
border-bottom: 0;
}
}
<table>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Type</th>
<th scope="col">Upload Date</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Name">John</td>
<td data-label="Type">file</td>
<td data-label="Upload Date">21/04/20</td>
<td class="dropdown">
<p><a id="" class="ti-more-alt"></a></p>
<div class="dropdown-content">
View
</div>
</td>
</tr>
<tr>
<td data-label="Name">John</td>
<td data-label="Type">file</td>
<td data-label="Upload Date">21/04/20</td>
<td class="dropdown">
<p><a id="" class="ti-more-alt"></a></p>
<div class="dropdown-content">
View
</div>
</td>
</tr>
<tr>
<td data-label="Name">John</td>
<td data-label="Type">file</td>
<td data-label="Upload Date">21/04/20</td>
<td class="dropdown">
<p><a id="" class="ti-more-alt"></a></p>
<div class="dropdown-content">
View
</div>
</td>
</tr>
</tbody>
</table>

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.

Responsive table, unable to line up thead and tbody

I have created a table however I cannot get the <thead>s to line up with the <tbody>s.
The table is responsive and works as I want it to when resized, however it's the initial screen size that is the issue.
I have added float:left to the <thead>s so they align properly instead of overlapping each other and would like the table data to a-line in the same way.
table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
table caption {
font-size: 1.5em;
margin: .5em 0 .75em;
}
table tr {
background: #f8f8f8;
border: 1px solid #ddd;
padding: .35em;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table td {
font-size: 0.60em;
}
table th {
font-size: .60em;
letter-spacing: .1em;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 0;
}
table caption {
font-size: 1.3em;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: .625em;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: .8em;
text-align: right;
}
table td:before {
/*
* aria-label has no advantage, it won't be read inside a table
content: attr(aria-label);
*/
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
border-bottom: 0;
}
#table-wrapper {
position: relative;
}
#table-scroll {
overflow: auto;
}
#table-wrapper table {
width: 100%;
}
#table-wrapper table * {
color: black;
font-size: 12px;
}
#table-wrapper table thead th .text {
text-align: center;
}
}
<div class="col-12 offset-0">
<div style="overflow-x:auto">
<div id="table-wrapper">
<div id="table-scroll">
<table class="table table-striped" border="0" cellspacing="0" cellpadding="0" align="center">
<h4>Success Stream</h4>
<thead style="float:left">
<tr>
<th scope="col">Year</th>
<th scope="col">{{n1}}'s age</th>
<th scope="col">{{n2}}'s age</th>
<th scope="col">Income</th>
<th scope="col">Personal Contribution to Pension</th>
<th scope="col">Company Contribution to Pension</th>
<th scope="col">Personal Contribution to ISA</th>
<th scope="col">Expenses</th>
<th scope="col">Cash Flow</th>
<th scope="col">Growth of Pension</th>
<th scope="col">Growth of ISA</th>
<th scope="col">Growth of Other</th>
<th scope="col">Withdrawals from Pension</th>
<th scope="col">Withdrawals from ISA</th>
<th scope="col">Withdrawals from Other</th>
<th scope="col">Pension Total</th>
<th scope="col">ISA Total</th>
<th scope="col">Other Total</th>
<th scope="col">Full Total</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Year"> 2018</td>
<td data-label="{{n1}}'s age">55</td>
<td data-label="{{n2}}'s age">55</td>
<td data-label="Income">57,000</td>
<td data-label="Personal Contribution to Pension">5,000</td>
<td data-label="Company Contribution to Pension">0</td>
<td data-label="Personal Contribution to ISA">0</td>
<td data-label="Expenses">50,500</td>
<td data-label="Cash Flow">1,500</td>
<td data-label="Growth of Pension">57,737</td>
<td data-label="Growth of ISA">0</td>
<td data-label="Growth of Other">0</td>
<td data-label="Withdrawals from Pension">0</td>
<td data-label="Withdrawals from ISA">0</td>
<td data-label="Withdrawals from Other">0</td>
<td data-label="Pension Total">862,737</td>
<td data-label="ISA Total">1</td>
<td data-label="Other Total">1,501</td>
<td data-label="Full Total">864,239</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Instead of using float:left for thead just change
table {
table-layout: fixed;
}
to
table {
table-layout: auto;
}

Ionic Framework responsive table with data attribute not working as expected

I am trying to achieve a responsive table for mobile using ionic framework. I am using the example from here (codepen) as of the codes below too
HTML
<table>
<thead>
<tr>
<th>Payment</th>
<th>Issue Date</th>
<th>Amount</th>
<th>Period</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Payment">Payment #1</td>
<td data-label="Issue Date">02/01/2015</td>
<td data-label="Amount">$2,311</td>
<td data-label="Period">01/01/2015 - 01/31/2015</td>
</tr>
<tr>
<td data-label="Payment">Payment #2</td>
<td data-label="Issue Date">03/01/2015</td>
<td data-label="Amount">$3,211</td>
<td data-label="Period">02/01/2015 - 02/28/2015</td>
</tr>
</tbody>
</table>
CSS
body {
font-family: arial;
}
table {
border: 1px solid #ccc;
width: 100%;
margin:0;
padding:0;
border-collapse: collapse;
border-spacing: 0;
}
table tr {
border: 1px solid #ddd;
padding: 5px;
}
table th, table td {
padding: 10px;
text-align: center;
}
table th {
text-transform: uppercase;
font-size: 14px;
letter-spacing: 1px;
}
#media screen and (max-width: 600px) {
table {
border: 0;
}
table thead {
display: none;
}
table tr {
margin-bottom: 10px;
display: block;
border-bottom: 2px solid #ddd;
}
table td {
display: block;
text-align: right;
font-size: 13px;
border-bottom: 1px dotted #ccc;
}
table td:last-child {
border-bottom: 0;
}
table td:before {
content: attr(data-label);
float: left;
text-transform: uppercase;
font-weight: bold;
}
}
I have tested this example previously using Onsen Hybrid Framework and also on a normal website, when the max-width of the browser or the mobile screen is below 600px, it will should be as the picture below
but what really happened with mine when using ionicframework is as below which are not aligned as it should be
The code used is exactly the same for both pictures with the codepen link given above. Am I missing something here which made it like this?
Note: If ever there is an alternative to this problem, i don't mind converting if it works.