Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem converting table with no fixed width to CSS

    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">
    <tr>
    <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>
    </tr>
    </table>

    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.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,700
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    Hm, a simple solution (without knowing the context) could be something like this:

    Code:
    <h1><span>Page Title</span></h1>
    Code:
    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.

  • #3
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Something like this might work for you
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    <style type="text/css">
    h1 {
    text-align:center;
    position:relative;
    font-size:20px;
    font-family:Verdana, Geneva, sans-serif;
    color:#F00;
    }
    h1 #florish_left {
    background:url(images/florish_left.gif);
    display:block;
    width:45px;
    height:25px;
    position:absolute;
    left:-52px;
    top:0;
    }
    h1 #florish_right {
    background:url(images/florish_left.gif);
    display:block;
    width:45px;
    height:25px;
    position:absolute;
    right:-52px;
    top:0;
    }
    </style>
    </head>
    <body>
    <h1><span id="florish_left"></span>Page Title<span id="florish_right"></span></h1>
    </body>
    </html>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    oesxyl (11-04-2008)

  • #5
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •