Solved

Nested Divs in IE and Firefox

Posted on 2007-11-16
7
3,194 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 42

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 42

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

708 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

15 Experts available now in Live!

Get 1:1 Help Now