Solved

Nested Divs in IE and Firefox

Posted on 2007-11-16
7
3,195 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Unordered lists (HTML ul tags) are very handy to create menus of all types, shapes and sizes.  All it takes is a little knowledge of CSS and the possibilities are endless. First off, you should know the general format for menus created using the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now