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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Centering Layers with CSS

    So. For the past 72 hours I have been relentlessly trying to solve this issue. It seems fairly simple, and in theory it should work. But theory is currently shafting me.

    I have two layers, both in html. One is a simple background image while the other is a gathering of transparent slices to be used as links. Now, I know you may be asking why I have the two separate, but I want to have the image load cleaner than it has been and would like to have the links load invisibly.

    I have tried many ways of centering the layers including <center>, <absmiddle>, 50% margins, etc.....and it still doesn't work! Its slightly infuriating. My last resort has been to work in out in CSS. Now I am in no way experienced, so I've been fishing around in forums for spare code in a vain attempt to piece together something that resembles code. It hasnt worked. PLease. If you have any ideas, it would be AMAZING!

    -Phil

  • #2
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    Hi Phil,

    Quote Originally Posted by holbrookphotos View Post
    My last resort has been to work in out in CSS.
    CSS should be your first resort when it comes to layout issues. Seriously.

    You should know that "layers" are an artificial construct used by graphics programs and WYSIWYG programs that create HTML code and really don't have any relevance to actual code. In other words, there's no <layer> tag.

    That said, what do you have so far? There are a couple of ways of centering sites using CSS, all of them quite simple and easy. A link to a page, all the HTML and CSS you have so far, or even a screen capture would be helpful.
    matt | design | blog

  • #3
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,667
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello holbrookphotos,
    The very basics of centering is
    • DocType
    • width
    • margin:auto;


    Like this example where you see the div #wrap is centered:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {
    	background: #FC6;
    }
    #wrap {
    	width: 800px;
    	height: 600px;
    	margin: 30px auto;
    	background: #999;
    }
    </style>
    </head>
    <body>
        <div id="wrap">
        <!--end wrap--></div>
    </body>
    </html>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #4
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    SO! I know that there is a lot here, and I am really fishing in the dark, so it most likely is jumbled and garbled....sorry about that. I have the css sheet first and the html doc afterwards. The most important thing to me is having the layers, so if thats possible to keep in, thatd be great. Again, sorry for the mass amount of text. In the HTML file you will see links to tons of graphics, those are all my slices so that I can link to other pages on my site. Thanks in advance, this is a huge help!



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Centered Element of unknown height and width</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="style.css" rel="stylesheet" type="text/css" /></head>

    body{

    text-align:center;
    }


    #Layer1 {
    position: absolute;
    top: 0;
    left: 50%;
    margin-top: 0;
    margin: 0 auto;
    z-index: 1;
    }

    #Layer2 {
    position: absolute;
    top: 0;
    left: 50%;
    margin-top: 0;
    margin: 0 auto;
    z-index: 2;
    }

    #Layer3 {
    position:absolute;
    top: 0px;
    left: 50%;
    right: 50%;
    position: absolute;
    z-index: 1;
    }

    #Layer4 {
    position:absolute;
    top: 0px;
    left: 0%;
    right: 50%;
    position: absolute;
    z-index: 2;
    }

    </body>
    </html>




    HTML!!!::::




    <!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" />
    <title>Center Test 2</title>

    <link rel=stylesheet type="text/css" href="../style.css">

    </head>
    <body bgcolor="#000000" leftmargin="auto" rightmargin="auto" topmargin="0" bottommargin="0" marginwidth="0" marginheight="0">

    <div id="top" style="left: 500px; top: 485px; position: absolute">

    <table id="Table_01" table class="center" width="1025" height="769" border="0" cellpadding="0" cellspacing="0">

    <tr>
    <td colspan="11">
    <img src="images/Head_slices_01.gif" alt="" width="1024" height="37" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="37" align="default"></td>
    </tr>
    <tr>
    <td rowspan="14">
    <img src="images/Head_slices_02.gif" alt="" width="74" height="731" align="default"></td>
    <td colspan="9" align="default" valign="top">
    <img src="images/Head_slices_03.gif" alt="" width="877" height="74" align="default"></td>
    <td rowspan="14">
    <img src="images/Head_slices_04.gif" alt="" width="73" height="731" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="74" align="default"></td>
    </tr>
    <tr>
    <td colspan="9">
    <img src="images/Head_slices_05.gif" alt="" width="877" height="122" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="122" align="default"></td>
    </tr>
    <tr>
    <td rowspan="12">
    <img src="images/Head_slices_06.gif" alt="" width="36" height="535" align="default"></td>
    <td align="default" valign="top">
    <img src="images/Head_slices_07.gif" alt="" width="193" height="91" align="default"></td>
    <td colspan="7" rowspan="2">
    <img src="images/Head_slices_08.gif" alt="" width="648" height="95" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="91" align="default"></td>
    </tr>
    <tr>
    <td>
    <img src="images/Head_slices_09.gif" alt="" width="193" height="4" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="4" align="default"></td>
    </tr>
    <tr>
    <td colspan="2" align="default" valign="top">
    <img src="images/Head_slices_10.gif" alt="" width="195" height="89" align="default"></td>
    <td colspan="6" rowspan="2">
    <img src="images/Head_slices_11.gif" alt="" width="646" height="93" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="89" align="default"></td>
    </tr>
    <tr>
    <td colspan="2">
    <img src="images/Head_slices_12.gif" alt="" width="195" height="4" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="4" align="default"></td>
    </tr>
    <tr>
    <td colspan="3" align="default" valign="top">
    <img src="images/Head_slices_13.gif" alt="" width="196" height="88" align="default"></td>
    <td colspan="5" rowspan="4">
    <img src="images/Head_slices_14.gif" alt="" width="645" height="197" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="88" align="default"></td>
    </tr>
    <tr>
    <td colspan="3">
    <img src="images/Head_slices_15.gif" alt="" width="196" height="6" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="6" align="default"></td>
    </tr>
    <tr>
    <td colspan="3" align="default" valign="top">
    <img src="images/Head_slices_16.gif" alt="" width="196" height="88" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="88" align="default"></td>
    </tr>
    <tr>
    <td colspan="3" rowspan="5">
    <img src="images/Head_slices_17.gif" alt="" width="196" height="165" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="15" align="default"></td>
    </tr>
    <tr>
    <td rowspan="4">
    <img src="images/Head_slices_18.gif" alt="" width="144" height="150" align="default"></td>
    <td colspan="3" align="default" valign="top">
    <img src="images/Head_slices_19.gif" alt="" width="129" height="37" align="default"></td>
    <td rowspan="4">
    <img src="images/Head_slices_20.gif" alt="" width="372" height="150" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="37" align="default"></td>
    </tr>
    <tr>
    <td colspan="3">
    <img src="images/Head_slices_21.gif" alt="" width="129" height="12" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="12" align="default"></td>
    </tr>
    <tr>
    <td rowspan="2">
    <img src="images/Head_slices_22.gif" alt="" width="22" height="101" align="default"></td>
    <td align="default" valign="top">
    <img src="images/Head_slices_23.gif" alt="" width="87" height="64" align="default"></td>
    <td rowspan="2">
    <img src="images/Head_slices_24.gif" alt="" width="20" height="101" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="64" align="default"></td>
    </tr>
    <tr>
    <td>
    <img src="images/Head_slices_25.gif" alt="" width="87" height="37" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="37" align="default"></td>
    </tr>
    <tr>
    <td>
    <img src="images/spacer.gif" alt="" width="74" height="1" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="36" height="1" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="193" height="1" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="2" height="1" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="1" height="1" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="144" height="1" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="22" height="1" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="87" height="1" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="20" height="1" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="372" height="1" align="default"></td>
    <td>
    <img src="images/spacer.gif" alt="" width="73" height="1" align="default"></td>
    <td></td>
    </tr>
    </table></div>

    <div id="Layer2"><img src="OVERLAY TEST.jpg"></div>

    </body>
    </html>

  • #5
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    Quote Originally Posted by msuffern View Post
    Hi Phil,
    You should know that "layers" are an artificial construct used by graphics programs and WYSIWYG programs that create HTML code and really don't have any relevance to actual code. In other words, there's no <layer> tag.
    You sure about that? Didn't Netscape have <layer> as opposed to <div> back in the mid-90s?
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #6
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    Quote Originally Posted by jerry62704 View Post
    You sure about that? Didn't Netscape have <layer> as opposed to <div> back in the mid-90s?
    Perhapsibly. But that part of "web history" is thankfully over.
    matt | design | blog

  • #7
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    I ignored css for a decade because of it. I just couldn't see every command being duplicated for both browsers. What a nightmare.
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #8
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    Phil: Let's start over. It's much easier than you think. Two points to remember:

    1. No self-respecting web designer uses tables for layout any more.
    2. You don't have to slice up your images if you lay out your page with CSS. It's a beautiful, wonderful thing.

    Excavator demonstrated the preferred method for centering. As far as the rest of your code, ditch the tables, read up on semantic code and learn how to lay out your page using only CSS.

    If you'd like more specific help here, post a link to your page and we can help you rework it. It's difficult/impossible to do without actually being able to see your images and thus deduce your design intent.
    matt | design | blog

  • #9
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Excavator demonstrated the preferred method for centering. As far as the rest of your code, ditch the tables, read up on semantic code and learn how to lay out your page using only CSS.
    ... and get inspired by seeing the beauty and flexibility of CSS based design : http://www.csszengarden.com/
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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