473,549 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Centering Both a Background Layer and Text Layers in css

3 New Member
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.
Sep 27 '07 #1
8 3521
NeoPa
32,564 Recognized Expert Moderator MVP
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
1,137 Top Contributor
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
7,435 Recognized Expert Expert
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
samaar
1 New Member
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
Sep 28 '07 #5
ayamopamo
3 New Member
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
7,435 Recognized Expert Expert
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
ayamopamo
3 New Member
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
shadowstrike
21 New Member
Use
Expand|Select|Wrap|Line Numbers
  1. margin:auto
for your body tag in CSS
Aug 23 '13 #9

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

Similar topics

1
1927
by: PAD | last post by:
I have written a javascript routine that populates a parent document with a series of <iframe>s. Each <iframe> receives its contents from a series of separate smaller HTML files. Of course my NN 4.8 browser doesn't deal well with the <iframe> so I wrapped the code that generates the <iframe> in <ilayer> tags. NN now recognizes the contents....
15
13484
by: red | last post by:
How do I center two side by side divs ? I've been writing css pages for a while but there's one thing tha still eludes me. I can center a div with margin auto. I can place two divs side by side with float. But I can't center two side by side divs. If I float them and give them auto margins, the auto margins are ignored. If I wrap the...
34
4397
by: The Good Son | last post by:
I'm trying to get my head around a problem that has me baffled. The following element: #wrapper {border:1px solid #000;background:#fff;} Renders as expected when using this DTD: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
1
1699
by: Christophe Candas | last post by:
Hye, You will find here under a script which will load a picture in a layer , picture depending on the cursor position. Everything's ok until the line: document.getElementById('zoom').style.background="url('chemin image.gif')"; which doesn't work. The script works (indication in the status barre) but the image is not loaded in the...
6
2302
by: Jerry Camel | last post by:
I want to center an image on the screen and have text centered over the image. What's the best way to do this? I've been playing with style tags and I can get the stuff to center automatically OR have the text appear on top of the image. But in the second case, the image and text aren't centered properly. Any help is appreciated... ...
3
4191
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a top level <divthen I can place it with CSS attribute 'left:', but this is a fixed offset. Is it possible to have a <divcentered in the browser window?...
16
9004
by: MS newsgroup | last post by:
I don't have clear reasons why we need business logic layer and data logic layer instead of having only data logic layer. Are there any good reasons for that?
2
1987
by: funkiejunkie | last post by:
Hello all, I posted a thread a while ago and was told to include the code so here it is. I still dont really get CSS, everything I have done has been blagged because I cant be bothered to read books to help me understand whats really going on. I would a few more containers within my centered text box in the middle so I dont have to press...
16
2417
by: parez | last post by:
I start a BackGroundWorker to populate a grid. It is started off in the ui layer The thread follows( cannot think of a better word) the path UI->Layer1->Layer2->Communication Layer and it blocks (the server is executing somthing where which takes time)
0
7532
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7462
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7492
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6059
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3510
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1957
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1069
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.