Centering Both a Background Layer and Text Layers in css

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayamopamo
    New Member
    • Sep 2007
    • 3

    Centering Both a Background Layer and Text Layers in css

    Hi- I am trying to center a web page. It seems like this should be very simple to do, but apparently it isn't my day. I have successfully centered the background by calling it in the css body tag:
    body
    { font-family: Trebuchet MS, Arial;
    cursor : default;
    background:#000 000 url("Images/long-template.jpg");
    background-repeat:no-repeat;
    background-position: center;
    background-attachment:scro ll;
    height: 1228px;

    }

    but the text layers on top of this background seem to be all over the page, depending on the monitor and browser used to view.
    Is there a simple way to keep the layers on top of the centered background safely contained within its boundaries?

    I am sure this is very simple and I have missed this in googling, but any help is greatly appreciated!!!
    Here is its temp url: http://conceptmoxie.com/annie/junkpage.htm
    Thanks.
    Last edited by ayamopamo; Sep 27 '07, 06:32 PM. Reason: need to add my link
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32661

    #2
    You've posted this in the Lounge (for general rather than technical discussions) but this would surely be better in the HTML / CSS forum so I'll move it there for you.

    Comment

    • Death Slaught
      Top Contributor
      • Aug 2007
      • 1137

      #3
      Originally posted by ayamopamo
      Hi- I am trying to center a web page. It seems like this should be very simple to do, but apparently it isn't my day. I have successfully centered the background by calling it in the css body tag:
      Code:
      body 
      {	font-family: Trebuchet MS, Arial; 
      	cursor : default;	
      	background:#000000 url("Images/long-template.jpg");
      	background-repeat:no-repeat;
      	background-position: center;
      	background-attachment:scroll;
      	height: 1228px;
      	
      }
      but the text layers on top of this background seem to be all over the page, depending on the monitor and browser used to view.
      Is there a simple way to keep the layers on top of the centered background safely contained within its boundaries?

      I am sure this is very simple and I have missed this in googling, but any help is greatly appreciated!!!
      Here is its temp url: http://conceptmoxie.com/annie/junkpage.htm
      Thanks.
      Sup ayamopamo, Welcome to TSDN!, please use proper code tags when posting code, and please read the posting guidelines .

      Post all of your CSS so we can look for errors, usually we could find them in the link you gave us. but your CSS is in an external style sheet.

      instead of centering your text move it using margins like
      Code:
      margin-left: 20%;
      in your CSS. That way you can potition your text exactly where you want it inside of the area in your "background so to speak" that you think looks best.

      Hope it helps, and Thanks, Death

      Comment

      • drhowarddrfine
        Recognized Expert Expert
        • Sep 2006
        • 7434

        #4
        Well, just to get you started, change this:
        <div id="Div1" style="z-index: 1; left: 275px; width: 700px; position: absolute; top: 145px">

        to:
        <div id="Div1" style="z-index: 1; margin: 145px auto 0 auto; width: 700px;">

        I don't know that the z-index is necessary and I didn't take the time to look at the graphic on top. The top margin may not be necessary depending on where it's coming from. id names should be lower-case.

        Comment

        • samaar
          New Member
          • Sep 2007
          • 1

          #5
          Why not using a code like this:

          [HTML]
          { font-family: Trebuchet MS, Arial;
          cursor : default;
          background:#000 000 url("Images/long-template.jpg");
          background-repeat:no-repeat;
          background-position: center;
          background-attachment:scro ll;
          height: 1228px;
          margin-left: auto;
          margin-right: auto
          ;
          }
          [/HTML]

          Just add the
          [HTML]Margin-left: auto;
          margin-right: auto;
          [/HTML]

          ..hope this helps

          Comment

          • ayamopamo
            New Member
            • Sep 2007
            • 3

            #6
            horizontal vs. vertical alignment

            Originally posted by drhowarddrfine
            Well, just to get you started, change this:
            <div id="Div1" style="z-index: 1; left: 275px; width: 700px; position: absolute; top: 145px">

            to:
            <div id="Div1" style="z-index: 1; margin: 145px auto 0 auto; width: 700px;">

            I don't know that the z-index is necessary and I didn't take the time to look at the graphic on top. The top margin may not be necessary depending on where it's coming from. id names should be lower-case.

            Hi- thanks for replying to my post. I did as you suggested, and it did indeed center the text on the page, however, now the top margin is a little screwy. Before, both ie and ff recognized it as 145 pixels from the top and that was consistent with both browsers--- the wild card was the horizontal alignment. Now they are both horizontally correct, but ff is pulling my nav bar way up high. is there anything i can do to fix this problem?
            Here is what I changed my css file to: [code=css]
            html {
            margin: 0px;
            padding: 0px;
            }

            body
            { font-family: Trebuchet MS, Arial;
            cursor : default;
            background:#000 000 url("Images/background-template.jpg");
            background-repeat:no-repeat;
            background-position: center;
            background-attachment:scro ll;
            height: 950px;
            margin-left: auto;
            margin-right: auto;
            }
            [/code]
            ***I have posted the entire css file at the bottom of this post. Be warned-- it is long. (sorry)

            and here is how i changed the <div> tag based on what you suggested.
            <div id="Div1" style="z-index: 1; margin: 140px auto 0 auto; width: 700px;">

            Here also, is the link to where the page is sitting currently:


            Correct in IE, not in FF. Thank you for helping me.

            (entire css file)[code=css]
            html {
            margin: 0px;
            padding: 0px;
            }

            body
            { font-family: Trebuchet MS, Arial;
            cursor : default;
            background:#000 000 url("Images/background-template.jpg");
            background-repeat:no-repeat;
            background-position: center;
            background-attachment:scro ll;
            height: 950px;
            margin-left: auto;
            margin-right: auto;
            }


            input, select, textarea
            {
            font-family:
            Trebuchet MS; font-size: 12pt; text-transform: uppercase;}

            a { font-family: Century Gothic, Trebuchet MS, arial; color:#ffffff; font-size:11pt;
            text-decoration: none; font-weight:bold; }
            a:hover { text-decoration: none; color:#F4944B; font-weight:bold; }
            .text { font-family: Arial; font-size: 10pt; color: #000000; font-weight:normal; }
            .textnote { font-family: Verdana; font-size: 9pt; color: #ffffff; } .info { font-family: Verdana; font-size: 10pt; }
            .datetext { font-family: Lucida Sans-Serif; font-size: 10pt; color: #000000; font-weight:bold; }
            .datetext2 { font-family: Lucida Sans-Serif; font-size: 16pt; color: #000000; font-weight:normal; }

            .nav { font-family: Trebuchet MS;
            padding-left:0px;
            padding-right: 0px;
            background-color:#6D5000;
            width: 200px;

            }

            .HeaderText { font-family: Trebuchet MS;
            padding-left:0px;
            padding-right: 0px;
            color: #F4944B;
            font-family: Trebuchet MS;
            font-weight: bold;
            font-size: 14pt;

            }
            .HeaderTextb { font-family: Trebuchet MS;
            padding-left:0px;
            padding-right: 0px;
            color: #027FC2;
            font-family: Trebuchet MS;
            font-weight: bold;
            font-size: 14pt;

            }
            .HeaderTextc { font-family: Trebuchet MS;
            padding-left:0px;
            padding-right: 0px;
            color: #4DBB38;
            font-family: Trebuchet MS;
            font-weight: bold;
            font-size: 14pt;

            }

            .SubHeader
            {
            font-family: Trebuchet MS;
            font-size: 11pt;
            color: #F4944B;
            font-weight:bold;
            }

            .ScriptText { font-family: Montotype Corsiva;
            color: #68CEF6;
            font-weight: bold;
            font-size: 14pt;

            }
            .LifeTable
            {
            background-color:#ffffff;
            font-family: Monotype Corsiva;
            font-size: 16pt;
            padding-left:10px;
            padding-right: 10px;
            text-align: center;
            border-top: #000000 3px solid;
            border-bottom: #000000 3px solid;
            border-left: #000000 3px solid;
            border-right: #000000 3px solid;
            width: 350px;
            height: 45px;

            }
            .DecoStyle1
            {
            background-color:#000000;
            border-top: #ffffff 3px solid;
            border-bottom: #ffffff 3px solid;
            border-left: #ffffff 3px solid;
            width: 365px;
            height: 65px;

            }


            .DecoStyle2
            {
            border-top: #ffffff 3px solid;
            border-left: #ffffff 3px solid;
            border-right: #ffffff 3px solid;
            width: 295px;
            height: 152px;

            }

            .Table1
            {
            width: 750px;


            }
            .Table2
            {
            width: 474px;
            }


            .Column1
            {
            width: 400px;

            }
            .Column2
            {
            width: 350px;
            padding-left:10px;
            padding-right:10px;
            vertical-align:top;
            font-family: Trebuchet MS;
            text-align:justify;
            font-size: 11pt;
            color: #6D5000;
            font-weight:normal;
            }

            .Column2a
            {
            width: 300px;

            vertical-align:top;
            font-family: Trebuchet MS;
            text-align:justify;
            font-size: 11pt;
            color: #000000;
            font-weight:normal;
            }

            .Column3
            {
            width: 175px;
            padding-left:10px;
            padding-right:10px;
            vertical-align:top;

            }

            .Column4
            {
            width: 500px;
            padding-left:10px;
            padding-right:10px;
            vertical-align:top;

            }

            .Column5
            {
            width: 850px;
            padding-left:10px;
            padding-right:10px;
            vertical-align:top;

            }
            .Column6
            {
            width: 250px;
            }

            .Column7
            {
            width: 650px;
            padding-left:10px;
            padding-right: 10px;
            }
            .Column8
            {
            width: 650px;

            }


            .Column8
            {
            width: 700px;

            }

            .TSpacer
            {
            width: 50px;
            }

            .VSpacer
            {
            height: 50px;
            }

            .VSpacer2
            {
            height: 400px;
            }

            .VSpacer3
            {
            height: 135px;
            }

            .VSpacer4
            {
            height: 35px;
            }
            .Table2
            {
            width: 474px;
            }


            .SubTable
            {
            BACKGROUND-COLOR: #ffffff;
            WIDTH: 730px;
            BORDER-TOP: #000000 5px solid;
            BORDER-BOTTOM: #000000 5px solid;
            border-left: #000000 5px solid;
            border-right: #000000 5px solid;
            height: 450px;
            }
            .SubTableV2
            {
            BACKGROUND-COLOR: #ffffff;
            WIDTH: 730px;
            BORDER-TOP: #000000 15px solid;
            BORDER-BOTTOM: #000000 15px solid;
            border-left: #000000 15px solid;
            border-right: #000000 15px solid;
            height: 450px;
            }

            .BlackSubTable
            {
            BACKGROUND-COLOR: #ffffff;
            WIDTH: 740px;

            height: 465px;
            }

            .NavBar
            {

            WIDTH: 750px;

            }


            .text1 { font-family: Trebuchet MS;
            padding-right:10px;
            padding-left:10px;
            text-align:justify;
            font-size: 11pt;
            color: #000000;
            font-weight:normal;
            vertical-align: top;
            }

            .Quote { font-family: Trebuchet MS;
            padding-right:10px;
            padding-left:10px;
            padding-top: 15px;
            text-align:justify;
            font-size: 11pt;
            color: #6D5000;
            font-weight:normal;
            font-style: italic;
            }



            .text2 { font-family: Trebuchet MS;
            font-size: 9pt;
            color: #6D5000;
            font-weight:bold;
            text-align: justify;
            }

            .textQa { font-family: Trebuchet MS;
            font-size: 9pt;
            color: #EA3E30;
            font-weight:bold;
            text-align: justify;
            font-style: italic;
            }

            .textQb { font-family: Trebuchet MS;
            font-size: 9pt;
            color: #027FC2;
            font-weight:bold;
            text-align: justify;
            font-style: italic;
            }
            .textQc { font-family: Trebuchet MS;
            font-size: 9pt;
            color: #4DBB38;
            font-weight:bold;
            text-align: justify;
            font-style: italic;
            }


            .text2c { font-family: Trebuchet MS;
            font-size: 9pt;
            color: #000000;
            font-weight:bold;
            text-align: center;
            vertical-align: top;
            }


            .Quoter { font-family: Trebuchet MS;
            font-size: 11pt;
            color: #6D5000;
            font-weight:bold;
            text-align: right;
            }

            .Quoter2 { font-family: Trebuchet MS;
            font-size: 9pt;
            color: #6D5000;
            font-weight:bold;
            text-align: right;
            }
            .Quoter2a { font-family: Trebuchet MS;
            font-size: 9pt;
            color: #EA3E30;
            font-weight:bold;
            text-align: right;
            }
            .Quoter2b { font-family: Trebuchet MS;
            font-size: 9pt;
            color: #027FC2;
            font-weight:bold;
            text-align: right;
            }
            .Quoter2c { font-family: Trebuchet MS;
            font-size: 9pt;
            color: #4DBB38;
            font-weight:bold;
            text-align: right;
            }


            .text3
            {
            font-family: Trebuchet MS;
            padding-right:10px;
            padding-left:10px;
            text-align:justify;
            font-size: 10pt;
            color: #000000;
            font-weight:normal;
            vertical-align: top;
            }

            .text3b
            {
            font-family: Trebuchet MS;
            padding-right:10px;
            padding-left:10px;
            text-align:justify;
            font-size: 10pt;
            color: #6D5000;
            font-weight:bold;
            }

            .text4 { font-family: Trebuchet MS;
            padding-right:5px;
            padding-left:5px;
            text-align:justify;
            font-size: 10pt;
            color: #6D5000;
            font-weight:normal;
            }

            .text4Right { font-family: Trebuchet MS;
            padding-right:5px;
            padding-left:5px;
            text-align:right;
            font-size: 10pt;
            color: #6D5000;
            font-weight:bold;
            }

            .text4b { font-family: Trebuchet MS;
            padding-right:5px;
            padding-left:5px;
            text-align:justify;
            font-size: 10pt;
            color: #9EBF3D;
            font-weight:bold;
            }
            .text5 { font-family: Trebuchet MS;
            padding-right:5px;
            padding-left:5px;
            text-align:justify;
            font-size: 12pt;
            color: #6D5000;
            font-weight:bold;
            }[/code]
            Last edited by drhowarddrfine; Sep 28 '07, 10:57 PM. Reason: Please use code tags

            Comment

            • drhowarddrfine
              Recognized Expert Expert
              • Sep 2006
              • 7434

              #7
              I'm off to my son's performance but, no, FF is performing correctly. Looking at it quickly, I believe it's an IE bug where it is expanding an element improperly, but I can't look at it again until late tonight or tomorrow sometime.

              Comment

              • ayamopamo
                New Member
                • Sep 2007
                • 3

                #8
                Does anyone have any suggestions for this? My client is viewing through IE, and while I could certainly fix this to be correct in her browser, anyone using FF would see a very misaligned page, at least vertically. I understand there is an IE/FF glitch, which causes a bit of difference btw. the two, but what can I do to minimize this so the page is within reason?

                Thanks to all of you who have replied so far, and to anyone who can help me.

                Comment

                • shadowstrike
                  New Member
                  • Aug 2013
                  • 21

                  #9
                  Use
                  Code:
                  margin:auto
                  for your body tag in CSS

                  Comment

                  Working...