Square table fitting in screen - html

I want to create a table which is square and contains of squares. The whole table must fit inside the window without scrolling. It's a bit hard to explain, here is an image what I want:
Is that possible? Until now, I have this but it is not really what I want...
FIDDLE
table {
width: 100%;
}
td {
width: 30%;
position: relative;
}
td:after {
content: '';
display: block;
margin-top: 100%;
}
td .content {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
td img {
width: 100%;
height: 100%;
}
<table>
<tr>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
</tr>
<tr>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
</tr>
<tr>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
</tr>
</table>

if it is to fill entire height :
body {
margin: 0;
}
table {
margin: auto;
width: 100vh;
table-layout: fixed;
border-collapse: collapse;
}
td {
width: 33.33%;
}
img {
width: 100%;
display: block;
}
/* take care of portrait orientation or ratio */
html {
height: 100%;
display: flex;
}
body {
margin: auto;
}
table {
max-width: 100vw;
}
<table>
<tr>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
</tr>
<tr>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
</tr>
<tr>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
<td>
<div class="content"><img src="http://placehold.it/128"></div>
</td>
</tr>
</table>
but if it comes into portrait , you might need js to find out ratio of window (landscape/portrait to overwrite style sheets rules).
the use of mediaqueries for orientation to reset width to vw units will be needed too

This will work with some jQuery: https://jsfiddle.net/rs136ksc/4/
Changed your rows to 3 (3x3 now).
The jQuery snippet makes your table's width exactly as much as your height. The table's height is exactly the window's height. This only works every time you load the page, so if you want it to be persistent you'll have to figure out some more jQuery. Good luck!
Some of the added CSS:
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
overflow:hidden;
}
table {
margin:0 auto;
height:100%;
}
jQuery:
var cw = $('.child').width();
$('.child').css({
'height': cw + 'px'
});

Related

Make whole table fill remaining print page

All of this is made with angular 12 and with ngx-print library
I have tabular data that I needs to display and I achieved the look and feel with HTML :
<div id="changeOrder">
<body>
<div *ngIf="allReports">
<!-- style="size: A4; display: block;height: 100%;" -->
<table style="size: A4; height: 100%;" *ngFor="let item of response">
<!-- Here the header starts -->
<div class="">
<div class="">
<tr>
<td>
<!--place holder for the fixed-position header-->
<div class="" style=" border-bottom: 1px solid black;">
<div class="">
<div class="">
<img src="../../../../../../../assets//img/logo_rr.png" alt="Logo"
style="height: 50px;" />
</div>
<table style="width:100%;">
<thead class="" style="width:100%;">
<tr>
<td style="width:155px;">
<h2>Change Order</h2>
</td>
<td>
<h2>{{item.CHANGEORDERID}} </h2>
</td>
</tr>
</thead>
</table>
</div>
</div>
</td>
</tr>
</div>
</div>
<!-- Here the header Ends -->
<tbody style="display: block;height: 100%;">
<tr>
<td>
<h3>Tasks</h3>
<table style="size: A4; height: 100%;">
<thead>
<tr>
<td>
<b>Name</b>
</td>
<td style="width:400px">
<b>Description</b>
</td>
<td>
<b>Status</b>
</td>
<td>
<b>Due Date</b>
</td>
</tr>
</thead>
<tbody *ngFor="let child of item.taskChild;">
<tr>
<td>{{ child.TDOTNUMBER }} </td>
<td style="width:400px">{{child.TASKSUMMARY}} </td
<td>{{child.TSTATUS}}</td>
<td>{{child.TDUEDATE_ORIG_TYPE}}</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
<tfoot>
<tr class="outer-row">
<td>
<div class="page-footer-space">
<!-- <b>Printed On</b> {{printedDate}} -->
</div>
</td>
</tr>
</tfoot>
</table>
</div>
</body>
</div>
and with this CSS :
.page-footer-space,
.page-footer {
height: 100px;
}
.page-footer {
position: fixed;
bottom: 0px;
/* width: 100%; */
}
.page {
page-break-after: always;
}
#page {
margin: 10mm !important;
size: landscape;
}
#media print {
table {
font-size: .8rem;
width: 100%;
height: 90vh;
border: solid;
table-layout: fixed;
}
tbody {
margin: 10mm;
}
tfoot {
display: table-footer-group;
}
button {
display: none;
}
}
Basically the data when it gets printed it look great,sometimes each report occupies more than 1 page, but what I need to achieve is that whenever an item of response is finished it does not matter at what point of the printing page it finished, the rest of the page needs to be blank and then the next item in the iteration should be printing.
I have not been successful in achieving that break-page at the end of the table.
This is how it currently looks:

How can I get the information table and image aligned on the same line

