Responsive table issue when html and body displayed as table - css

I'm in the middle of finishing off a responsive table for a website I'm building. The problem is that because of the html and body elements being displayed as table (due to being part of a sticky footer solution), the width of the tables containing div is not respecting the 100% width, when scaled down below 745px. Removing the display table from the html and body elements isn't an option due to the sticky footer. I would love to hear if anyone in the community has come across this issue and more importantly managed to find a solution/workaround?
See the link below to a pen with the table in question:
Codepen example
HTML:
<div id="opening-hours">
<div class="opening-inner">
<table>
<thead>
<tr>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
<th>Sunday</th>
</tr>
</thead>
<tbody>
<tr>
<td><span>Open gym</span><br>07.00-10.00</td>
<td><span>PT</span><br>07.00-18.30</td>
<td><span>Open gym</span><br>07.00-10.00</td>
<td><span>PT</span><br>07.00-18.00</td>
<td><span>Open Gym</span><br>07.00-10.00</td>
<td><span>Open Gym</span><br>10.00-12.00</td>
<td class="closed"></td>
</tr>
<tr>
<td><span>PT</span><br>10.00-17.00</td>
<td><span>Circuits</span><br>18.30-19.30</td>
<td><span>PT</span><br>10.00-16.30</td>
<td><span>Circuits</span><br>18.00-19.00</td>
<td><span>PT</span><br>10.00-18.00</td>
<td class="closed"></td>
<td class="closed"></td>
</tr>
<tr>
<td><span>Open gym</span><br>17.00-20.30</td>
<td><span>Open gym</span><br>19.30-20.30</td>
<td><span>Open gym</span><br>17.30-20.30</td>
<td><span>Open gym</span><br>19.00-20.30</td>
<td class="closed"></td>
<td class="closed"></td>
<td class="closed"></td>
</tr>
</tbody>
</table>
</div>
</div>
For the full code and working example see the Codepen example

Related

I want scrollable in <thread> in table on top header

<div className="table-responsive">
<table className="table table-sm">
<thead>
<tr className="table-active">
<th>name</th>
<th>nickname</th>
<th>age</th>
<th>gender</th>
<th>height</th>
<th>weight</th>
</tr>
</thead>
<tbody id="table-body">
<tr>
<td>Alex</td>
<td>Alex</td>
<td>24</td>
<td>Male</td>
<td>1.70</td>
<td>60</td>
<tr>
</tbody>
</table>
</div>
i want css style scrollable in header table and under table and don't want fixed head table on top
so i was searching all day in google I can't found result i want please tell or help me.

Razor: Table does not expand when a large screen is used

I am using in my ASP .NET Razor Page and it scales very nicely when i decrease the width of my browser. However, when i increase the width of my browser, it does not increase anymore. I want it to increase in size as it has too much white space on the sides.
In the code below i tried style="width:100%" or even changing the margins but it doesn't scale due to large screens. I also tried using container-fluid class and it doesn't work. Need a solution.
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Name</th>
</tr>
</thead>
<tr>
<td>1</td>
<td>Bob</td>
</tr>
<tr>
<td>2</td>
<td>Bobby</td>
</tr>
</table>
Try setting the display as table
display:table
If the table is inside any other tags like div, try setting it width to 100% as well and the display of div is block
Did you put the table in a container-flex? (Bootstrap 4) If not the 100% table width is the same as the normal Bootstrap container width where the table is in.
<div class="container-flex">
<div class="row">
<div class="col">
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Name</th>
</tr>
</thead>
<tr>
<td>1</td>
<td>Bob</td>
</tr>
<tr>
<td>2</td>
<td>Bobby</td>
</tr>
</table>
</div>
</div>
</div>

Align text in middle when there is a image in a row Bootstrap table

I have a bootstrap table, but I can't seem to get the text to align in the middle because the image expands the row.
I have tried adding vertical-align: middle to .table in my CSS, but it doesn't seem to do anything.
Example
https://jsfiddle.net/DTcHh/#&togetherjs=hy7S1lFDR3
<div class="container">
<h2>Hover Rows</h2>
<p>The .table-hover class enables a hover state on table rows:</p>
<table class="table table-hover">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Image</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
<td><img src="http://fullsoftwarepro.com/wp-content/uploads/2015/07/Radmin- server-and-viewer-3.5-Crack-License-key-Download.jpg" width=50></td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary#example.com</td>
<td><img src="http://fullsoftwarepro.com/wp-content/uploads/2015/07/Radmin- server-and-viewer-3.5-Crack-License-key-Download.jpg" width=50></td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july#example.com</td>
<td><img src="http://fullsoftwarepro.com/wp-content/uploads/2015/07/Radmin-server-and-viewer-3.5-Crack-License-key-Download.jpg" width=50></td>
</tr>
</tbody>
</table>
</div>
Answer
Twitter Bootstrap have a CSS class called text-center, you can simply use this one, as shown below.
Try this:
CSS
.mid-align:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.25em;
}
HTML
<div class="container">
<h2>Hover Rows</h2>
<p>The .table-hover class enables a hover state on table rows:</p>
<table class="table table-hover text-center">
<thead>
<tr>
<th class="text-center">Firstname</th>
<th class="text-center">Lastname</th>
<th class="text-center">Email</th>
<th class="text-center">Image</th>
</tr>
</thead>
<tbody>
<tr>
<td class="mid-align">John</td>
<td class="mid-align">Doe</td>
<td class="mid-align">john#example.com</td>
<td><img src="http://fullsoftwarepro.com/wp-content/uploads/2015/07/Radmin-server-and-viewer-3.5-Crack-License-key-Download.jpg" width=50></td>
</tr>
<tr>
<td class="mid-align">Mary</td>
<td class="mid-align">Moe</td>
<td class="mid-align">mary#example.com</td>
<td><img src="http://fullsoftwarepro.com/wp-content/uploads/2015/07/Radmin-server-and-viewer-3.5-Crack-License-key-Download.jpg" width=50></td>
</tr>
<tr>
<td class="mid-align">July</td>
<td class="mid-align">Dooley</td>
<td class="mid-align">july#example.com</td>
<td><img src="http://fullsoftwarepro.com/wp-content/uploads/2015/07/Radmin-server-and-viewer-3.5-Crack-License-key-Download.jpg" width=50></td>
</tr>
</tbody>
</table>
</div>
As for specificity, declaring a style attribute inside a tag overwrites the style written in your *yourStyle*.css file, so in most cases it is not the best practice to declare the style inside the HTML element, but it is surely acceptable (just added a small note).

