Jeffry Houser's Blog - CSShttps://www.jeffryhouser.com/index.cfm
Jeffry Houser's Blogen-usMon, 19 Nov 2018 16:55:15 -0700Thu, 15 Nov 2018 09:00:00 -0700BlogCFChttp://blogs.law.harvard.edu/tech/rssjhblog@farcryfly.comjhblog@farcryfly.comJeffry Houserjhblog@farcryfly.comJeffry HouserJeffry Houser's Bloghttps://www.jeffryhouser.com/index.cfm
noHow do I uppercase the first letter of a word with CSS?https://www.jeffryhouser.com/index.cfm/2018/11/15/How-do-I-uppercase-the-first-letter-of-a-word-with-CSS
I was working on a project, and during a Pull Request review someone had written a TypeScript function to capitalize the first letter of each word. I said "It looks good to me" but one of my colleagues said "Hey, why don't we use CSS for this."
"CSS can do this?" Said Jeffry, blinking surprised.
It can, and it is super simple to do. CSS provides a <a href="https://www.w3schools.com/cssref/pr_text_text-transform.asp">text-transform</a> property.
Try this text:
<code>
<div style="text-transform: capitalize;">the quick brown fox jumped over the lazy dogs</div>
</code>
<a href="https://plnkr.co/edit/IQCOvSS5EFjQCjzM4ZlC?p=preview">Play with the Sample</a>.
Sometimes I'm more surprised by the simple stuff I don't know than the complicated stuff.
ProfessionalCSSThu, 15 Nov 2018 09:00:00 -0700https://www.jeffryhouser.com/index.cfm/2018/11/15/How-do-I-uppercase-the-first-letter-of-a-word-with-CSSinfo@theflexshow.com (Jeffry Houser and John Wilker)How do I fix IE11 problems with CSS Calc and min-height?https://www.jeffryhouser.com/index.cfm/2017/10/10/How-do-I-fix-IE11-problems-with-CSS-Calc-and-minheight
I hate it when you have a problem that you cannot replicate in a simple example. That's exactly where I am. I'm working on an application built with HTML, CSS, and various JavaScript frameworks. The application requires a footer to be aligned at the bottom of the page. If the content is too large for the page, then the the footer should show up under the content. But, if the content is too small for the page, the footer should show up at the bottom of the window, or viewport.
This should be pretty simple to build using CSS and HTML:
<code>
<div class="wrapper">
Lots of Main Content and navigation and headers Here
</div>
<footer>
Some Footer Information Here that should always be at the bottom of the page
</footer>
</code>
The CSS would be something like this:
<code>
html, body {
height: 100vh;
margin : 0;
}
.wrapper {
min-height: calc(100% - 200px);
}
footer {
height : 200px;
background-color : blue;
}
</code>
The actual client project code is a lot more complex, but this gives you the gist. <A href="https://plnkr.co/edit/QA791p1dM1Yf6Jfa0SPj?p=preview">Play with the code here</a>. Ignore my design skills.
The problem I was having was that IE11 seemed to have a problem with the min-height. When clicking in the page, or clicking a link to go to another page, it was as if the wrapper's min-height would shrink down on pages where the view height was greater than the actual content. This would cause the footer to jump to the middle of the page.
For the life of me, I haven't been able to create a simple sample to demonstrate this. Some part of the client's custom code seems to be causing this.
After some head banging and conferring with my team, I came up with this solution. It makes use of JavaScript and JQuery to 'hard code' the min-height on the wrapper. Instead of using the CSS Calc. this happens when the page loads and whenever the page is resized.
<code>
if(/MSIE \d|Trident.*rv:/.test(navigator.userAgent)){
function onResize(){
/* The jquery calc code */
$('.wrapper').css('min-height', '100%').css('min-height', '-=200px');
}
$(window).resize(function() {
onResize()
});
$(window).ready(function(){
onResize()
});
}
</code>
I used a <a href="https://stackoverflow.com/questions/29987969/how-to-load-a-script-only-in-ie">regex trick</a> to only execute the code for IE browsers. And I used <a href="https://stackoverflow.com/a/21245509/133840">this answer </a> as a base for my solution.
Part of our problem solving this was my inability to create a simple reproducible case, but pouring over thousands of line of code I could not find the magic style combination that caused the 'footer jump' problem.
Frustrating; but the JS code above seems to solve the issue admirably.
JavaScriptProfessionalCSSTue, 10 Oct 2017 10:00:00 -0700https://www.jeffryhouser.com/index.cfm/2017/10/10/How-do-I-fix-IE11-problems-with-CSS-Calc-and-minheightinfo@theflexshow.com (Jeffry Houser and John Wilker)How do I Extend a Background Color the Full Height of a Div with CSS?https://www.jeffryhouser.com/index.cfm/2017/8/11/How-do-I-Extend-a-Background-Color-the-Full-Height-of-a-Div-with-CSS
Last week <a href="https://www.jeffryhouser.com/index.cfm/2017/8/4/Can-I-create-an-HTML-Background-with-an-inline-Image">I used CSS to tile</a> a graphic across the whole width of a page. The purpose was to extend a header bar's color when the page scrolled right beyond the iniital viewport.
Now, with the same project I wanted to extend the left nav to the full height of the page. I couldn't use the same trick as you can't tile two separate background images.
This is still doable with some CSS. First, start the HTML Body:
<code>
<body>
</body>
</code>
We want the body to be the height of the view area:
<code>
body {
height : 100vh;
}
</code>
This sets the body to 100% height of the view area.
Now create our content wrapper div inside the body:
<code>
<div class="flex">
</div>
</code>
This code uses FlexBox for display:
<code>
.flex {
display : flex;
height : auto;
min-height : 100%;
}
</code>
It also contains a trick. The height is set to auto and the min-height is set to 100%. That, combined with the body's height of 100vh will extend this div through the full height of the page.
Finally, create our left nav bar inside our Flex div:
<code>
<div class="somebar">
Some Text and other things
</div>
</code>
This is styled with a specific width, but no specific height. I also specified the color
<code>
.somebar{
width : 150px;
background-color:blue;
color : white;
}
</code>
Check out the <a href="http://www.plnkr.co/edit/urLF2rNVru4uX71K">code here</a>.
I've been doing a lot of HTML CSS work for a client, but I'm working on some longer programming based articles which will be coming out soon.
ProfessionalCSSFri, 11 Aug 2017 06:19:00 -0700https://www.jeffryhouser.com/index.cfm/2017/8/11/How-do-I-Extend-a-Background-Color-the-Full-Height-of-a-Div-with-CSSinfo@theflexshow.com (Jeffry Houser and John Wilker)Can I create an HTML Background with an inline Image?https://www.jeffryhouser.com/index.cfm/2017/8/4/Can-I-create-an-HTML-Background-with-an-inline-Image
I'm working on a site for some clients, and one of their complaints was that the left nav bar was not extending the full height of the page. The nav div was set to expand to its content, which meant it stopped when it ran out of content. On some pages it looked fine, on others the nav bar ended too early. As a programmer, I don't often deal with design issues like this, so I pulled in the project's designer and we put our heads together to find a solution.
First, the problem was very generically <a href="http://plnkr.co/edit/rz7ybmq9DwbZWzJ5Q27Y?p=preview">like this</a>:
<code>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
margin : 0px;
}
.nav{
background-color : #0000FF;
width : 200px;
height : 50%;
color : #ffffff;
}
.nav a {
color : #ffffff;
}
</style>
</head>
<body>
<div class="nav">
Some info in the nav bar<br/>
<A href="">Some Link</A>
</div>
</body>
</html>
</code>
Our code was much more complicated, using Flexbox for complicated layouts, but this is simple enough example to demonstrate the problem. We were not able to use a simple height:100% in CSS because some parent containers used Flexbox styling and did not stretch the full height of the page.
My designer friend recommended tiling a background image. We can change the CSS for the body tag to something like this:
<code>
body {
margin : 0px;
background: top left url(blue1x200.png) repeat-y;
}
</code>
The blue1x200.png is an image with just the color blue in it which has a height of 1 pixel and a width of 200 pixels. The repeat-y clarification tells the browser to repeat this image on the y axis, meaning up and down.
This solved our issue, so whatever was happening to the page nav or the page content it would not prevent the left 200 pixels on the page from showing up the same color as the background.
Using the url attribute to the background CSS will force the page to spawn another HTTP request to load the image. My designer had a trick for that too. He converted the image to a Base64 string representation and replaced the URL:
<code>
background: top left url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAABCAIAAAAU3Xa1AAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgug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tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAABhJREFUeNpiZGD4zzAKRgG1AQAAAP//AwBYegEBJ5aHWAAAAABJRU5ErkJggg==') repeat-y;
</code>
The encoded image looks like a lot of gobblygook, but the browser treats it as an image without having to make a new request to load something from the server. Check <a href="http://plnkr.co/edit/Tp5BbTOiYQUmVAJRNQtp?p=preview">out the code</a>.
<a href="https://www.browserling.com/tools/image-to-base64">You can use a site like this to convert your image toBase64</a>.
If you've been doing Web Development for a long time, this sort of technique is probably not new to you, however I had never seen someone encode the images and include it in-line before. It's a cool technique.
ProfessionalCSSFri, 04 Aug 2017 11:05:00 -0700https://www.jeffryhouser.com/index.cfm/2017/8/4/Can-I-create-an-HTML-Background-with-an-inline-Imageinfo@theflexshow.com (Jeffry Houser and John Wilker)How do I right align a div inside a div?https://www.jeffryhouser.com/index.cfm/2017/7/6/How-do-I-right-align-a-div-inside-a-div
I was working with a client to create a specific layout on the page and I wanted to align a div inside another div. But, I couldn't use text-align because I didn't want to right align the text elements in the inner div.
How do you do it?
First, create the outer div and inner div:
<code>
<div class="outerDiv">
<div class="innerDiv">
This is Text in the inner div<br/>
Some other Text
</div>
</div>
</code>
A simple div is inside another div, and the inner div has some text. The outer div's only purpose is a wrapper for positioning purposes. Both the outerDiv and innerDiv have CSS Styles attached.
This is the CSS for the outerDiv:
<code>
.outerDiv {
display: flex;
float : right;
}
</code>
It enables the outerDiv to use flexbox styling and floats the content to the right. Flexbox is an advanced way to position CSS elements.
The innerDiv doesn't need any special CSS styling to make this work, but let's give it a background color:
<code>
.innerDiv{
background: #e6e6e6;
}
</code>
<a href="http://plnkr.co/edit/ptdteuuTe6esV45ntSv5?p=preview">Play with the code here</a>.
The implementation is really simple once you figure it out; but sometimes getting there is a stumble.
ProfessionalCSSThu, 06 Jul 2017 09:00:00 -0700https://www.jeffryhouser.com/index.cfm/2017/7/6/How-do-I-right-align-a-div-inside-a-divinfo@theflexshow.com (Jeffry Houser and John Wilker)Aligning Left Text, Center Text, and Right Text with CSShttps://www.jeffryhouser.com/index.cfm/2016/10/4/Aligning-Left-Text-Center-Text-and-Right-Text-with-CSS
I was building out an application for a client who wanted pagination on some tabled data. I needed to create a pagination bar that included a previous button on the left, a next button on the right, and a message in the center. In the old days I could implement something like this using tables, however I wanted to see if there was a CSS way to get the same layout. I found two separate, but great, implementations of this. This blog post will explain both of them.
<h2>Aligning Text with Float</h2>
My first attempt to implement this was to use the CSS float property. The float means that text moves out of its normal place in the container, usually moving to the left or right of the container. I could float some text to the right, some text to the left and keep some in the middle. Here is the CSS Style for left aligned text:
<code>
.leftAligned {
float : left;
}
</code>
This puts left aligned text to the left side of the div to contain our pagination header. Right aligned text is similar:
<code>
.rightAligned{
float : right;
text-align : right;
}
</code>
The float argument is specified as right so the rightAligned block will move to the right of the container. I also specified a text-align property to move the text all the way over to the right within the rightAligned container.
Finally, we need centered text:
<code>
.centeredText {
margin: 0 auto;
text-align : center;
}
</code>
This margin property is used to make sure that the centeredText can align right up against the right and left segments.
Use these in HTML:
<code>
<div>
<div class="leftAligned">Previous/div>
<div class="rightAligned">Next</div>
<div class="centeredText">Displaying 10-20 of 50</div>
</div>
</code>
Reviewing the code, you need to put the left and right aligned divs first, and the centered text last. This bugged a bit of my OCD, but worked almost perfectly.
<a href="http://plnkr.co/edit/zKRB0p2gxxZpYJyg30Iq?p=preview">Play with the code here</a>. The Plunker sample uses some Angular code to simulate the forward and next navigation for sample purposes.
As the user was paginating through the data the previous and next links might disappear. When that happened the centered text would change spots. This wouldn't do. We could fix that by adding explicit widths to each div, which worked for <a href="http://plnkr.co/edit/ajE5AzsvBer9Ym9qQcHh?p=preview">the sample application</a>. However my real world app was having problems with that, I believe due to other CSS conflicts. So, I went searching for a second way to accomplish this layout.
<h2>Aligning Text with CSS Tables</h2>
My second approach to was to use CSS Tables. You can use the display property in CSS to specify table, or table row or table cell.
First, create a table:
<code>
.table {
display:table;
width : 100%;
}
</code>
The table CSS style specifies the display type as table and width of 100%. This parallels the HTML table tag.
Next, create a table row:
<code>
.tr {
display:table-row;
width : 100%;
}
</code>
The table row specifies the display type as table-row. This parallels the HTML tr tag.
Now, the left-aligned text:
<code>
.leftAligned {
display:table-cell;
width : 25%;
}
</code>
The left aligned text specifies table-cell as the display type. The width is given as 25%. Next, the right aligned cell:
<code>
.rightAligned {
display:table-cell;
text-align : right;
width : 25%;
}
</code>
The right aligned table cell specifies table-cell as the display. It also right aligns the text with the text-align property and specifies the cell width as 25%.
Finally, create the centered text:
<code>
.centeredText {
display:table-cell;
text-align : center;
width : 50%;
}
</code>
The centered text also has a table-cell type. It also specifies the text-align to center the text; and the width is 50%. The three table cells have a combined width of 100%.
Finally, we need to create the table in the HTML. We'll use divs as the controllers. First, create the table div:
<code>
<div class="table">
</div>
</code>
Inside of that, put a table row:
<code>
<div class="tr">
</div>
</code>
Now put the main content inside the table row:
<div>
<div class="leftAligned" >Previous</div>
<div class="centeredText">Displaying 11-20 of 50</div>
<div class="rightAligned" >Next</div>
</div>
<a href="http://plnkr.co/edit/3JTONi1wduqijuHWRrTS?p=preview">Play with the Code Here</a>. As with the previous sample, this uses some AngularJS magic to make the forward and next buttons work.
<h2>Final Thoughts</h2>
I was surprised at how hard it was to find resources to explain how to do this, so hopefully this helps someone. Both approaches work well, depending what you're doing. The limitation of the second approach--which is specifying table widths--is that if you have text that is expanding or contracting to unknown widths you may have odd layouts as the text grows beyond their containers. But, I'm sure that can be worked around if you run into the problem.
<form action="https://www.jeffryhouser.com/MailingList/MailingListSignup.cfm" method="post" >
<div style="background-color:#3d4dcb;color:#ffffff;font-size:28px">
<table background="">
<tr>
<td colspan="2"><b style="color:#ffffff;font-size:28px">Sign up for DotComIt's Monthly Technical Newsletter</b></td>
</tr>
<tr>
<td><label for="mce-FNAME" style="color:#ffffff">First Name </label></td>
<td><input type="text" value="" name="nameField" class="" id="mce-FNAME"></td>
</tr>
<tr>
<td><label for="mce-EMAIL" style="color:#ffffff">Email Address <span class="asterisk">*</span></label></td>
<td><input type="email" value="" name="emailField" class="required email" id="mce-EMAIL"></td>
</tr>
<tr>
<td>
<td>
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
</td>
</tr>
</table>
</div>
</form>
ProfessionalCSSTue, 04 Oct 2016 09:00:00 -0700https://www.jeffryhouser.com/index.cfm/2016/10/4/Aligning-Left-Text-Center-Text-and-Right-Text-with-CSSinfo@theflexshow.com (Jeffry Houser and John Wilker)Make a two column layout in Bootstraphttps://www.jeffryhouser.com/index.cfm/2016/7/5/Make-a-two-column-layout-in-Bootstrap
Multi-column layouts are a common requirement when building building HTML web sites or applications. In the old days, we would just use an HTML table and be done with it. But, these days using CSS for layout is the preferred approach. Using HTML tables for layout is considered a bad idea. Bootstrap provides an easy way to create a two column layout.
<h2>Create the two column layout: The Old Way</h2>
If I were using HTML tables to create a two column layout, I'd do something like this:
<code>
<table style="width:100%">
<tr>
<td>Label</td>
<td><input type="text" /></td>
</tr>
<tr>
<td>Some Other Label</td>
<td><input type="text" placeaholder="second text" /></td>
</tr>
</table>
</code>
This is an HTML table with two rows, and two cells in each row. This is simple, but the HTML can get complex if you are nesting tables to get specific layouts. When I started building HTML sites; this was the defacto standard for complex layouts.
<img src="https://www.jeffryhouser.com/images/TableLayout.png">
<a href="https://plnkr.co/edit/QBVht8cAJGa5gqjlDuPI?p=preview">Play with this sample</a>!
Nowdays, CSS is considered superior for layout purposes than using lots of nested tables, and Bootstrap is a great framework to help you do that.
<h2>Import Bootstrap</h2>
The first step is to import the Bootstrap library into your HTML page. Bootstrap is primarily a CSS library, but also has a JavaScript portion. For the purposes of this article, we just need the CSS:
<code>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" >
</code>
Now all of the Bootstrap CSS is available to our application.
<h2>The Bootstrap Grid System</h2>
Bootstrap includes styles for a grid system consisting of rows and up to 12 columns. These are the associated styles:
<ul>
<li>row</li>
<li>Col-md-1</li>
<li>Col-md-2</li>
<li>Col-md-3</li>
<li>Col-md-4</li>
<li>Col-md-5</li>
<li>Col-md-6</li>
<li>Col-md-7</li>
<li>Col-md-8</li>
<li>Col-md-9</li>
<li>Col-md-10</li>
<li>Col-md-11</li>
<li>Col-md-12</li>
</ul>
The first style, row, is used to dictate a row in the grid. Inside the row; you would use some combination of the column styles to dictate the length of your cell; across a 12 column row. The col-md-1 style would span across a single column. The col-md-6 style would span across 6 columns. The col-md-12 style would spread across 12 columns, or a whole row. When putting together layouts with this approach, I like to make sure the total number of cells matches 12 for each row.
<h2>Create the two column layout: With Bootstrap</h2>
Bootstrap styles can be used to create a similar layout to the one created earlier, with a table. First, create the Bootstrap row:
<code>
<div id="row">
</div>
</code>
Inside the row, we can create two separate columns. For the purposes of this article, both will use col-md-6, meaning each column will span 6 cells, totaling 12 cells:
<code>
<div class="col-md-6">
Label
</div>
<div class="col-md-6">
<input type="text" />
</div>
</code>
The reason for making sure that the total number of columns used is equal to 12 is so that the next row will be placed under the first row; instead of next to it.
We can use the same approach for the second row:
<code>
<div id="row">
<div class="col-md-6">
Some Other Label
</div>
<div class="col-md-6">
<input type="text" placeaholder="second text" />
</div>
</div>
</code>
<img src="https://www.jeffryhouser.com/images/02Bootstrap2ColumnLayout.png">
<a href="https://plnkr.co/edit/pUxzMUxcjpNYWdihW5jp?p=preview">Play with the code here</a>
<h2>Final Thoughts</h2>
The Bootstrap Grid system can be very powerful, especially when dealing with nested layout elements.
ProfessionalCSSBootstrapTue, 05 Jul 2016 09:00:00 -0700https://www.jeffryhouser.com/index.cfm/2016/7/5/Make-a-two-column-layout-in-Bootstrapinfo@theflexshow.com (Jeffry Houser and John Wilker)How do I display hidden text in my table on rollover using CSS?https://www.jeffryhouser.com/index.cfm/2015/11/3/How-do-I-display-hidden-text-in-my-table-on-rollover-using-CSS
I was building out an app for a client and they had some wireframes that showed a list of users. The wireframes had a bunch of user data; but the client wanted some of the data hidden until the user rolled over the table row. How do I do that? CSS is the answer.
First, create a CSS class:
<code>
#tableWithHiddenData{
}
</code>
Now, create a style for hidden data:
<code>
#tableWithHiddenData .rollOverText{
display:none;
}
</code>
The <a href="http://www.w3schools.com/css/css_display_visibility.asp">display CSS element</a> is used to control layout. By giving it the value of none; the information will, essentially, be hidden.
Next, we'll need some CSS to display the hidden text on hover:
<code>
#tableWithHiddenData tr:hover .rollOverText{
display:block;
}
</code>
These are the three CSS elements that are needed, now lets create the table. Since, for my use case, I was displaying user data, our table will contain two columns. One for a user's name and one for the username. The a will always be displayed and a username that is only displayed on rollover:
<code>
<table id="tableWithHiddenData">
<tr>
<th>Name</th>
<th>UserName</th>
</tr>
<tr>
<td>Jeffry Houser</td>
<td><div class="rollOverText">jhouser</div></td>
</tr>
<tr>
<td>Someone Else</td>
<td><div class="rollOverText">someUser41</div></td>
</tr>
<tr>
<td>A Third User</td>
<td><div class="rollOverText">LuckyThird</div></td>
</tr>
</table>
</code>
<a href="http://plnkr.co/edit/FZGGUCzbKC7vxxBUcu3c?p=preview">Try this out on Plunkr</a>.
<form action="https://www.jeffryhouser.com/MailingList/MailingListSignup.cfm" method="post" >
<div style="background-color:#3d4dcb;color:#ffffff;font-size:28px">
<table background="">
<tr>
<td colspan="2"><b style="color:#ffffff;font-size:28px">Sign up for DotComIt's Monthly Technical Newsletter</b></td>
</tr>
<tr>
<td><label for="mce-FNAME" style="color:#ffffff">First Name </label></td>
<td><input type="text" value="" name="nameField" class="" id="mce-FNAME"></td>
</tr>
<tr>
<td><label for="mce-EMAIL" style="color:#ffffff">Email Address <span class="asterisk">*</span></label></td>
<td><input type="email" value="" name="emailField" class="required email" id="mce-EMAIL"></td>
</tr>
<tr>
<td>
<td>
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
</td>
</tr>
</table>
</div>
</form>
JavaScriptCSSTue, 03 Nov 2015 09:00:00 -0700https://www.jeffryhouser.com/index.cfm/2015/11/3/How-do-I-display-hidden-text-in-my-table-on-rollover-using-CSSinfo@theflexshow.com (Jeffry Houser and John Wilker)