Different FieldHeaderStyle DetailsView for edit vs readonly mode - asp.net

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;
}

Related

HTML scaling table with resolution

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/

Tooltips, CSS only, Show text tooltip on mouseover using a class to define the text

I'm fairly new to CSS, but have what seems to be an unique question.
I have a TL;DR if you want to skip to it.
I've seen MANY tutorials on how to display tooltips, but none answer this exact scenario, so it may not be possible.
Backstory:
I've been playing around with tables to show a calendar and have made it so I can simply change the class of a td cell to change the background colour.
This allows me to very easily edit my HTML, changing a single class on each line to change a date from available to booked. For instance:
HTML: <td class="b">1</td>
CSS: .b { color: #FFFFFF; background-color: #CC0033; font-size: 12px; text-align: center}
in my CSS, I have the "b" set to turn the background red, indicating this date is no longer available.
HTML: <td class="a">1</td>
CSS: .a { font-size: 12px; text-align: center}
The above would have no background colour and would indicate the date is available.
Now, I have been able to get a tooltip to show based on what class the cell is set to, but it seems I have to set every cell with the text, like this:
<td class="a">1<span class="tooltiptext">Tooltip text here</span></td>
which I guess is a way to do it, but it takes more time to edit, and I want it so I can display 2-3 different messages depending on which class I select in the td class.
So the question:
Is there a way I can set it up so,
If the td class = "a", a tooltip will show up saying "Available"
OR If the td class = "b", a tooltip will show up saying "Booked"
OR If the td class = "r", a tooltip will show up saying "Reserved"
when I mouseover the cell, without having to set those responses over and over again in every td cell.
IE: Without doing something like this:
<td class="a">1<span class="tooltiptext">Available</span></td>
<td class="b">2<span class="tooltiptext">Booked</span></td>
<td class="r">3<span class="tooltiptext">Reserved</span></td>
<td class="b">4<span class="tooltiptext">Booked</span></td>
<td class="b">5<span class="tooltiptext">Booked</span></td>
<td class="b">6<span class="tooltiptext">Booked</span></td>
<td class="a">7<span class="tooltiptext">Available</span></td>
<td class="b">8<span class="tooltiptext">Booked</span></td>
<td class="b">9<span class="tooltiptext">Booked</span></td>
I'd rather it was simply like this:
<td class="a">1</td>
<td class="b">2</td>
<td class="r">3</td>
<td class="b">4</td>
<td class="b">5</td>
<td class="b">6</td>
<td class="a">7</td>
<td class="b">8</td>
<td class="b">9</td>
and the tooltip text set elsewhere, but displayed on mouseover depending on which td class was set.
I feel I'm explaining this really badly.
Here is a snippet of my CSS using "t" as a test class, just in case you need it. Please don't worry about the formatting or positioning of the tooltip yet, I can fix that easily enough if I can get it working how I want:
.t { color: #FFFFFF; background-color: #FFA500; font-size: 12px; text-align: center; title:"Example";}
.t:hover .tooltiptext{ visibility: visible; }
.t .tooltiptext {visibility: hidden; width: 120px; background-color: black; color: #fff; text-align: center; border-radius: 6px; padding: 5px 0; position: absolute; z-index: 1; }
and the relevant piece of HTML:
<tr>
<td class="t">1<span class="tooltiptext">Test Message</span></td>
<td class="b">2</td>
<td class="b">3</td>
<td class="b">4</td>
<td class="b">5</td>
<td class="b">6</td>
<td class="a">7</td>
</tr>
So, in the above, can I relocate the span somewhere else so it only appears once, and is referenced depending on which td class is defined, and have 2 other spans with different messages, which are defined by the td class "a" and "b"?
An ideal solution to this would be something I can do in the CSS like this:
.t .tooltiptext {custom-text: "This text will display on hover";
visibility: hidden;
width: 120px;
Etc...
}
TL;DR Is there a 'CSS only' way of making the tooltip text display different text by only changing the td class?
Unfortunately in pure CSS you can't
relocate the span somewhere else (only in Javascript, Jquery, etc etc)
But if each td with a specific class has a span element you can display different text in this way:
span {
display:none;
/*Etc etc*/
}
td:hover span {
display:inherit;
}
.a span:after {
content: 'something about class A';
}
.b span:after {
content: 'something about class B';
}
<table>
<tr>
<td class="a">1<span></span></td>
</tr>
<tr>
<td class="b">2<span></span></td>
</tr>
<tr>
<td class="a">3<span></span></td>
</tr>
</table>

Absolute Div top position changed while zoom ( Ctrl + ) in chrome browser

I have problem with absolute positioning DIV over the table element. I have a DIV that’s set the position absolute and set the top position to display the exact place. Now what happened in chrome browser while zooming (ctrl +) the DIV position has been changed at zoom level 125, 150, 175 ... etc. But Zoom level 100,200, 300… (Multiple of 100) it’s displayed the same position. The problem was other than the multiple of 100 zoom level the DIV position changed. How can I fix this issue ?
I have created the sample page in jsfiddle - demo . please run the page in chrome browser and zoom the browser ( ctrl + ) the red color DIV position will be change, this is the issue. I really hope someone find a solution for this.
HTML :
<div class="container">
<table width="700px" class="custom">
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
<div>
<div class="apptest"> </div></div>
CSS :
table
{
border-collapse:collapse;
}
.custom tr td
{
height:20px;
border:1px solid;
background-color:White;
}
.container {
position: relative;
}
.apptest
{
height:70px;
width:400px;
position:absolute;
top:185px;
left:0px;
background-color:Red;
}
Link : http://jsfiddle.net/mJcsb/5/
Use a container with a style like this;
.Container {
margin-right: auto;
margin-left: auto;
width: 500px;
}
I'm not going to debate whether tables are a poor choice or not these times. But an absolute positioning here is a pretty bad idea.
I don't know what you have to do and what is your aim, but you could have a different (and probably better) solution using divs; in that case, a div containing your "red" div would just.. contain it, heh!
If you want to go anyway with absolute positioning and tables, be aware that this is a dirty solution and could break anytime. In that case, I'd suggest you to go with percentage-based absolute positioning, so that the box flows with the zoom (that is, by the way, difficult to predict and normalize in every browser).
i.e.
.apptest
{
height:70px;
width:400px;
position:absolute;
top:61.2%;
left:0px;
background-color:Red;
}
A fork of you fiddle with percentage for absolute positioning (POOR SOLUTION WARNING HERE): http://jsfiddle.net/U4TGd/
Keep in mind that, again, this is a bad solution and mixing percentages and pixels in often a bad idea. If you have time or possibility, convert your table-based design and use divs instead of tabs.
Its not the div position which was changing, the one which our eye relates the div position was changing(in this case the table border of each cell).
I found out this with some testing,
use this css to know that the absolute position div is in exact position.
.custom tr td {
height:20px;
border:0px solid;
}
.container {
position: relative;
height:185px;
background:#0F6;
}
.apptest {
height:70px;
width:400px;
position:fixed;
top:185px;
left:0px;
background-color:Red;
}
So you have no problem with absolute positioning DIV, but maybe chrome rendering the table cells differently.

Mozilla border-radius in a table not working consistently

Driving myself nuts here!.
Firstly can I just clarify that it is no longer necessary to prefix border radius eg with -moz-. But is it good practice to do so in case an old browser is employed?
Secondly I accept that in employing a border radius inside a table demands that border-collapse is not collapse I also believe that border-spacing should not be 0.
The following draft CSS & HTML creates nicely rounded table elements in all browsers except mozilla where for some reason the table is rounded the th is rounded BUT the td's are all square.
Fire bug reports that the radius is applied. Indeed if I place a background colour on td I can see that this background is rounded. But it still displays the remainder as square.
Any thoughts ???
/* borders */
#booking_Form_Wrapper{
border: 0px;
padding: 0px;
margin: 0px;
}
#booking_Table{
width: 300px;
height: 400px;
background-color: #a5a5a5;
border-radius: 14px;
border-spacing: 6px 6px;
}
#booking_Table th{
border-radius: 10px;
}
#booking_Table td{
border-radius: 10px;
}
/* other styles */
HTML
<table id="booking_Table">
<thead id="booking_Title">
<th>
Booking
</th>
</thead>
<tbody>
<tr id="booking_Session">
<td>
<a>Class - Level</a><br />
<a>Day and Date</a><br />
<a>Start Time - End Time</a>
</td>
</tr>
<tr id="booking_XXXXXXX">
<td style="border-radius: 6px;">
<label>Do you want to XXXXXXXX</label><input type="checkbox"/>
<label>XXX</label><input type="radio" name="XXX" value="b">
<label>XXX</label><input type="radio" name="XXX" value="s">
<label>XXX</label><input type="radio" name="XXX" value="r">
</td>
</tr>
<tr id="booking_Cancel">
<td>
<P><span>Cancellation Policy</span> - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</P>
</td>
</tr>
<tr class="form_Footer">
<td>
<input class="form_Submit" type="submit" name="submit" value="Make Booking"/>
<input class="form_Cancel" type="cancel" name="cancel" value="Cancel"/>
</td>
</tr> <!-- form footer -->
</tbody>
</table> <!-- booking table -->
Here is the firebug computed style info for the first square td
I found the solution - I may not be stating this in the correct technical terms but the effect was caused in FF by giving the containing element a height. In my case the <tr>. The interesting thing is that none of the other browsers complain about this and round the <td> regardless. I think that this is connected to the mozilla developer notes which say that the radius is applied to the background of the element where the radius is applied regardless of whether a border is specified or not. The <tr> was not part of the background and so was not rounded.
Anyway don't give the container a height and everything good.

