Solved

Nested Divs in IE and Firefox

Posted on 2007-11-16
7
3,197 Views
Last Modified: 2010-04-21
<div class="ContentBackground" id="ContentBackground">
      <div class="Content" id="Content">
      <div id="Layer1"></div>
      </div>
</div>
Here is my situation...I have a div tag nested inside of a second div tag. ContentBackground has an image in the background. I am trying to center and it works...it works in IE and Firefox...
Now the problem is the nested DIV Content.  I want to center it also over the background image but also want to set the margins so that it sets INSIDE of the background image...
If I get it to work in IE it doesn't in Firefox...Firefox seems to ignore the centering and margins...
Any ideas?
.ContentBackground {
      background-image: url(../images/content.jpg);
      background-repeat: no-repeat;
      height: 413px;
      background-position: center;

}
0
Comment
Question by:cenetadmin
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Expert Comment

by:oceanbeach
ID: 20302362
Hello cenetadmi,

Do these styles make the divs act the way you need...

.ContentBackground {
      background: url(../images/content.jpg) no-repeat 50% 50%;
      height: 413px;
}
.Content {
margin: 20px;
}

I hope this helps!

oceanbeach
0
 

Author Comment

by:cenetadmin
ID: 20314635
not really...the issue is that the content that i have on TOP of the background image will not go where I want it to...I want it relative to the background image div which should center on the page...(horizontally). I just set the div for the content to aqua so that I could see it...I want it to be about 20 pixels to the right of the background image...but the div is 20 pix relative to the form and not the background div.

My Code:
<div class="ContentBackground" id="ContentBackground">
      <div class="Content" id="Content">
      </div>
</div>

my Content div is:
.Content
{ margin: 20px;
background-color:Aqua;
}
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 20316733
If you're trying to centre the Content div inside the ContentBackground, then set the left and right margin of the Content div to auto. If you don't specify a width for the Content div then it will stretch the full width of the ContentBackground (so centring it won't show any difference.) It will only 'look' centred if the content div is narrower than the ContentBackground div.

Not really clear what you're after. You said you wanted to centre it AND set it to 20px to the right of the background image!! Seems a little contradictory, unless I've misunderstood.

If you need more help, could you show the full code (or point us to a page on the net)
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 12

Accepted Solution

by:
oceanbeach earned 125 total points
ID: 20321178
Hello cenetadmin,

Does it work if you set div.Content to a width that is 40px shorter than the background image width & center it?  Something like...


.ContentBackground {
      background: url(../images/content.jpg) no-repeat 50% 50%;
      height: 413px;
}
.Content {
width: 460px; /* Assumes background image width of 500px minus 40px for margins */
margin: 0 auto;
}

I hope this helps!

-OB
0
 

Author Comment

by:cenetadmin
ID: 20321448
my real issue is this...I need a solution that works in IE and FIrefox...I need a div that has a background image that I can center on the page...then I want to place div's on top of that background div and have them stay relative to the background...and these divs that lay on top of the background div will need to fall within a 'margin' of the background image.
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 20322045
cenetadmin,

Thats exactly what oceanbeach's code does. The .ContentBackground div will stretch the full width of the page. The background image will centre in that DIV. The .Content div is then set to be 40px less than the width of the background image (if you need this div to sit further 'inside' the background, then set it's width to less). The margin:0 auto; then sets the left and right margin of the .Content div to auto, which centres it within the .Contentbackground div
0
 

Author Closing Comment

by:cenetadmin
ID: 31409669
Thanks
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question