I am trying to make a web-page where I have a table of information and an image side-by-side as in the example below
Example:
bar fOo
Instead of:
bar
fOo
I have placed the image within a div and the information table in another div element, and I have been playing with the CSS properties to try to get them to be side-by-side, however they refuse to work as expected.
The CSS is below, #book is the image itself, while book_information is the information inside the table.
#book
{
float: right;
flex: 33.33%;
padding: 5px;
margin-left: 0;
width: 50%;
}
#book_information
{
width: 50%;
float: left;
padding-right: 0;
margin-right: 0;
}
table
{
border-collapse: collapse;
float:top;
border: 1px solid black;
table-layout: fixed;
width: 50%;
}
What should I use to allow this to work as expected? and what improvements could work I work on to get it responsive?
Below is the html structure of the page at the moment that I am using along with this:
<main>
<div>
<div class= "left" id="book"><img src="Book.jpg" alt="></div>
<div class="left" id="book_information">
<table id="information">
<tr>
<td class="1">Price:</td>
<td class="1">€18.90</td>
</tr>
<tr>
<td>Author</td>
<td></td>
</tr>
<tr>
<td class="1">About</td>
<td class="1"><p></p></td>
</tr>
<tr>
<td>Where to get it:</td>
<td>Amazon ,
Casa Del Libro ,
FNAC ,
Libelista
</td>
</tr>
</table>
</div>
</div>
</main>
There are different ways of doing this.
Here's a solution that involves using float:left style for your table:
table {
float: left;
}
img {
width: 100px;
height: 100px;
}
<table>
<tr>
<td>Price</td>
<td>$5</td>
</tr>
<tr>
<td>Author</td>
<td>Bob</td>
</tr>
</table>
<div>
<img
src="https://via.placeholder.com/120.png?text=Book+Image"
alt="Book Image Here">
</div>
This one involves putting your table and image in yet another table:
img {
width: 100px;
height: 100px;
}
<table>
<tr>
<td>
<table>
<tr>
<td>Price</td>
<td>$5</td>
</tr>
<tr>
<td>Author</td>
<td>Bob</td>
</tr>
</table>
</td>
<td>
<div>
<img
src="https://via.placeholder.com/120.png?text=Book+Image"
alt="Book Image Here">
</div>
</td>
</tr>
</table>

How to get an image to scale vertically inside a table cell?

