Creating Side-by-side Comparison Table

Hello all,:cool:

I made a new design for a side-by-side comparison table. I uploaded the code to a test page before implementing it in the landing pages. There are a couple of things I didn’t quite figure out yet, though.

  1. Properly hide the product name/logo text behind the image, only to be displayed when images are turned off.
    **make the text align nicely and vertically even

  2. Fix the graph so it doesn’t shrink from the left side. When I apply a percentage width to one of the bar images, the graph shrinks from the left, which is obviously backwards.


<h1>Creating a New Table</h1>
							<div class="tablewrap">
                                <table class="sidebysidecomparison">
                                    <tr>
                                        <th colspan="3">Comparison</th>
                                    </tr>
                                    <tr>
                                    	<td class="catcolumn"></td>
                                    	<td class="firstrowtop">
                                        	<p class="prodname">Guitar Tricks</p>
                                            <img src="guitartrickslogo.jpg" title="Guitar Tricks" alt=" " width="140" height="40" />
                                        </td>
										<td class="firstrowtop">
                                        	<p class="prodname">Jamorama</p>
                                            <img src="jamlogo.jpg" title="Jamorama" alt=" " width="130" height="95" />
                                        </td>
                                    </tr>
                                    <tr>
                                    	<td class="catcolumn firstcolleft">Overall</td>
                                        <td class="firstrowbottom firstcolright">
                                            <div class="xgraph">
                                            	<div class="horizbar" id="guitartricksoverall2"></div>
                                                <div class="xaxis"></div>
                                            </div>
                                            <div class="ratingnumber">9.0</div>
                                        </td>
                                        <td class="firstrowbottom">
                                            <div class="xgraph">
                                            	<div class="horizbar" id="guitartrickslayout1"></div>
                                                <div class="xaxis"></div>
                                            </div>
                                            <div class="ratingnumber">8.5</div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="catcolumn firstcolleft">Features</td>
                                        <td class="firstcolright">
                                        	<div class="xgraph">
                                            	<div class="horizbar" id="guitartrickslayout1"></div>
                                                <div class="xaxis"></div>
                                            </div>
                                            <div class="ratingnumber">8.2</div>
                                        </td>

                                        <td>
                                            <div class="xgraph">
                                            	<div class="horizbar" id="guitartrickslayout1"></div>
                                                <div class="xaxis"></div>
                                            </div>
                                            <div class="ratingnumber">7.5</div>
                                        </td>
                                    </tr>
                                    <tr>
                                    	<td class="catcolumn firstcolleft">User Interface</td>
                                        <td class="firstcolright">                                        	
                                            <div class="xgraph">
                                            	<div class="horizbar" id="guitartrickslayout1"></div>
                                                <div class="xaxis"></div>
                                            </div>
                                            <div class="ratingnumber">9.6</div>
                                        </td>

                                        <td>
                                            <div class="xgraph">
                                            	<div class="horizbar" id="guitartrickslayout1"></div>
                                                <div class="xaxis"></div>
                                            </div>
                                            <div class="ratingnumber">8.8</div>
                                        </td>
                                    </tr>
                                    <tr>
                                    	<td class="catcolumn firstcolleft">Video Content</td>
                                        <td class="firstcolright">
                                            <div class="xgraph">
                                            	<div class="horizbar" id="guitartrickslayout1"></div>
                                                <div class="xaxis"></div>
                                            </div>
                                            <div class="ratingnumber">8.9</div>
                                        </td>

                                        <td>
                                            <div class="xgraph">
                                            	<div class="horizbar" id="guitartrickslayout1"></div>
                                                <div class="xaxis"></div>
                                            </div>
                                            <div class="ratingnumber">9.0</div>
                                        </td>
                                    </tr>
                                    <tr>
                                    	<td class="catcolumn firstcolleft">Cost</td>
                                        <td class="firstcolright green">$12.50 per month</td>

                                        <td class="green">$10 per month</td>
                                    </tr>
                                </table>
                       		</div>

the styles:


