473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Div margin only works if outer div has border

Hi All,

I've been having real trouble with some css in both Win/IE6 and
Win/Firefox0.9.2 that doesn't make sense to me. I have a div that is
supposed to be spaced away from the top and right hand edges of it's
containing div and therefore I set suitable values for it's margins.
Unfortunately it refuses to move itself unless I give the parent div a
border.

Perhaps this will make more sense with an example (I've boiled the
problem down to a relatively small code sample):

--- START XHTML ---

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>
<title>Template</title>
<link href="draft1_style2.css" rel="stylesheet" type="text/css" />
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1" />
</head>

<body>

<div id="page">

<div id="content">

<h2>Segment Title</h2>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisienim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
Duis autem vel eum iriure dolor inhendrerit in vulputate velit esse
molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
eros et accumsan et iusto odio dignissim quiblandit praesent luptatum
zzril delenit augue duis dolore te feugait nulla facilisi.</p>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisienim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
Duis autem vel eum iriure dolor inhendrerit in vulputate velit esse
molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero
eros et accumsan et iusto odio dignissim quiblandit praesent luptatum
zzril delenit augue duis dolore te feugait nulla facilisi.</p>

</div>

<div id="nav"><p>paragraph</p><p>paragraph</p><p>paragraph</p></div>

</div>

</body>

</html>

--- END XHTML ---

--- START CSS (draft1_style2.css) ---

body
{
background-color: black ;
}

#page
{
border: 1px solid #ffffff ;
position: relative ;
background-color: #ff0000 ;
}

#content
{
margin: 60px 110px 0 0 ;
background-color: #00ff00 ;
}

#nav
{
position: absolute ;
top: 60px ;
right: 0 ;
width: 110px ;
background-color: #0000ff ;
}

--- END CSS ---

To see what I mean try changing the border width attribute in the style
#page to 0.
Jul 20 '05 #1
1 4655
On Sat, 17 Jul 2004 14:00:59 +0100, Corvus
<to************************@phiz.org.uk> wrote:
I've been having real trouble with some css in both Win/IE6 and
Win/Firefox0.9.2 that doesn't make sense to me. I have a div that is
supposed to be spaced away from the top and right hand edges of it's
containing div and therefore I set suitable values for it's margins.
Unfortunately it refuses to move itself unless I give the parent div a
border.

Perhaps this will make more sense with an example (I've boiled the
problem down to a relatively small code sample):


Read up the CSS spec on collapsing margins (section 8.3.1). I think the
margin of your DIV is collapsing with the page margin, though I haven't
got every detail clear in my mind. When this is a problem it's generally
recommended to use padding instead of margin, though a 1px border of the
same colour as one of the backgrounds would presumably also work.

HTH

--
Stephen Poley

http://www.xs4all.nl/~sbpoley/webmatters/
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: moocow | last post by:
Hi. I am using a background image in a form button. The problem I am having is that there is a 1 pixel margin inside the button on all sides. I would like my background image to fill the...
2
by: Florian Brucker | last post by:
I got a problem with code looking like that: <div class="outer"> <div class="inner"> Sample text </div> </div> The outer DIV has margin/padding=0, the inner DIV has a margin (all 4 sides)....
19
by: Thomas Mlynarczyk | last post by:
Hello, The following gives different results in IE and "Non-IE" browsers: <div style="background-color: green; width: 200px"> <div style="margin-top: 20px; background-color: red"> Hello...
0
by: bugbear | last post by:
I was struggling with some elaborate nested divs, and my styles were working fine on everything (even Mac/ie5.2) *except* IE6.0 on Windows 2000 professional. I have 2 nested DIVS, both...
10
by: tbcarver | last post by:
I have a table that I am trying to add a bottom margin to in IE. I have found that if the table is inside more than 1 div then the shape of the containing div collapses. Please look at this...
13
by: Cool Guy | last post by:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>test</title> </head> <body> <div style="height: 100px; width: 100px;...
3
by: stan | last post by:
I have code that produces 5 boxes across the screen width. So far I have only tested it in IE 6 and NS 8. It works in IE, but in NS I am not able to fit in the 5th box. I am using two...
6
by: Hacking Bear | last post by:
Hi, I still don't quite fully understand how to handle mixing border/margin pixel width with percentage width. In the example below, I want to place side-by-side two DIV boxes inside a box....
7
by: GTalbot | last post by:
Hello fellow authoring.stylesheets colleagues, Can someone please explain why the bottom margin of the last inflow block-level child in an overflowed parent should not have its margin reachable....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.