I'm working with a legacy table layout, and I've come across a layout problem with the scaling of images within a table cell.
The following code when in a page, scales the image up and down as the width of the browser window changes. However if you change the browswer height of the window up and down, it doesn't scale the image it seems to be locked to whatever the width of the image is. So if the window is wide, then the green section disappears off the bottom of the window
How can I make it so it scales based on height as well? Meaning the red section and the green section should squash the image till it is tiny as the height of the browser gets smaller.
There are javascript solutions to this problem, but I'd like to do it with HTML/CSS.
<style>
.red {
background-color: red;
}
.green {
background-color: green;
}
table {
height: 100vh;
table-layout: fixed;
}
img {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<table style="width:100%">
<col width="100">
<col width="100%">
<col width="100">
<tr class="red" style="height:100px;"> <td> </td> <td> </td> <td></td> </tr>
<tr>
<td> </td>
<td>
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c4/PM5544_with_non-PAL_signals.png" />
</td>
<td> </td>
</tr>
<tr class="green" style="height:200px;">
<td> </td> <td> </td> <td> </td>
</tr>
</table>
</body>
so here is the width compressed, and the image shrinks...
here, the width is wider, but the height is the same, but the image is now taking more vertical height
Maybe those edits will be useful, play with it.
.red {
background-color: red;
}
.green {
background-color: green;
}
table {
height: 100vh;
table-layout: fixed;
}
img {
width: 100%;
height: 100%;
}
.image{
position: relative;
padding-top: 30vh;
}
.image img{
position: absolute;
top: 0;
height: auto;
max-height: 100%;
width: auto;
max-width: 100%;
right: 0;
margin: auto;
left: 0;
}
<table style="width:100%">
<col width="100">
<col width="100%">
<col width="100">
<tr class="red" style="height:100px;"> <td> </td> <td> </td> <td></td> </tr>
<tr>
<td> </td>
<td class="image">
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c4/PM5544_with_non-PAL_signals.png" />
</td>
<td> </td>
</tr>
<tr class="green" style="height:200px;">
<td> </td> <td> </td> <td> </td>
</tr>
</table>
I set max-height for your image to visible the bottom green section in all devices. So you can resize it. You can adjust the max-height based on your requirement. I hope this solution may help you.
.red {
background-color: red;
}
.green {
background-color: green;
}
table {
height: 100vh;
table-layout: fixed;
}
img {
width: 100%;
height: 100%;
max-height: 450px;
object-fit: contain;
}
<table style="width:100%">
<colgroup>
<col width="100">
<col width="100%">
<col width="100">
</colgroup>
<tr class="red" style="height:100px;">
<td> </td>
<td> </td>
<td></td>
</tr>
<tr>
<td> </td>
<td>
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c4/PM5544_with_non-PAL_signals.png" />
</td>
<td> </td>
</tr>
<tr class="green" style="height:200px;">
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
Your <col> widths were 100px, 100%, 100px which is 200px over. The middle column is a non-specified width so it takes whatever space the left and right fixed columns do not take.
The height for the first row is 100px and last row is 200px. The height of the middle row takes up the remaining vertical space. Special pseudo-classes were used to target the td (not the tr). tr seems the logical choice to modify height but it isn't't, because the nature of a html is content oriented therefore witdh and height is 90% td and 10% table.
tr:first-of-type td:first-of-type
tr:last-of-type td:last-of-type
<html> and <body> are set to 100% x 100% position:relative so the <table> assigned with position:absolute sits squarely within the viewport.
The middle row was expanded by colspan='3' and the image is now a background-image. With a minor change the image can expand and fill the whole row without overflow or shifting the other rows further. set background-size to cover from contain.
Demo
html,
body {
height: 100%;
width: 100%;
position:relative;
overflow:hidden;
}
* {
margin:0;
padding:0;
}
.red {
background-color: red;
}
.green {
background-color: green;
}
table {
height: 100%;
width:100%;
table-layout: fixed;
position:absolute;
left:0;
top:0;
bottom:0;
right:0;
}
tr:nth-of-type(2) td {background:url("https://upload.wikimedia.org/wikipedia/commons/c/c4/PM5544_with_non-PAL_signals.png" )no-repeat; background-size:contain;background-position:center center;}
tr:first-of-type td:first-of-type {
min-height: 100px;
}
tr:last-of-type td:last-of-type {
min-height: 200px
}
<table style="width:100%">
<col width="100">
<col>
<col width="100">
<tr class="red">
<td height='100'> </td> <td>
</td><td></td>
</tr>
<tr>
<td colspan='3'> </td>
</tr>
<tr class="green">
<td height='200'> </td>
<td></td>
<td> </td>
</tr>
</table>
Like this?
https://jsfiddle.net/xhc6ovzL/
<table style="width:100%">
<col width="100">
<col width="100%">
<col width="100">
<tr class="red" style="height:100px;"> <td> </td> <td> </td> <td></td> </tr>
<tr>
<td colspan="3">
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c4/PM5544_with_non-PAL_signals.png" />
</td>
<td> </td>
</tr>
<tr class="green" style="height:200px;">
<td> </td> <td> </td> <td> </td>
</tr>

why I can't set width in td when `td` wrote in two div while one was set `position: absolute` and another `position: relative`?

Just like the title, I can't set the td width in specific environment like this and you can look the demo here http://codepen.io/quietcoder/pen/ygRVLB?editors=1100
.outer {
position: relative;
display: inline-block;
}
.inner {
position: absolute;
}
<div class="outer">
<div class="inner">
<table>
<tr>
<td style="width: 100px">
<div>123</div>
</td>
<td>
<div>123</div>
</td>
</tr>
</table>
</div>
</div>
Then, If I write two table, the width in td will work, it's so amaaaaaaaazing!!!
And do you knew why this happened?
.outer {
position: relative;
display: inline-block;
}
.inner {
position: absolute;
white-space: nowrap;
}
.inline-block-box {
display: inline-block;
}
<div class="outer">
<div class="inner">
<div class="inline-block-box">
<table>
<tr>
<td style="width: 100px">
<div>123</div>
</td>
<td>
<div>123</div>
</td>
</tr>
</table>
</div>
<div class="inline-block-box">
<table>
<tr>
<td style="width: 100px">
<div>123</div>
</td>
<td>
<div>123</div>
</td>
</tr>
</table>
</div>
</div>
</div>
If you check the div.inner width property in devtool, you can find that the width is very interesting......
Can you explain it?
First you have to set width to table, then td will be resized
.outer {
position: relative;
display: inline-block;
}
.inner {
position: absolute;
}
<div class="outer">
<div class="inner">
<table style="width: 200px">
<tr>
<td style="width: 100px">
<div>123</div>
</td>
<td>
<div>123</div>
</td>
</tr>
</table>
</div>
</div>
Because of your
.inner {
position: absolute;
}
.outer {
position: relative;
display: inline-block;
}
<div class="outer">
<div class="inner">
<table>
<tr>
<td style="width: 100px; background-color: red;">
<div>123</div>
</td>
<td>
<div>123</div>
</td>
</tr>
</table>
</div>
</div>
I think it's a combination of these factors:
outer div is inline-block, which means it has zero width
inner div is limited by the width of the outer one
table has it's own layout management and it tries to fit its container
So unless you set the width of table/inner/outer, the table cell will stay narrow.
Inside tables, width will always be taken as a suggestion rather than an absolute.
Now in this case, the width of the table's parent is undetermined (because it is positioned absolutely, and inside a div with inline-block) so the table doesn't know how wide it can be. So it won't make itself wider than its contents.
If the absolute div would have a width specified, then the table would know how wide it could make its cells.
.outer {
position: relative;
display: inline-block;
}
.inner {
position: absolute;
width:150px; /* added */
}
<div class="outer">
<div class="inner">
<table>
<tr>
<td style="width: 100px">
<div>123</div>
</td>
<td>
<div>123</div>
</td>
</tr>
</table>
</div>
</div>
Or, of course, set the width of the table itself.
You can give table border to view width or height of your TD as Like This
.inner {
position: absolute;
}
.inner {
position: absolute;
}
<div class="outer">
<div class="inner">
<table border='1'>
<tr>
<td style="width: 100px">
<div>123</div>
</td>
<td>
<div>123</div>
</td>
</tr>
</table>
</div>
</div>

How to force or bring vertical scroll bar to front in html css

I would like to bring this vertical scroll bar to the front. Here is the image.
I do not know how to set it.
UPDATE
I did a work around but the wrong part is that the items text element are not hidding behind the header. Here is my fiddle
.container
{
position: absolute;
background: lightblue;
height: 100%;
width: 90%;
}
.table-header
{
position: absolute;
height: 25px;
width: 100%;
background: red;
}
.table-body
{
position: relative;
padding-top: 25px;
overflow: auto;
height: 30%;
}
.table
{
table-layout: fixed;
}
<div class="container">
<div class="table-header">
<table class="table">
<thead>
<th>
Header
</th>
</thead>
</table>
</div>
<div class="table-body">
<table class="table">
<tbody>
<tr>
<td>
Item 1
</td>
</tr>
<tr>
<td>
Item 2
</td>
</tr>
<tr>
<td>
Item 3
</td>
</tr>
<tr>
<td>
Item 4
</td>
</tr>
<tr>
<td>
Item 5
</td>
</tr>
<tr>
<td>
Item 6
</td>
</tr>
<tr>
<td>
Item 7
</td>
</tr>
</tbody>
</table>
</div>
</div>
As the scrollbar is on your table, there's no way you can have the scrollbar on top of the table header, and your table below the table header. Your best bet is to have it offset from top the height of the header:
So change your current CSS for your table body:
.table-body
{
position: relative;
overflow: auto;
height: 30%;
margin-top: 25px;
}
See this fiddle.
Update
Instead of adding padding-top:25px you need to add margin-top:25 to .table-body
This should work. Adding z-index to .table-header will fix the issue.
.container
{
position: absolute;
background: lightblue;
height: 100%;
width: 90%;
}
.table-header
{
position: absolute;
height: 25px;
width: 100%;
z-index:1000;
background: red;
}
.table-body
{
position: relative;
margin-top: 25px;
overflow: auto;
height: 30%;
}
.table
{
table-layout: fixed;
}
<div class="container">
<div class="table-header">
<table class="table">
<thead>
<th>
Header
</th>
</thead>
</table>
</div>
<div class="table-body">
<table class="table">
<tbody>
<tr>
<td>
Item 1
</td>
</tr>
<tr>
<td>
Item 2
</td>
</tr>
<tr>
<td>
Item 3
</td>
</tr>
<tr>
<td>
Item 4
</td>
</tr>
<tr>
<td>
Item 5
</td>
</tr>
<tr>
<td>
Item 6
</td>
</tr>
<tr>
<td>
Item 7
</td>
</tr>
</tbody>
</table>
</div>
</div>
You can bring header on front by using z-index and after that just adjust the width of header to scroll-bar.
.container
{
position: absolute;
background: lightblue;
height: 100%;
width: 90%;
}
.table-header
{
position: absolute;
height: 25px;
width: 96.8%;
background: red;
z-index:1;
}
.table-body
{
position: relative;
padding-top: 25px;
overflow: auto;
height: 30%;
}
.table
{
table-layout: fixed;
}
<div class="container">
<div class="table-header">
<table class="table">
<thead>
<th>
Header
</th>
</thead>
</table>
</div>
<div class="table-body">
<table class="table">
<tbody>
<tr>
<td>
Item 1
</td>
</tr>
<tr>
<td>
Item 2
</td>
</tr>
<tr>
<td>
Item 3
</td>
</tr>
<tr>
<td>
Item 4
</td>
</tr>
<tr>
<td>
Item 5
</td>
</tr>
<tr>
<td>
Item 6
</td>
</tr>
<tr>
<td>
Item 7
</td>
</tr>
</tbody>
</table>
</div>
</div>