HTML scaling table with resolution - css

I have a html table on my web page. It fits and looks really well on 1920x1080 but when the resolution gets changed to a smaller one or the window gets resized, then the table doesn't fit in the screen any more. I searched and tried like everything and could not fix it so I have to ask here.
Table in html:
<table class="table" id="table">
<tr id="table_headers">
<th >Id</th>
<th>Category</th>
<th>Service Date</th>
<th>Contract Date</th>
<th>Locations</th>
<th>Rate</th>
<!-- <th>Hourly Rate</th>
<th>Turn Rate</th>
<th>Flight Rate</th> -->
<th>Contract Expiration</th>
<th>Past Due Penalty</th>
<th>Billing Address</th>
<th>Billing Email</th>
<th>Name</th>
<th>Phone</th>
<th>Account Number</th>
<th>Signed</th>
<th>PDF</th>
<th class="custom">View</th>
<th class="custom">Download</th>
<th class="custom">Edit</th>
<th class="custom">Delete</th>
</tr>
<?php
$q = $db->prepare("select * from pdfs");
$q->execute();
$res = $q->fetchAll();
foreach($res as $result)
{
echo '<tr id="row'.$result['id'].'">
<td>'.$result['id'].'</td>
<td class="category_tbl_td">'.$result['category'].'</td>
<td>'.$result['date_serviced'].'</td>
<td>'.$result['contract_date'].'</td>
<td>'.$result['locations'].'</td>
<td>'.$result['rate'].'</td>
<td>'.$result['contract_expiry'].'</td>
<td>'.$result['past_due_penalty'].'</td>
<td>'.$result['billing_mail_address'].'</td>
<td>'.$result['billing_email_address'].'</td>
<td>'.$result['billing_name'].'</td>
<td>'.$result['billing_phone'].'</td>
<td>'.$result['AccountNumber'].'</td>
<td>'.$result['Signed'].'</td>
<td>'.$result['pdf_location'].'</td>
<td></td>
<td></td>
<td>
<button type="button" class="btn btn-info">
<a href="edit.php" >
<span class="glyphicon glyphicon-pencil"></span>
</button></td>
<td><b>×</b></td>
</tr>';
}
Table in css:
table,tr,th,td{
color:white;
border: 1px solid #080808;
border-collapse:collapse;
text-align: center;
font-size: 16px;
margin-left: -27%;
margin-top: 1%;
text-align: center;
table-layout: auto;
min-width: 50%;
font-family: Arial;
background:linear-gradient(top, #3c3c3c 0%, #222222 100%);
background:-webkit-linear-gradient(top, #3c3c3c 0%, #222222 100%);
}
I thought adding % instead of px would fix it but it doesn`t. The whole website works just fine, but the table causes issues.
Any ideas what might be the reason for that and how to fix it?
This is how table looks with full hd:
This is how it looks on any lower resolution:

For responsive websites give width in terms of percentage rather than pixels
.class_name
{
width:50%
}

To some screen size you can use this
.table { width: 100%; }
On mobile deviсes you must try someting more complicated. Adding JS Plugin
This fore excample
https://github.com/filamentgroup/tablesaw
Or use css tricks like this
https://css-tricks.com/responsive-data-tables/

Related

need to have caption overlay over table

i can't get the caption to overlay over the table in IE , FF and Chrome work fine
tried everything i know how in css with jsfiddle and can't get IE to look like FF and Chrome , any advice ? I can't change the HTML at all , so i'm left to CSS to try to get this
http://jsfiddle.net/6V2Qf/74/
<table class="report">
<caption>
</caption>
<tbody>
<tr>
<th></th>
<th></th>
</tr>
</tbody>
</table>
Here:
Fiddle: http://jsfiddle.net/pn2Th/
I added position:relative; to the caption:
.report {
width:200px;
height:50px;
border:2px solid green;
background:pink;
}
.report caption { //I also changed this, comes in handy if you have more than one table with caption, because now these rules only apply to the caption of tables with class 'report'
position:relative; //I added this
width:196px; //I also changed this, to align the caption's width with the table's in IE (in Chrome the table was actually 204px wide before)
height:50px;
border:2px solid red;
background:black;
margin-bottom:-2px;
}
I thought it was necessary to add z-index:0; to .report (or maybe even .report tbody),
and z-index:1; to caption...
But none of that appears to be necessary.
<table class="report">
<caption>
</caption>
<tbody>
<tr>
<th></th>
<th></th>
</tr>
</tbody>
<div class="overlay"></div>
</table>
http://jsfiddle.net/kisspa/6V2Qf/75/

CSS - Style the title from the image tag

I'm trying to style the title from the image tag.
I have search other question but can´t it put working in my project.
But I can´t make any changes.
Someone can give me hand with this pls?
my code:
table.tablesorter tbody tr td a:hover img[title]:after
{
content: attr(title);
padding: 4px 8px;
color: #FFF;
background-color:black;
}
<table class="tablesorter" style="width:98% !important">
<thead>
<tr>
<th>
.....
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
..........
</td>
<td>
<a href="#Url.Action("Edit","Account", new { id=item.UserId })">
<img src="~/Content/images/icon_edit.png" title="Edit"/>
</a>
</td>
</tr>
</tbody>
<tfooter>
</tfooter>
</table>
It should be content: attr(title);, not content: attr(data-title); - you don't have a data attribute.
Also, it seems ::before and ::after pseudo-elements are not defined for img - you may have to use something else:
CSS Content attribute for IMG tag
Working Example (when the image is missing): http://jsfiddle.net/DMAFm/
Another example, with the title on the <a> tag: http://jsfiddle.net/DMAFm/1/

Different FieldHeaderStyle DetailsView for edit vs readonly mode

I'm using an ASP DetailsView and would like the item header to be different depending on what mode the DetailsView is in.
I have two images - each one is 500px wide and 30px high. The right 300px is white whereas the left 200px is green or gray, depending on what mode the form will be in (gray for read-only, green for edit). I want the colored area to be the background of the field headings and the white part of the image to be behind the actual bound data.
Using a skin and some simple CSS, this works perfectly for Firefox (version 21.0):
<asp:DetailsView SkinID="DetailsViewSkin" runat="server" CssClass="DetailsView"
RowStyle-CssClass="DetailsViewRow"
EditRowStyle-CssClass="DetailsViewRowEdit"
FieldHeaderStyle-CssClass="DetailsViewHeader"/>
.DetailsView
{
width: 500px;
}
.DetailsViewRow
{
background: url('../Images/KL/tableRowGrayjpg') no-repeat #fff;
}
.DetailsViewHeader
{
width: 200px;
height:30px;
}
.DetailsViewRowEdit
{
background: url('../Images/tableRowGreen.jpg') no-repeat #fff;
}
The colored area appears behind the headings and the rest overlays the white part of the image. However, for IE (version 10) and Chrome (version 26.0.1410.64), the background image is appearing in both the <td> for the heading and the <td> for the values.
Anyone know if this is possible or some cross-browser trick? Thanks!
EDIT
Here is the html code that is being generated (for a little more clarity).
<table id="dvPerson" class="DetailsView" cellspacing="0" border="1" style="border-collapse:collapse;" rules="all">
<tbody>
<tr class="DetailsViewRow"> <!-- DetailsViewRowEdit, when in edit mode -->
<td class="DetailsViewHeader"></td>
<td> … </td>
</tr>
</tbody>
</table>
Firefox only applies DetailsViewRow (the css with the image) to the <tr> element so the <td>'s are left as is, but Chrome and IE apply it to each individual <td> element, so that each column has the background image.
I think you can solve this differentiating the header row <th> and <td> for the data rows.
tr.DetailsViewRow
{
background: url('../Images/KL/tableRowGrayjpg') no-repeat #fff;
}
tr.DetailsViewRowEdit
{
background: url('../Images/tableRowGreen.jpg') no-repeat #fff;
}
td.DetailsViewHeader
{
width: 200px;
height:30px;
background: none;
}
Got it! #Leniel helped me get in the right direction. Based on the html that was being generated (seen below, for brevity), I had to do a little more manual css work:
Generated code:
<table id="dvPerson" class="DetailsView" cellspacing="0" border="1" rules="all">
<tbody>
<tr class="DetailsViewRow"> <!-- DetailsViewRowEdit, when in edit mode -->
<td class="DetailsViewHeader"></td>
<td> … </td>
</tr>
</tbody>
</table>
resulting css (works on Firefix, Chrome, and IE)
.DetailsView
{
width: 500px;
}
.DetailsViewHeader
{
width: 170px;
height:25px;
}
tr.DetailsViewRow td.DetailsViewHeader
{
background: url('../Images/KL/tableRowGray.jpg') no-repeat #fff;
}
tr.DetailsViewRowEdit td.DetailsViewHeader
{
background: url('../Images/KL/tableRowGreen.jpg') no-repeat #fff;
}

Table row hovering - exclude specific cell?

I made a pricing table that will change the background of the row when hovered. Due to the way I am using it I ran into two problems.
there is a 3 row span I am using to hold the purchase button as I want it vertically aligned in the center with the columns to its left. I had to use !important to keep the background white on rollover. Fixed.
when you rollover the purchase button cell its highlights the first row. This is what I do not want. I've tried all sorts of things and rearranged things as well and can't come up with any solution without removing the 3 row span.
jsfiddle
<table>
<tr>
<th colspan="3">title text</th>
</tr>
<tr>
<td>amount</td>
<td class="pricing">price</td>
<td class="purchase" rowspan="3">purchase button</td>
</tr>
<tr>
<td>amount</td>
<td class="pricing">price</td>
</tr>
<tr>
<td>amount</td>
<td class="pricing">price</td>
</tr>
</table>
table{
margin:.5em 0 1em 0;
width:100%;
font-size:15px;
}
table th{
padding:0px 0 10px 5px;
}
table td{
padding:2px 5px;
}
table td.purchase{
text-align:right;
width:150px;
vertical-align:middle;
background:#ffffff !important;
}
table td.pricing{
width:130px;
border-left:5px #ffffff solid;
}
table td.details {
padding:0 35px 0 15px;
}
table tr:hover td
{
background-color: #ebf1f6;
}
I had a similar requirement: apply a background color on a table row, as I hovered over the row with the mouse pointer, except on a 'selected' row, that was already highlighted in a different background color.
Using 'pointer-events: none;' achieved exactly what i wanted: JsFiddle
table#CustOrders tbody tr:hover td {
background-color: LemonChiffon;
}
table#CustOrders tbody tr#selected {
background-color: Yellow;
pointer-events: none;
}
The first thing that came to my mind is using "pointer-events" css property. But I am not sure if it is useful here. Check this link (there is a jsFiddle example available)
Also think about using some javascript code to set the logic you need. I understand that you want to use css only, but js fix can be quite small and obvious here - so why not ?
you can check Answer
HTML
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td colspan="2" scope="row">title text </td>
</tr>
<tr>
<td width="75%" scope="row">
<table width="100%" border="0" cellspacing="2" cellpadding="2" class="amount_table">
<tr>
<td>amount</td>
<td>price</td>
</tr>
<tr>
<td>amount</td>
<td>price</td>
</tr>
<tr>
<td>amount</td>
<td>price</td>
</tr>
</table>
</td>
<td width="25%">Purchace</td>
</tr>
</table>
CSS
.amount_table tr:hover{
background:gray
}

Text misaligns in IE

I have a ASP.net web page I'm working with, I didn't create it myself, with the following HTML code:
<DIV style="POSITION: absolute; TEXT-ALIGN: center; WIDTH: 1400px; TOP: 60px; LEFT: 125px">
<SPAN style="TEXT-ALIGN: center; FONT-SIZE: xx-large" id=labelInstructions>Some Text: <BR><BR></SPAN>
<TABLE style="WIDTH: 1200px" border=1 align=center>
<TBODY>
<TR>
<TD><LABEL style="FONT-SIZE: x-large" for=FileUpload1>ENTER Path: </LABEL><INPUT id=FileUpload1 size=70 type=file name=FileUpload1></TD>
</TR>
<TR>
<TD><SPAN style="COLOR: red; FONT-SIZE: medium" id=fileUploadError><BR><BR></SPAN></TD>
</TR>
<TR>
<TD>
<TABLE style="WIDTH: 1200px" border=1>
<TBODY>
<TR>
<TD style="WIDTH: 400px; FONT-SIZE: x-large" vAlign=top align=right>FILE CONTENT INSTRUCTIONS:</TD>
<TD style="WIDTH: 850px; FONT-SIZE: x-large" vAlign=top align=left>INSTRUCTION 1<BR>INSTRUCTION 2<BR></TD></TR>
<TR><TD></TD></TR>
<TR>
<TD style="WIDTH: 400px; FONT-SIZE: x-large" vAlign=top align=right>FILE CONTENT EXAMPLE:</TD>
<TD style="WIDTH: 850px; FONT-SIZE: x-large" vAlign=top align=left>EXAMPLE 1<BR>EXAMPLE 2<BR><BR></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</DIV>
When this html is displayed in IE, I notice that the alignment of the text in the cells in the inner table, i.e. the table that is in the third cell of the outer table, is distorted when zooming in and out on it. I have a fixed table setting in pixels instead of percentages, so I don't understand why this is an issue. I want the text in the cells to stay in the same
position when zooming. The code must be manipulated from the code behind, so I cannot create a separate CSS file. Any help is appreciated.
Here are two examples to illustrate what I'm talking about:
Normal zoom at 100%:
Zoom at 75%:
Notice in the second image the two table cells at the bottom are slightly offset to the left.
UPDATE:
Yes, I understand, we will be implementing a new system in the near future. Obviously this is old and very non-standard, this was dropped in my lap when I started working with it. And we're coming up with plans for a new system to replace it, in the meantime, this is what I have to deal with.
(1) There's a problem with your nested table...
<TBODY>
<TR>
<TD style="WIDTH: 400px; FONT-SIZE: x-large" vAlign=top align=right>FILE CONTENT INSTRUCTIONS:</TD>
<TD style="WIDTH: 850px; FONT-SIZE: x-large" vAlign=top align=left>INSTRUCTION 1<BR>INSTRUCTION 2<BR></TD></TR>
<TR><TD></TD></TR>
<TR>
<TD style="WIDTH: 400px; FONT-SIZE: x-large" vAlign=top align=right>FILE CONTENT EXAMPLE:</TD>
<TD style="WIDTH: 850px; FONT-SIZE: x-large" vAlign=top align=left>EXAMPLE 1<BR>EXAMPLE 2<BR><BR></TD>
</TR>
</TBODY>
The format of this inner table is:
Row 1: Two cells.
Row 2: One cell.
Row 3: Two cells.
You need to have an extra td in row #2. (I'd say use colspan, but I'm not sure if IE does that correctly either.)
(2) I don't know how to fix that, but my guess would be that it will require javascript or disabling of the zoom feature (last I heard, the latter is not possible, though. I could be wrong there.) I haven't read the entire thing, but this MSDN article seems like a great place to start. It looks like you can detect the browser's zoom factor. If it's not equal to 1.0, you could try to get javascript to resize things in order to get the td's to their intended location.
(3) It isn't recommended that you use tables for content alignment. (I suppose this would be a good reason why.)

Resources