/* 2nd table - horizontal graph comparison between 2 different products or services */
table.sidebysidecomparison {
    border-spacing:0;   /* border-spacing: is the equivalent of the cellspacing attribute only better. */
    border-left:2px solid #ccc;    /* specifiying border properties (esp. color) makes them cross-browser consistent... */
    border-top:2px solid #ccc;     /* the shading of border-style: inset, outset, groove, and ridge vary considerably between browsers */
    border-right:2px solid #999;
    border-bottom:2px solid #999;
    margin:0 auto;
    width:90%; /* adjusted for the table to wrap with the images and text */
	text-align:center;
	font-weight:bold;
}
.sidebysidecomparison th {     /* Styles the title bar */
    font-size:1.5em;
    font-family:Georgia,serif;
    padding:6px 0;
}
.sidebysidecomparison td.catcolumn {
	padding:3px 4px;
	font-family:Arial, Helvetica, sans-serif;
}

.sidebysidecomparison th,
.sidebysidecomparison td {    /* these borders are also applied to the cells in the .rating (inner) table. */
    border-left:2px solid #999;
    border-top:2px solid #999;
    border-right:2px solid #ccc;
    border-bottom:2px solid #ccc;
 /* FYI: if {padding:0;} were applied here, it would be the equivalent of the cellpadding="0" attribute except that it would apply to all cells in both tables. */
}
td.firstcolleft{text-align:left; min-width:5.5em; border-right:2px dotted #757575;}
td.firstcolright{border-left:2px dotted #757575;}
td.firstrowtop{border-bottom:2px dotted #757575;}
td.firstrowbottom{border-top:2px dotted #757575;}

.namelogo span{
	repeat:no-repeat;
	position:absolute;
	top:0;
	left:0;
}
p.namelogo{
	position:relative;
	width:100%;
	height:100%;
}

.xgraph {
    height:34px;      /* same as the colored bar and xaxis images */
	width:150px;
    position:relative;   /* creates a stacking context for the elements inside the .ratings table cells (because table cells cannot be positioned). */
    overflow:hidden;
}
.xaxis {
    position:absolute;
    left:0;
    top:0;
    right:0;
    bottom:0;
    background:url("xaxis.gif") no-repeat 100% 100%;   /* 180x240 */
}
.horizbar {
	width:100%;
    height:100%;
    position:absolute;
    right:0;    /* offsets the right edge of the colored bar */
    bottom:14px;
    background:url("horizbar.jpg") repeat-x 0 100%;
}
div.ratingnumber {text-align:center; font-weight:bold; padding:0; margin-top:3px;}
.prodname {
	font-weight:bold;
	position:absolute;
}

#guitartricksoverall2{width:80%;}

.green{color:#060;}
.bold{font-weight:bold;}

I appreciate your input.

Cheers,

Tyler

Hi, Tyler,

#2. Change “right” to “left”:


.horizbar {
    width:100%;
    height:100%;
    position:absolute;
    [color=red][s]right:0;[/s][/color]
    [color=blue]left:0;[/color]
    bottom:14px;
    background:url("horizbar.jpg") repeat-x 0 100%;
}

Ronpat,

This definitely solved the first issue. I’ll post back when I find the solution for hiding the text behind the image.

Thanks,

Ty

Tyler, give this a try and see how it works for you. You can move the CSS from the top of the page to your stylesheet. I don’t think there are any redundant properties, but you might want to double check.

I added <div class=“title”> inside .firstrowtop and a couple of break tags <br/> in the .green text.

As usual, there are a couple of outlines that you can enable to see how the boxes are arranged.

The method of vertically centering the text in .prodname is not bulletproof. It depends on the text being one line. If the text is two lines, {margin-top:-0.5em} will have to be adjusted.

It would be helpful (not essential) if the product images could be a uniform height and width, perhaps the same width as the graph.

At first, I noticed that the graph had no tolerance for someone zooming text-only larger, or otherwise using a larger font than expected. Adding the two <br/> tags cleared that up. Table cells tend to stretch wider to accommodate their contents. Wrapping text will sometimes push a cell wider than desired. <br/> tags avoid putting pressure on the sides of the cell.

See what you think:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="tablestyles.css" rel="stylesheet" type="text/css" media="screen, projection, tv" />
    <title>Testing Table 2</title>
    <style type="text/css">
table.sidebysidecomparison {
    position:relative;
}
.firstrowtop {
    vertical-align:middle;
    text-align:center;
}
.title {    /* NEW div. (change the classname to suit your page) */
    position:relative;
    z-index:1;
}
.title img {
/*    outline:1px solid red;  /* TEST Outline */
    display:block;
    margin:0 auto;
}
.title .prodname {
/*    outline:1px solid blue;  /* TEST Outline */
    position:absolute;
    top:50%;
    left:0;
    right:0;
    margin:-0.5em auto 0 auto;
    z-index:-1;
}
    </style>
</head>
<body>

<h1>Creating a New Table</h1>
<div class="tablewrap">
    <table class="sidebysidecomparison">
        <tr>
            <th colspan="3">Comparison</th>
        </tr>
        <tr>
            <td class="catcolumn"></td>
            <td class="firstrowtop">
                <div class="title">
                    <img src="guitartrickslogo.jpg" title="Guitar Tricks" alt=" " width="140" height="40" />
                    <p class="prodname">Guitar Tricks</p>
                </div>
            </td>
            <td class="firstrowtop">
                <div class="title">
                    <img src="jamlogo.jpg" title="Jamorama" alt=" " width="130" height="95" />
                    <p class="prodname">Jamorama</p>
                </div>
            </td>
        </tr>
        <tr>
            <td class="catcolumn firstcolleft">Overall</td>
            <td class="firstrowbottom firstcolright">
                <div class="xgraph">
                    <div class="horizbar" id="guitartricksoverall2"></div>
                    <div class="xaxis"></div>
                </div>
                <div class="ratingnumber">9.0</div>
            </td>
            <td class="firstrowbottom">
                <div class="xgraph">
                    <div class="horizbar" id="guitartrickslayout1"></div>
                    <div class="xaxis"></div>
                </div>
                <div class="ratingnumber">8.5</div>
            </td>
        </tr>
        <tr>
            <td class="catcolumn firstcolleft">Features</td>
            <td class="firstcolright">
                <div class="xgraph">
                    <div class="horizbar" id="guitartrickslayout1"></div>
                    <div class="xaxis"></div>
                </div>
                <div class="ratingnumber">8.2</div>
            </td>
            <td>
                <div class="xgraph">
                    <div class="horizbar" id="guitartrickslayout1"></div>
                    <div class="xaxis"></div>
                </div>
                <div class="ratingnumber">7.5</div>
            </td>
        </tr>
        <tr>
            <td class="catcolumn firstcolleft">User Interface</td>
            <td class="firstcolright">
                <div class="xgraph">
                    <div class="horizbar" id="guitartrickslayout1"></div>
                    <div class="xaxis"></div>
                </div>
                <div class="ratingnumber">9.6</div>
            </td>
            <td>
                <div class="xgraph">
                    <div class="horizbar" id="guitartrickslayout1"></div>
                    <div class="xaxis"></div>
                </div>
                <div class="ratingnumber">8.8</div>
            </td>
        </tr>
        <tr>
            <td class="catcolumn firstcolleft">Video Content</td>
            <td class="firstcolright">
                <div class="xgraph">
                    <div class="horizbar" id="guitartrickslayout1"></div>
                    <div class="xaxis"></div>
                </div>
                <div class="ratingnumber">8.9</div>
            </td>
            <td>
                <div class="xgraph">
                    <div class="horizbar" id="guitartrickslayout1"></div>
                    <div class="xaxis"></div>
                </div>
                <div class="ratingnumber">9.0</div>
            </td>
        </tr>
        <tr>
            <td class="catcolumn firstcolleft">Cost</td>
            <td class="firstcolright green">$12.50<br/>per month</td>  <!-- Use <br> tags to prevent text from wrapping -->
            <td class="green">$10<br/>per month</td>  <!-- Text that wraps pushes the cell wider and results in unequal column widths -->
        </tr>
    </table>
</div>

</body>
</html>

Okay. This seemed to be worthy of going ahead and transferring it into an actual page.

About the text aligning in the center, the text will likely occupy 2 lines at times. I haven’t been able to come up with a CSS solution for the logo images. It seemed to make sense just to have the images in the HTML. I guess the images are causing the uncertainty in the position of the underlying text.

Weird! :confused: I wonder what is causing those logo images to be tiny and not properly aligned when I transferred the code into the live page. It may be something colliding with the image styles .floatLeft and .floatRight in lp.css. I already had to add in a line of code for the table logo images to remove the border that was inherited from those float styles.

Everything else looks good with the table, though.

When the original page was designed, it was expected that images inside the floatRight and floatLeft containers would indeed be floated (thus the parent container classname). Adding nonfloated images within these containers requires negating some of the styles assigned to the floated images.

Add the blue styles to your stylesheet and see how they work for you.

NOTES: as noted, opacity was added as a TEST device (so you can see the .prodname text behind the image) and should be commented out or deleted from the active CSS file.

I changed the margin-top in .prodname from .5em to 1 em. That will render one line of text slightly above the middle of the cell, but should be quite acceptable. Two lines will be rendered slightly below the middle of the cell.

Again, I recommend adding some opaque white space around the images so they are the same width as .horizbar.jpg (150px). Additional height on shorter images would be a good idea, too, to prevent zoomed text from creeping over the edges. If the two images could be the same dimensions, that would be even better.


.logocontainer img {
    display:block;
    [color=blue]max-width:none;[/color]
    border:none;
    [color=blue]float:none;[/color]
    [color=blue]opacity:0.5;    /* {opacity:.5} for TESTING ONLY.  DELETE or comment out */[/color]
    margin:0 auto;
}
.logocontainer .prodname {
    font-weight:bold;
    position:absolute;
    top:50%;
    left:0;
    right:0;
    z-index:-1;
    [color=blue]margin:-1em auto 0 auto;[/color]
}


Yes, Ronpat! This definitely does the trick. I always learn to look for a lot more each time we figure these things out. In this case, I’ll be zooming in and out of the page to see how the elements behave. Also, the max-width on the images was reset from its value of 55% from .floatLeft and .floatRight

You mentioned white space around the images around to match the width of horizbar.jpg. I thought everything was the same width at 150 px. Each of the 10 horizontal graph notches are exactly 15 px apart. I don’t know if I fully understand what you mean. The table seems to behave very nicely now.

Hi, Ty.

Sorry I wasn’t clear about the .firstrowtop images.

The actual size of these two images is width="140" height="40" and width="130" height="95".

What I meant to suggest is that you use your paint program to increase the dimensions of these images so they are both width="[color=blue]150[/color]" height="[color=blue]95[/color]".

I’m not suggesting that you scale these images larger, just that you add some “white area” around them in your graphics program so the overall images end up 150px wide and 95px high. Doing this will solve at least a couple of issues: (1) Right now, the pinstriped background is visible around the images (hard to see, but it is :slight_smile: ); if both are the same dimensions, no pinstripes will be seen. (2) There will be no opportunity around a short image for the hidden text in .prodname to peep around the edges of the image if the user’s font-size happens to be larger than you designed for or if the text takes up two or maybe three lines. Right now, the text “Guitar Tricks” is barely hidden.

Examples:

To this image,
<img src=“guitartrickslogo.jpg” title=“Guitar Tricks” alt=" " width=“140” height=“40” />
you would add 5px of opaque white to the left and right sides and 27px & 28px to the top & bottom edges to make it 150px wide and 95px tall.

To this image,
<img src=“jamlogo.jpg” title=“Jamorama” alt=" " width=“130” height=“95” />
you would add 10px of opaque white to the left and right sides and nothing to the top or bottom to make it 150px wide and 95px tall.

I hope this makes more sense. If it doesn’t, let me know and I’ll modify the images and put them in your dropbox to illustrate what I mean. It won’t take but a minute.

I have the images at 150 x 95 now. It looks great on the page now.

Cool. That’ll keep the text hidden behind the images. :slight_smile: