View Full Version : Problem converting table with no fixed width to CSS

11-01-2008, 06:22 AM
I am attempting to convert a Web site to CSS from a tables layout, and I've run into a problem that's driving me nuts. Below is a screen capture of a simple table.


The code for the table is:

<table border="0" align="center" cellpadding="0" cellspacing="0">
<td align="right" style="padding-right:7px"><img src="images/florish_left.gif" alt="" width="45" height="25"></td>
<td align="center" nowrap><span class="verdana20px-red">Page Title </span></td>
<td align="left" style="padding-left:7px"><img src="images/florish_right.gif" alt="" width="45" height="25"></td>

As you can see, the table is centered on the page, and both the table and center cell do not have a fixed width. This is so that the center cell will resize automatically to fit the contents.

And that's the reason for the problem I'm having with duplicating this in CSS. If that center area had a fixed width, there would be no problem.

So, in summary, this is what the CSS needs to do:

Horizontally center the group of objects on the page.

Center the page title between the two images.

Enable the center "container" to resize automatically to fit the contents.

Works in both IE and other browsers.

If anyone can figure this out, I'd really appreciate it. With tables, this is so simple, but, with CSS, I just can't find the way to do it.

If there was a way of vertically aligning images in relation to text so that I'd get the same result, I wouldn't even bother with CSS for this, but there isn't.

11-01-2008, 09:34 AM
Hm, a simple solution (without knowing the context) could be something like this:

<h1><span>Page Title</span></h1>

h1 {
padding-left: 50px;
background: url(left image) left center no-repeat;
h1 span {
display: block;
padding-right: 50px;
background: url(right image) right center no-repeat;

However, there are different approaches to this depending on the overall code layout/context.
And you might have to play around with the height of the span.

11-01-2008, 08:05 PM
Thanks, VIPStephan, but that didn't work. What ended up happening is that the graphics appeared all the way to the left and right-hand sides of the page rather than beside the text. I played with it for a while to see if I could fix it but had no luck. I am doing my tests on an otherwise blank page, so there isn't any other code that would be affecting its behavior.

What with all the hours I've wasted on this one little thing, I'm afraid that, unless somebody can resolve this, I'm ready to admit defeat and leave that one element as a table. (Yes, I can hear the CSS purists out there issuing a collective gasp of horror.) I'd rather do that than change the page design and eliminate the images.

11-01-2008, 08:40 PM
Something like this might work for you

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
h1 {
font-family:Verdana, Geneva, sans-serif;
h1 #florish_left {
h1 #florish_right {
<h1><span id="florish_left"></span>Page Title<span id="florish_right"></span></h1>

11-02-2008, 01:27 AM
Thank you, but I'm afraid that didn't work either. The container holding the text goes the entire width of the page, and the two graphics are completely off the page.

The problem is the way that CSS handles containers that are horizontally centered and have no fixed width. In that situation, it wants to expand the container to the available width of the page (or whatever else might be containing it), and there doesn't seem to be a way to stop it from doing that. :(