CSS issue with Table with images - Screenshots included - html

I'm working on a project where I've made my phpmyadmin database spit out a set of 6 images on my webpage. I've put it into a table and this is where the trouble begins - even though it sounds easy!
I need the images to be in three's, in a horizontal line.
I will have 6 images most of the time so 3 per row with good spacing/padding etc.
I've tried a lot of things and played around with the CSS but couldn't get it to work.
Here are (respectively) the actual page and how it looks, the CSS for it and the actual code/script of the table:
Actual Page
CSS for the table: table.Evidence td {
padding:0px,10px,0px,0px;
}
Script for the table:
It looks very easy but I couldn't make it work.
Any help would be much appreciated!
I'm new so please bear with me until I get used to this.

The first thing is that if you define all 4 paddings in one command you have to seperate them with spaces.
table.Evidence td { padding:0px 10px 0px 0px; }
It also seems that you don't use the table tags right.
With an tr you are adding tan new row and with an td you are adding a new cell.
A table of 2x2 cells would look like:
<table border="1">
<tr>
<td>
1
</td>
<td>
2
</td>
</tr>
<tr>
<td>
3
</td>
<td>
4
</td>
</tr>
</table>

Your <tr></tr> tags should be after every third image, so the if in your while should be:
if($i % 3 == 0){
echo "</tr></tr>";
}
else{
echo "<td><img something...></td>";
}
Also you must have one <tr> opening tag directly after the <table> tag, and one </tr> closing tag directly before the </table> tag.

Related

laravel dompdf not rendering complex html with rowspan and colspan correctly

I have a very complex dynamic table that I need to output to pdf in laravel 5.6. The project I inherited had Dompdf installed and is already rendering all other content. Therefore, I use it as well for compatibility.
My issue is I have a table to render consisting of 13 columns and undefined number of rows, where intermittently a column may span 13 columns for a heading or a row may span several rows at any given time or a colspan within the rowspan that spans 11 columns from the 3rd row. No html is hardcoded except the <table>, <thead>, <th> and <tbody> tags. The html within the tbody tag is dynamically generated depending on the array data.
Everything looks great in the browser and when I view() the pdf blade as well as ctrl + p it creates a nice pdf, although for some reason rowspan cells spanning to the next page does not carry over markup and content. As soon as I try to stream() the pdf the table becomes warped and looks like a toppled building built by Picasso.
Here is links to pdf's, the one I ctrl + p lost its colour due to me removing names.
File to view pdf printed with ctrl + p
Pdf streamed with Dompdf
Image of viewing pdf in browser
Image of pdf when streaming via Dompdf:
Html sample rendered in browser:
<tr style="background-color: #5b8969;">
<td rowspan="2" style="background-color: #F8C293; color: black;">Spray 4</td>
<td>Pollinate</td>
<td>7-10 days later</td>
<td>BENOMYL WP 25KG </td>
<td>benomyl 500g/kg</td>
<td> </td>
<td>1000</td>
<td>2.00</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Full bloom</td>
<td>Black Spot</td>
<td>WETCIT DUO 20L </td>
<td>borax 10g/orange oil 50g/l</td>
<td> </td>
<td>1000</td>
<td>25.00</td>
<td>100.0000</td>
<td>120.0000L</td>
<td>2500.0000</td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="13" style="background-color: #9fb5d3;" class="h3 font-weight-bold">ANOTHER ONE</td>
</tr>
<tr>
<td rowspan="7" style="background-color: #F8C293; color: black;">Spray 7</td>
<td>20 cm</td>
<td>African Armyworm</td>
<td>CERATO 250 EC 5L </td>
<td>pyraclostrobin 250g/l</td>
<td> </td>
<td>1000</td>
<td>2.00</td>
<td>10.0000</td>
<td></td>
<td>20.0000</td>
<td></td>
<td></td>
</tr>
Can someone please help and give me a clue on how to output such a complex table with Dompdf? As I would really want to keep on using only one PDF rendering library in this project.
Otherwise I am open to suggestions to use another pdf library that can handle rowspan that span pages and this complex layout?
Update
Based on a comment by Don't panic (he suggested validating html and fill empty td tags with ), that he subsequently deleted.
I re-wrote the HTML as a template into my pdf.blade.php view. Now, I only output the values in a loop in my view. Firstly, it becomes easier to maintain and to leave off the validation he suggested. I also filled every empty <td> tag with a hardcoded ' '. This is to more easily see why certain rows end where they should and others not. The result is sadly still the same, a warped table. But it does seem to be a rowspan issue not colspan. The 'rowspan' rows stack after another. So maybe missing a td tr.
Solved rowspan stacking issue
Two weeks of testing and only problem was it was not outputting certain rows' opening tags, which lead to rows not knowing when to begin. Now only problem left is rowspan across pages.
Update on update
So I have really tried everything I can to get DomPdf to do what it is suppose to do, which is rendering pdf's. I have read a bit more and found that this library has a long standing issue of not being able to render rowspan accross pages. Therefore, on to the next rendering library wkhtlmpdf or I could logically divide rowspans to stop at end of page and start again on new page. Will have to check my watch on this one.

Alternate table row color using CSS, individual cells get colored not the even rows

Somehow I can't figure out the following: Alternate table row color using CSS?
If I use the code suggested in the aforementioned topic the even cells get colored (the first, third and fifth. There is a total of 5 cells in a row). It doesn't matter if I use 'even' or 'odd'.
td:nth-child(odd)
{
background: #f5f6fa;
}
If use the following code, all the rows get colored.:
tr:nth-child(odd)
{
background: #f5f6fa;
}
#svdh You've got tags outside of your body and html tags also which in a normal web page wouldn't be rendered. The problem with your HTML is you're setting up loads of tables instead of one with multiple rows. It should be like this.
<table>
<tr>
<td>One</td>
<td>One.</td>
</tr>
<tr>
<td>Two</td>
<td>Two.</td>
</tr>
<tr>
<td>Three</td>
<td>Three.</td>
</tr>
</table>
Fiddle here..
https://jsfiddle.net/fo7Ldfqs/
UPDATED:
If you've got multiple tables and you're trying to color every other one then just use:
table:nth-child(odd){background:#ff0000;}
Fiddle here.. https://jsfiddle.net/4641ph6u/

Firefox printing table on 2nd page

I have a small header at the top of my page and then a table containing a decent amount of dynamic data.
The data occasionally falls right on the edge of a page break when printing. So for example.
If there are 19 or less rows in the table, it will all print on 1 page.
If there are 20 or 21 rows it will throw the entire table on the second page.
If there are 22 or more rows it the table, it will print 20 on the first page and 2 on the second page
I don't mind the 1st or 3rd scenario, but I don't care for the second. I realize this is my OCD kicking in, but it seems like someone would know of a fix for it.
This seems to only occur in Firefox. In Chrome the table will always split, around after 18 rows. IE10 seems to always split as well, also at 18 rows.
I've tried every conceivable variation of the following:
table { page-break-inside:auto }
tr { page-break-inside:avoid; page-break-after:auto }
Im using bootstrap3, if that makes a difference.
Note: You can have it all print on one page by changing the print zoom, but I cant expect my users to do that.
Note: I do realize I could do a hack like check how many rows, and if it falls in the bad range, add or remove some padding somewhere on the page. But I'd rather do it the correct way, assuming there is one.
UPDATE: I Found out this happens only when Firefox is at the 100% zoom setting. When you set it to "Shrink To Fit" it behaves as the other browsers do. IE10, even with zoom set to 100% behaves normally.
You could try to add css:
table {page-break-before: avoid;}
You can put your tr inside tag but as div doesnot support tr so you have to make structure of your table like
replace
<table>
<tr >
<td class="fixture-table-header">Location Name</td>
<td class="fixture-table-header">Fixture Type</td>
<td class="fixture-table-header">Fixture Photo</td>
<td class="fixture-table-header">Qty</td>
<td class="fixture-table-header">Input Watts</td>
<td class="fixture-table-header">Annual Hours</td>
<td class="fixture-table-header">kW</td>
<td class="fixture-table-header">Annual kWh</td>
<td class="fixture-table-header">Total Utility Incentive Avaiable</td>
<td class="fixture-table-header">Total Proposed Cost</td>
</tr>
</table>
with
<table >
<tr>
<td><div><table><tr style="page-break-inside : avoid">
<td class="fixture-table-header">Location Name</td>
<td class="fixture-table-header">Fixture Type</td>
<td class="fixture-table-header">Fixture Photo</td>
<td class="fixture-table-header">Qty</td>
<td class="fixture-table-header">Input Watts</td>
<td class="fixture-table-header">Annual Hours</td>
<td class="fixture-table-header">kW</td>
<td class="fixture-table-header">Annual kWh</td>
<td class="fixture-table-header">Total Utility Incentive Avaiable</td>
<td class="fixture-table-header">Total Proposed Cost</td>
</tr></table></div></td>
</tr>
</table>
and then add this css
#media print
{
#page {size: landscape} //optional
table { page-break-after:auto }//optional
div { page-break-inside:avoid; page-break-after:auto }
}

nesting html tables issue

Hello I have nested a table inside a gridview(which I think is also basically a table) in asp.net ,but the thing is the table which is inside a cell leaves a space at it edges ,(i.e from the wall of the grid view), I want this space to be minimized this is my grid view :
<FooterTemplate>
<table border="1" cellspacing="0" cellpadding="0" width="auto">
<tr><td><asp:Label ID="cl_crTotal" runat="server" CssClass="alLbl" /></td>
</tr>
<tr><td><asp:Literal runat="server" ID="closingTotC" ></asp:Literal></td>
</tr>
</table>
</FooterTemplate>
I have also given the image ,please check
http://imgur.com/4ukGm&K8tRy "this image"
PS:I know and hope this is a simple problem and would be easily solve just that I am new to this
Without seeing the code of that grid-view, I can only guess, that there are some paddings or margins set, which cause this behavior.
So for the grid cell, in which the table appears set
padding: 0;
and for the table itself set
margin: 0;
Actually, its pretty simple. If you look at all your fields in the data, you see actually every field has it. Its called a padding.
What you should do is remove the padding from that cell. I am going to asume you dont want it in the rest of your table, so what you do is give the specific cell an id, and add in the css a rule to it saying it shouldnt receive any padding.
your html would look like this:
<body>
<table>
<tr>
<td id="cell_id">somedata</td>
</tr>
</table>
</body>
This would look something like this in your css file
#cell_id { padding: 0px; }

Removing table line

I want to add two table or more consecutively and they must be seemed like one table.
<html>
<head>
<style type="text/css">
.cls
{
border:1px solid #000000;
}
.cls td {
border:1px solid #000000;
}
</style>
</head>
<body>
<table class="cls">
<tr>
<td>aaa</td><td>bbb</td><td>ccc</td>
</tr>
<tr>
<td>ddd</td><td>eee</td><td>fff</td>
</tr>
</table>
<table class="cls">
<tr>
<td>aaa</td><td>bbb</td><td>ccc</td>
</tr>
<tr>
<td>ddd</td><td>eee</td><td>fff</td>
</tr>
</table>
</body>
</html>
My problem is the line that tables combined has a doble line normally. How can i show it like a single line.
.cls-last
{
border-top: 0px;
}
On your 2nd table:
<table class="cls cls-last">
<tr>
<td>aaa</td><td>bbb</td><td>ccc</td>
</tr>
<tr>
<td>ddd</td><td>eee</td><td>fff</td>
</tr>
</table>
You could change the top (or bottom) border of the table via CSS.
However, alignment could be a challenge here. In the example you gave, not a problem--each contains 3 (relatively) similar characters each. So, it'd be nearly identical. However if one column in one table has 10 characters for instance, HTML is going to stretch that column and you're going to be left with two obviously different entities.
So, to make this work 100% of the time, you're going to need to set widths and (possibly) overflow properties as well.
I'm having a tough time understanding why you'd have to do it this way. I'm sure you've got a reason, but two similar entities with similar widths and columns should be able to be commingled. If the tables were to only sometimes appear, or you wanted to remove rows, you could do so via Javascript and/or CSS or at the server level when rendering.