Showing the JSF Error Messages

I am using JSF Myfaces Impl 1.2 without tomahawk and other libs :
I am using different styles + images to show JSF Error messages, find below a sample.
<h:panelGroup rendered="${adminBean.showErrorIcon==2}">
<table width="375" align="center" class="InfoMsg" border="1"
cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="375" align="center" class="InfoMsg" border="0">
<tr>
<td width="50"><img src="static/images/info_icon.gif"
width="40" height="40" border="0" /></td>
<td width="325" align="left"><h:messages layout="table"
errorClass="InfoMsg" /></td>
</tr>
</table>
</td>
</tr>
</table>
Based on the int variable of the Backing Bean , I am displaying a diff image and the corresponding FacesMessage(s) in the screen - only 2 cases - error or an information.
I am using the below code to set the variable of the Backing Bean
//Checking if there are messages!
log.debug("Checking if there are messages to be shown ]");
if(getShowErrorIcon()==99){//Set only if the value is still the default :
log.debug("getShowErrorIcon was DEFAULT - Changing it ]");
Iterator<FacesMessage> messages = FacesContext.getCurrentInstance().getMessages();
if(messages != null && getShowErrorIcon()==99){//Set Error/Info for messages that are not added here :
while(messages.hasNext()){
log.debug("There are ***messages***");
FacesMessage aMessage =(FacesMessage) messages.next();
if(aMessage.getSeverity().compareTo(FacesMessage.SEVERITY_ERROR)==0){
setShowErrorIcon(1);
break;//just once is enough
}
if(aMessage.getSeverity().compareTo(FacesMessage.SEVERITY_INFO)==0){
setShowErrorIcon(2);
break;
}
}
}
}//if it is not default, then something has been set already, why again?
Now the problem I have is , There are FacesMessage(s) that are added by the MyFacesImpl - like the required=true and the custom validator messages which are added during PROCESS_VALIDATION Phase, These are not shown in the screen since my integer variable of the Backing Bean is not set , and since the INVOKE_APPLICATION Phase was not called (and that means the above code was not called!!!)
How do I resolve this? Or Whats the best way / Where's the best place to place the above checking code ?
Appreciate your help.Thanks!
I'm not sure, but this all look like unnecessarily overcomplicated. To change icons/styles based on the message severity, just make use of the CSS powers. You can specify different CSS classes based on message severity using infoClass and errorClass attributes of the <h:messages> and you can specify the icons as CSS background image.
JSF:
<h:messages id="messages" layout="table" infoClass="info" errorClass="error" />
CSS:
#messages .info td {
background: url('info.gif') no-repeat left center;
padding-left: 15px;
}
#messages .error td {
background: url('error.gif') no-repeat left center;
padding-left: 15px;
}
The <h:messages layout="table"> itself already renders a HTML <table>. I think the whole table around it is unnecessary as well. Just apply styles accordingly the usual CSS way.
#messages {
width: 375px;
margin: 0 auto;
border: 1px black solid;
border-collapse: collapse;
}
See also:
W3schools CSS tutorial/reference
CSStutorial.net CSS tutorial
Update: as per the comments, you're looking for something like this:
<h:messages layout="table" styleClass="messages info" infoClass="info" errorClass="error" />
<h:messages layout="table" styleClass="messages error" infoClass="info" errorClass="error" />
with CSS:
.messages {
width: 375px;
margin: 0 auto;
border-collapse: collapse;
border: 1px black solid;
}
.messages.info {
background: url('info.gif') no-repeat left center;
}
.messages.error {
background: url('error.gif') no-repeat left center;
}
.messages.info tr.error, .messages.error tr.info {
display: none;
}
.messages td {
padding-left: 15px;
}
This shows two separate message tables, one for info and other for error messages, each with a single icon on the left center.

Resources