By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,404 Members | 2,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,404 IT Pros & Developers. It's quick & easy.

Centering Both a Background Layer and Text Layers in css

P: 3
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:#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.
Sep 27 '07 #1
Share this Question
Share on Google+
8 Replies


NeoPa
Expert Mod 15k+
P: 31,494
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.
Sep 27 '07 #2

Death Slaught
100+
P: 1,137
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:
Expand|Select|Wrap|Line Numbers
  1. body 
  2. {    font-family: Trebuchet MS, Arial; 
  3.     cursor : default;    
  4.     background:#000000 url("Images/long-template.jpg");
  5.     background-repeat:no-repeat;
  6.     background-position: center;
  7.     background-attachment:scroll;
  8.     height: 1228px;
  9.  
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
Expand|Select|Wrap|Line Numbers
  1. 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
Sep 27 '07 #3

drhowarddrfine
Expert 5K+
P: 7,435
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.
Sep 27 '07 #4

P: 1
Why not using a code like this:

[HTML]
{ 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;
margin-left: auto;
margin-right: auto
;
}
[/HTML]

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

..hope this helps
Sep 28 '07 #5

P: 3
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:
Expand|Select|Wrap|Line Numbers
  1. html {
  2. margin: 0px;
  3. padding: 0px;
  4. }
  5.  
  6. body 
  7. {    font-family: Trebuchet MS, Arial;  
  8.     cursor : default;    
  9.     background:#000000 url("Images/background-template.jpg");
  10.     background-repeat:no-repeat;
  11.     background-position: center;
  12.     background-attachment:scroll;
  13.     height: 950px;
  14.     margin-left: auto;
  15.     margin-right: auto;    
  16.  
***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:
http://conceptmoxie.com/annie/junkpage.htm

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

(entire css file)
Expand|Select|Wrap|Line Numbers
  1. html {
  2. margin: 0px;
  3. padding: 0px;
  4. }
  5.  
  6. body 
  7. {    font-family: Trebuchet MS, Arial;  
  8.     cursor : default;    
  9.     background:#000000 url("Images/background-template.jpg");
  10.     background-repeat:no-repeat;
  11.     background-position: center;
  12.     background-attachment:scroll;
  13.     height: 950px;
  14.     margin-left: auto;
  15.     margin-right: auto;    
  16.  
  17.  
  18. input, select, textarea 
  19.     font-family: 
  20. Trebuchet MS; font-size: 12pt; text-transform: uppercase;}
  21.  
  22. a { font-family:  Century Gothic, Trebuchet MS, arial;  color:#ffffff; font-size:11pt;
  23.  text-decoration: none; font-weight:bold; } 
  24. a:hover { text-decoration: none; color:#F4944B; font-weight:bold; } 
  25. .text { font-family: Arial; font-size: 10pt; color: #000000; font-weight:normal; } 
  26. .textnote { font-family: Verdana; font-size: 9pt; color: #ffffff; } .info { font-family: Verdana; font-size: 10pt; } 
  27. .datetext { font-family: Lucida Sans-Serif; font-size: 10pt; color: #000000; font-weight:bold; } 
  28. .datetext2 { font-family: Lucida Sans-Serif; font-size: 16pt; color: #000000; font-weight:normal; } 
  29.  
  30. .nav { font-family: Trebuchet MS; 
  31.     padding-left:0px; 
  32.     padding-right: 0px;
  33.     background-color:#6D5000;
  34.     width: 200px; 
  35.  
  36.     } 
  37.  
  38. .HeaderText { font-family: Trebuchet MS; 
  39.     padding-left:0px; 
  40.     padding-right: 0px;
  41.     color: #F4944B;
  42.     font-family: Trebuchet MS;
  43.     font-weight: bold;
  44.     font-size: 14pt;
  45.  
  46.     }
  47.     .HeaderTextb { font-family: Trebuchet MS; 
  48.     padding-left:0px; 
  49.     padding-right: 0px;
  50.     color: #027FC2;
  51.     font-family: Trebuchet MS;
  52.     font-weight: bold;
  53.     font-size: 14pt;
  54.  
  55.     }
  56.     .HeaderTextc { font-family: Trebuchet MS; 
  57.     padding-left:0px; 
  58.     padding-right: 0px;
  59.     color: #4DBB38;
  60.     font-family: Trebuchet MS;
  61.     font-weight: bold;
  62.     font-size: 14pt;
  63.  
  64.     }
  65.  
  66. .SubHeader 
  67. {
  68.     font-family: Trebuchet MS; 
  69.     font-size: 11pt; 
  70.     color: #F4944B; 
  71.     font-weight:bold;
  72. }
  73.  
  74.     .ScriptText { font-family: Montotype Corsiva; 
  75.     color: #68CEF6;
  76.     font-weight: bold;
  77.     font-size: 14pt;
  78.  
  79.     }
  80.     .LifeTable 
  81.     {
  82.     background-color:#ffffff;    
  83.     font-family: Monotype Corsiva; 
  84.     font-size: 16pt;
  85.     padding-left:10px; 
  86.     padding-right: 10px;
  87.     text-align: center;
  88.     border-top: #000000 3px solid;     
  89.     border-bottom: #000000 3px solid; 
  90.     border-left: #000000 3px solid;
  91.     border-right: #000000 3px solid;
  92.     width: 350px;
  93.     height: 45px; 
  94.  
  95.     } 
  96.     .DecoStyle1 
  97.     {
  98.     background-color:#000000;    
  99.     border-top: #ffffff 3px solid;     
  100.     border-bottom: #ffffff 3px solid; 
  101.     border-left: #ffffff 3px solid;
  102.     width: 365px;
  103.     height: 65px; 
  104.  
  105.     } 
  106.  
  107.  
  108.     .DecoStyle2 
  109.     {
  110.     border-top: #ffffff 3px solid;     
  111.     border-left: #ffffff 3px solid;
  112.     border-right: #ffffff 3px solid;
  113.     width: 295px;
  114.     height: 152px; 
  115.  
  116.     }
  117.  
  118. .Table1 
  119. {     
  120.     width: 750px;
  121.  
  122.  
  123.     }
  124. .Table2 
  125. {     
  126.     width: 474px;     
  127.     }
  128.  
  129.  
  130.     .Column1 
  131. {     
  132.     width: 400px;
  133.  
  134.     }
  135.         .Column2 
  136. {     
  137.     width: 350px;
  138.     padding-left:10px;
  139.     padding-right:10px;
  140.     vertical-align:top;
  141.     font-family: Trebuchet MS; 
  142.     text-align:justify; 
  143.     font-size: 11pt; 
  144.     color: #6D5000; 
  145.     font-weight:normal; 
  146.     }
  147.  
  148.     .Column2a 
  149. {     
  150.     width: 300px;
  151.  
  152.     vertical-align:top;
  153.     font-family: Trebuchet MS; 
  154.     text-align:justify; 
  155.     font-size: 11pt; 
  156.     color: #000000; 
  157.     font-weight:normal; 
  158.     }
  159.  
  160.     .Column3 
  161. {     
  162.     width: 175px;
  163.     padding-left:10px;
  164.     padding-right:10px;
  165.     vertical-align:top;
  166.  
  167.     }
  168.  
  169.     .Column4 
  170. {     
  171.     width: 500px;
  172.     padding-left:10px;
  173.     padding-right:10px;
  174.     vertical-align:top;
  175.  
  176.     }
  177.  
  178. .Column5 
  179. {     
  180.     width: 850px;
  181.     padding-left:10px;
  182.     padding-right:10px;
  183.     vertical-align:top;
  184.  
  185.     }
  186. .Column6 
  187. {     
  188.     width: 250px;
  189. }
  190.  
  191. .Column7 
  192. {     
  193.      width: 650px;
  194.      padding-left:10px;
  195.      padding-right: 10px;
  196. }
  197. .Column8
  198. {     
  199.      width: 650px;
  200.  
  201. }
  202.  
  203.  
  204. .Column8
  205. {     
  206.      width: 700px;
  207.  
  208. }
  209.  
  210. .TSpacer
  211. {     
  212.     width: 50px;     
  213.     }
  214.  
  215.     .VSpacer
  216. {     
  217.     height: 50px;     
  218.     }
  219.  
  220.     .VSpacer2
  221. {     
  222.     height: 400px;     
  223.     }
  224.  
  225.     .VSpacer3
  226. {     
  227.     height: 135px;     
  228.     }
  229.  
  230.     .VSpacer4
  231. {     
  232.     height: 35px;     
  233.     }
  234. .Table2 
  235. {     
  236.     width: 474px;     
  237.     }    
  238.  
  239.  
  240. .SubTable
  241. {    
  242.     BACKGROUND-COLOR: #ffffff;
  243.     WIDTH: 730px;
  244.     BORDER-TOP: #000000 5px solid;     
  245.     BORDER-BOTTOM: #000000 5px solid; 
  246.     border-left: #000000 5px solid;
  247.     border-right: #000000 5px solid;
  248.     height: 450px;
  249. }
  250. .SubTableV2
  251. {    
  252.     BACKGROUND-COLOR: #ffffff;
  253.     WIDTH: 730px;
  254.     BORDER-TOP: #000000 15px solid;     
  255.     BORDER-BOTTOM: #000000 15px solid; 
  256.     border-left: #000000 15px solid;
  257.     border-right: #000000 15px solid;
  258.     height: 450px;
  259. }
  260.  
  261. .BlackSubTable
  262. {    
  263.     BACKGROUND-COLOR: #ffffff;
  264.     WIDTH: 740px;
  265.  
  266.     height: 465px;
  267. }
  268.  
  269. .NavBar
  270. {    
  271.  
  272.     WIDTH: 750px;
  273.  
  274. }
  275.  
  276.  
  277. .text1 { font-family: Trebuchet MS; 
  278.     padding-right:10px; 
  279.     padding-left:10px; 
  280.     text-align:justify; 
  281.     font-size: 11pt; 
  282.     color: #000000; 
  283.     font-weight:normal;
  284.     vertical-align: top; 
  285.     } 
  286.  
  287.     .Quote { font-family: Trebuchet MS; 
  288.     padding-right:10px; 
  289.     padding-left:10px;
  290.     padding-top: 15px; 
  291.     text-align:justify; 
  292.     font-size: 11pt; 
  293.     color: #6D5000; 
  294.     font-weight:normal;
  295.     font-style: italic; 
  296.     }
  297.  
  298.  
  299.  
  300. .text2 { font-family: Trebuchet MS; 
  301.     font-size: 9pt; 
  302.     color: #6D5000;
  303.     font-weight:bold;
  304.     text-align: justify; 
  305.     }
  306.  
  307.     .textQa { font-family: Trebuchet MS; 
  308.     font-size: 9pt; 
  309.     color: #EA3E30;
  310.     font-weight:bold;
  311.     text-align: justify;
  312.     font-style: italic; 
  313.     }
  314.  
  315.     .textQb { font-family: Trebuchet MS; 
  316.     font-size: 9pt; 
  317.     color: #027FC2;
  318.     font-weight:bold;
  319.     text-align: justify;
  320.     font-style: italic; 
  321.     }
  322.     .textQc { font-family: Trebuchet MS; 
  323.     font-size: 9pt; 
  324.     color: #4DBB38;
  325.     font-weight:bold;
  326.     text-align: justify;
  327.     font-style: italic; 
  328.     }
  329.  
  330.  
  331.     .text2c { font-family: Trebuchet MS; 
  332.     font-size: 9pt; 
  333.     color: #000000; 
  334.     font-weight:bold;
  335.     text-align: center;
  336.     vertical-align: top; 
  337.     }
  338.  
  339.  
  340.     .Quoter { font-family: Trebuchet MS; 
  341.     font-size: 11pt; 
  342.     color: #6D5000; 
  343.     font-weight:bold;
  344.     text-align: right; 
  345.     }
  346.  
  347.     .Quoter2 { font-family: Trebuchet MS; 
  348.     font-size: 9pt; 
  349.     color: #6D5000; 
  350.     font-weight:bold;
  351.     text-align: right; 
  352.     }
  353.     .Quoter2a { font-family: Trebuchet MS; 
  354.     font-size: 9pt; 
  355.     color: #EA3E30; 
  356.     font-weight:bold;
  357.     text-align: right; 
  358.     }
  359.     .Quoter2b { font-family: Trebuchet MS; 
  360.     font-size: 9pt; 
  361.     color: #027FC2; 
  362.     font-weight:bold;
  363.     text-align: right; 
  364.     }
  365.     .Quoter2c { font-family: Trebuchet MS; 
  366.     font-size: 9pt; 
  367.     color: #4DBB38; 
  368.     font-weight:bold;
  369.     text-align: right; 
  370.     }
  371.  
  372.  
  373. .text3 
  374.     font-family: Trebuchet MS; 
  375.     padding-right:10px; 
  376.     padding-left:10px; 
  377.     text-align:justify; 
  378.     font-size: 10pt; 
  379.     color: #000000;
  380.     font-weight:normal;
  381.     vertical-align: top; 
  382.     } 
  383.  
  384.     .text3b 
  385.     font-family: Trebuchet MS; 
  386.     padding-right:10px; 
  387.     padding-left:10px; 
  388.     text-align:justify; 
  389.     font-size: 10pt; 
  390.     color: #6D5000;
  391.     font-weight:bold; 
  392.     }
  393.  
  394. .text4 { font-family: Trebuchet MS; 
  395.     padding-right:5px; 
  396.     padding-left:5px; 
  397.     text-align:justify; 
  398.     font-size: 10pt; 
  399.     color: #6D5000; 
  400.     font-weight:normal; 
  401.     }
  402.  
  403.     .text4Right { font-family: Trebuchet MS; 
  404.     padding-right:5px; 
  405.     padding-left:5px; 
  406.     text-align:right; 
  407.     font-size: 10pt; 
  408.     color: #6D5000; 
  409.     font-weight:bold; 
  410.     } 
  411.  
  412.     .text4b { font-family: Trebuchet MS; 
  413.     padding-right:5px; 
  414.     padding-left:5px; 
  415.     text-align:justify; 
  416.     font-size: 10pt; 
  417.     color: #9EBF3D; 
  418.     font-weight:bold; 
  419.     }
  420. .text5 { font-family: Trebuchet MS; 
  421.     padding-right:5px; 
  422.     padding-left:5px; 
  423.     text-align:justify; 
  424.     font-size: 12pt; 
  425.     color: #6D5000; 
  426.     font-weight:bold; 
  427.     }
Sep 28 '07 #6

drhowarddrfine
Expert 5K+
P: 7,435
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.
Sep 28 '07 #7

P: 3
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.
Oct 1 '07 #8

P: 21
Use
Expand|Select|Wrap|Line Numbers
  1. margin:auto
for your body tag in CSS
Aug 23 '13 #9

Post your reply

Sign in to post your reply or Sign up for a free account.