Setting the width of the cells in html5

I'm trying to attribute an width for cells but it doesn't work. I used CSS to make it, since width is not supported in HTML5. In my problem I have a table with headers and inside that table I have another table with a scroll to show the results, I need to order the cell results by the headers attributing the same width as headers. Can someone help me?
Here's the fiddle . Thank you!
Here's what i've tried:
<table class="two">
<thead>
<tr>
<th style="width:150px">Tipo de Anúncio</th>
<th style="width:150px">Tipo de Imóvel</th>
<th style="width:150px">Localização</th>
<th style="width:150px">Mediador</th>
<th style="width:150px">Preço</th>
<th style="width:150px">Área</th>
</tr>
</thead>
<tbody class="scroll">
<tr>
<td colspan="2">
<div class="scroll">
<table>
<tr>
<td style="width:150px">January</td>
<td style="width:150px">$100</td>
<td style="width:150px">February</td>
<td style="width:150px">$80</td>
<td style="width:150px">February</td>
<td style="width:150px">$80</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
<td>February</td>
<td>$80</td>
<td>February</td>
<td>$80</td>
</tr>
<tr>
<td>January</td>
<td>$100</td>
<td>February</td>
<td>$80</td>
<td>February</td>
<td>$80</td>
</tr>
You have several problem in your layout but the main is not the width but the colspan : (thw width work right)
your th don't wrap all the column. If ypu have six column you need a colspan = 6
<tbody class="scroll">
<tr>
<td colspan="6">
I have touched only few element but ypou can see a preliminary result in this jsfiddle

Align text at each end of a column - Bootstrap

I have a responsive table where the end column shows money figures. Currently it looks like this:
But I want it to do this:
There may not be any data so the £ sign will be replace with N/A which should also be pulled to the right of the column.
The data is fetched from MySQL but here is a simplified snippet of my code:
<table id="mytable" class="table table-bordred table-striped">
<thead>
<th>Reference</th>
<th>Client</th>
<th>Description</th>
<th>Money</th>
</thead>
<tbody>
<tr>
<td>#1234</td>
<td>Josh Blease</td>
<td>Needs a new filter fixing</td>
<td class='money'>
<div class='text-right'>Budget: £123,456</div>
<div class='text-right'>Value: £200,000</div>
<div class='text-right'>Spent: N/A</div>
</td>
</tr>
</tbody>
Divs are useful but Ii don't think that be the best solution for this case maybe you need to use better the table properties
http://www.usabilidad.tv/tutoriales_html/colspan_y_rowspan.asp
<table id="mytable" class="table table-bordred table-striped">
<thead>
<th>Reference</th>
<th>Client</th>
<th>Description</th>
<th colspan="2">Money</th>
</thead>
<tbody>
<tr>
<td rowspan="4">#1234</td>
<td rowspan="4">Josh Blease</td>
<td rowspan="4">Needs a new filter fixing</td>
</tr>
<tr>
<td>Budget</td>
<td>£123,456</td>
</tr>
<tr>
<td>Value</td>
<td>£200,000</td>
</tr>
<tr>
<td>Spent</td>
<td>N/A</td>
</tr>
</tbody>
</table>
<table id="mytable" class="table table-bordred table-striped">
<thead>
<th>Reference</th>
<th>Client</th>
<th>Description</th>
<th>Money</th>
</thead>
<tbody>
<tr>
<td>#1234</td>
<td>Josh Blease</td>
<td>Needs a new filter fixing</td>
<td class='money'>
<div class='text-right'><span>Budget:</span> £123,456</div>
<div class='text-right'><span>Value:</span> £200,000</div>
<div class='text-right'><span>Spent:</span> N/A</div>
</td>
</tr>
</tbody>
and
#mytable tbody tr td .text-right span{
min-width:200px;
max-width:300px;
display: inline-block;
}
Spans need to be set as inline-block otherwise the width properties won't take hold as they are by default inline only elements.
Setting the min and max width will force the span container to not go below or above a certain point, meaning that your other text will be forced to stay to the left of the (example) 200px mark even if your initial text (as in spent) only ends up being (again, example) 80px

Resources