472,133 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

STRICTly speaking, what is 100%?

I'm trying to create a page: Three sections (left, topright and
bottomright), each with a heading and scrolling (overflow) content.
The size of these sections should be based upon the size of the user's
viewable area in their browser. I'm close... really close, but I'm
confused over how to mix specific measurements with percentages.

When I began, things were quite nice:
(http://play.psmonopoly.com/autosize.html). A little clunky in IE, but
firefox and ie both worked pretty well.
Then I started trying to add a 1em high heading for each section, add
some small margins and padding and everything went downhill
(http://play.psmonopoly.com/autosize1.html).

Can someone please explain what 100% really means, and is there a way
that 100% means all the area available minus the padding of the parent
container?

Thanks!

Mike

May 8 '06 #1
17 2051
Mike wrote:

Can someone please explain what 100% really means,
It means 100% of the content area

http://www.w3.org/TR/REC-CSS2/box.html
and is there a way
that 100% means all the area available minus the padding of the parent
container?


Only in IE :)

--
Brian O'Connor (ironcorona)
May 8 '06 #2
ironcorona wrote:
and is there a way
that 100% means all the area available minus the padding of the parent
container?


Sorry, I just re-read that. That's exactly what it means. If I set an
element's width to 100% it will take up *all* of its parent element's
content area.

--
Brian O'Connor (ironcorona)
May 8 '06 #3
Mike wrote:
Can someone please explain what 100% really means, and is there a way
that 100% means all the area available minus the padding of the parent
container?


It depends what property you are talking about.

In the case of height it means "As tall as the container, providing the
container is not height: auto in which case it becomes height: auto
instead".

In the case of width it means exactly what it sounds like, but remember that
the width is the _content_ width and that padding, border and margin go
outside it.

On elements that are display: block, a width of auto is "whatever space is
left over after border, margin and padding are accounted for".

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
May 8 '06 #4
That's what I thought, but it doesn't seem to be working that way. All
is fine, until I add some margin or padding and divs seem to bleed
outside the browser window. Take a look at the sample pages, they're
both pretty simple. Any advice?

Thansk!

Mike

May 10 '06 #5
Mike wrote:
That's what I thought
What is what you thought? http://www.safalra.com/special/googlegroupsreply/
, but it doesn't seem to be working that way. All
is fine, until I add some margin or padding and divs seem to bleed
outside the browser window.


So you have an element with content width of 100% of the parent elements
content area, then you add margin or padding. 1005 + something greater than
zero is going to equal more than 100%.
--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
May 10 '06 #6
On 8 May 2006 21:47:21 -0700 Mike <mp*****@gmail.com> wrote:

| That's what I thought, but it doesn't seem to be working that way. All
| is fine, until I add some margin or padding and divs seem to bleed
| outside the browser window. Take a look at the sample pages, they're
| both pretty simple. Any advice?

Is this what you are seeing?

https://bugzilla.mozilla.org/show_bug.cgi?id=167408

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
May 10 '06 #7
David wrote:
So you have an element with content width of 100% of the parent elements
content area, then you add margin or padding. 1005 + something greater than
zero is going to equal more than 100%.


Here's an example to illustrate the problem I'm having. I set up two
divs (left-content and right-content), I'd like a 1em margin around
both divs, as well as inbetween them. My goal is to have the content
in these two divs what real estate remains after those margins, and
resize as the browser resizes.

Here's what I did:

· Set html rules to 100% width & height, with 0 margin to establish
inheritance.
· Set body to 100% width & height, but added a 1em margin to surround
the page.
· Created the two content divs "left-content" and
"right-content", set height and width to 100% , added some color,
padding and a little text.
· To establish the 1em "margin" between the two divs, I created
parent divs "left" and "right". Both of these are float:left
so they display side by side, height:100% and width:50%, but I added a
..5em padding in the center to establish the 1em "margin" between
the nested content divs. (code below).

I expected that this would work, but when testing in Foxfire and IE7,
it doesn't. If you reduce #left,#right {width:40%}, you'll see that
the 1em "margin" between the two divs doesn't appear in Foxfire or IE7.
Clearly, my understanding of how this works is off. How would you make
this work?

Thanks!

Mike

Here's my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css" media="screen">
html {
height: 100%;
width: 100%;
margin: 0;
}
body {
height: 100%;
width: 100%;
margin:1em;
}
#left {
padding-right:1em;
}
#right {
padding-left:1em;
}
#left,#right {
float:left;
width:40%;
height:100%;
}
#left-content {
height:100%;
width:100%;
padding:1em;
background-color:red;
}
#right-content {
height:100%;
width:100%;
padding:1em;
background-color:blue;
}
</style>
</head>
<body>
<div id="left">
<div id="left-content">Left Content.</div>
</div>
<div id="right">
<div id="right-content">Right Content.</div>
</div>
</body>
</html>

May 10 '06 #8
Mike wrote:
David wrote:
So you have an element with content width of 100% of the parent elements
content area, then you add margin or padding. 1005 + something greater than
zero is going to equal more than 100%.
Here's an example to illustrate the problem I'm having. I set up two
divs (left-content and right-content), I'd like a 1em margin around
both divs, as well as inbetween them. My goal is to have the content
in these two divs what real estate remains after those margins, and
resize as the browser resizes.

Here's what I did:

· Set html rules to 100% width & height, with 0 margin to establish
inheritance.
· Set body to 100% width & height, but added a 1em margin to surround
the page.
· Created the two content divs "left-content" and
"right-content", set height and width to 100% , added some color,
padding and a little text.
· To establish the 1em "margin" between the two divs, I created
parent divs "left" and "right". Both of these are float:left
so they display side by side, height:100% and width:50%, but I added a
.5em padding in the center to establish the 1em "margin" between
the nested content divs. (code below).

A div's default width is auto, or 100% of the container.
As others have noted the total width is the percentage PLUS margin,
padding and border. So 50% width for the two divs used all the width with
no room for the other box features.
I expected that this would work, but when testing in Foxfire and IE7,
it doesn't. If you reduce #left,#right {width:40%}, you'll see that
the 1em "margin" between the two divs doesn't appear in Foxfire or IE7.

You do not understand the CSS box model.
See <http://www.w3.org/TR/REC-CSS2/box.html>.
Change "padding" to "margin".

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
May 10 '06 #9
Thanks Jim,

Okay, I now understand that 50% is the width of the container, not
factoring in padding, margin or border. Honestly, I'm not sure what
value that is, or why I would ever use it unless I have no other
features. Since I do need those features, and would like to figure out
how to accomplish the following across the width:

margin:1em
padding:1em
width:50% of width - width of features
padding:1em
margin:1em
padding:1em
width:50% of width - width of features
padding:1em
margin:1em

I see two options, and am hoping someone else sees a better way:

(1) use Javascript, and accept that CSS can't go there.
(2) come close by using a smaller percentages.

I gather there is no way to write a CSS rule to have the browser
calculate it all (e.g., 50%-feature width)? Perhaps there's some way
to nest divs in such a way that 100% is truly equal the width I'm
shooting for? If someone can see a solution, please let me know.

thanks!

Mike

May 10 '06 #10
On Tue, 09 May 2006 04:33:20 +0800 ironcorona <ir*********@gmail.com> wrote:
| ironcorona wrote:
|
|>> and is there a way
|>> that 100% means all the area available minus the padding of the parent
|>> container?
|
| Sorry, I just re-read that. That's exactly what it means. If I set an
| element's width to 100% it will take up *all* of its parent element's
| content area.

And then some (more).

I think maybe this guy might be running into the same bug I have.

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
May 10 '06 #11
VK

Mike wrote:
Can someone please explain what 100% really means, and is there a way
that 100% means all the area available minus the padding of the parent
container?


That was discussed rather profoundly in the thread [DOCTYPE Strict uses
"correct" box model - so why is 100% width now useless?], see for
example
<http://groups.google.com/group/comp.infosystems.www.authoring.stylesheets/browse_frm/thread/7bec5fd9a15c3ebc/83a733f399e3f736>

W3C Box Model vs IE Box model is the issue.

In W3C Box Model you cannot use both 100% width and
margin/padding/border without a minor or severe layout damage. You have
to use extra wrappers around of each involved element in such case.

Of course 100% should be the width of the element, not the width of the
content IMHO. But it is as it is: IE Box is reasonable and convenient
but not standard; W3C Box is a pain in one place but standard. A plague
o' both your houses! :-)

May 10 '06 #12
"VK" <sc**********@yahoo.com> wrote in message:
That was discussed rather profoundly in the thread [DOCTYPE Strict uses
"correct" box model - so why is 100% width now useless?], see for
example
<http://groups.google.com/group/comp.infosystems.www.authoring.stylesheets/browse_frm/thread/7bec5fd9a15c3ebc/83a733f399e3f736>

W3C Box Model vs IE Box model is the issue.

In W3C Box Model you cannot use both 100% width and
margin/padding/border without a minor or severe layout damage. You have
to use extra wrappers around of each involved element in such case.

Of course 100% should be the width of the element, not the width of the
content IMHO. But it is as it is: IE Box is reasonable and convenient
but not standard; W3C Box is a pain in one place but standard. A plague
o' both your houses! :-)

I started that very thread (VK, thanks for referencing it) and sadly, the
answer to your question is that there is no answer. I agree 100% (and I
mean 100%, not 102% or 98%) with VK that the IE Box has some advantages over
the W3C box such as this very issue. If you read that thread I started,
you'll see I started to go rather insane about this and said some rather
nasty things that weren't really meant for those responding but rather
outrage at the W3C for their "perfect" box model.

All that aside, I did figure one thing out at the end that did help a bit,
which has already been mentioned - adding a single specific margin to a
parent DIV. See this page for an example:
http://www.digitolle.net/google/hotboxmodelaction.htm.

And since we're on the topic, let's add some more fun:

Can anyone figure out how to create a table that fits into a fixed-size DIV
where the table's width = 100% of the content area of the DIV and the DIV
shows a vertical scroll bar only when the table's height is too large to
fit?

In Firefox, there's no challenge at all because 100% width works as you'd
hope with the DIV having overflow:auto, but in IE, it doesn't seem to care
if there's a scroll-bar because it doesn't calculate available width in the
DIV differently if there's one there or not. Here's the sample page:
http://www.digitolle.net/google/funwithscrolling.htm (look at it with IE and
Firefox to see the differences, but the task is to get it to work in IE,
since Firefox is fine.)
May 10 '06 #13
VK

Shadow Lynx wrote:
In Firefox, there's no challenge at all because 100% width works as you'd
hope with the DIV having overflow:auto, but in IE, it doesn't seem to care
if there's a scroll-bar because it doesn't calculate available width in the
DIV differently if there's one there or not. Here's the sample page:
http://www.digitolle.net/google/funwithscrolling.htm (look at it with IE and
Firefox to see the differences, but the task is to get it to work in IE,
since Firefox is fine.)


Big Brother always loves you. Do you love him? :-))

(Just use one of regular hacks to hide expression from other browsers
and - if you care - from CSS Validator)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>$Template$</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
</style>
</head>

<body>
<div style="width:200px; height:50px; overflow:auto; border:1px solid
blue;">
<table style="width:expression(this.clientWidth)">
<tr>
<td>Stuff</td>
<td align="right">Stuff</td>
</tr>
<td>Stuff</td>
<td align="right">Stuff</td>
</tr>
<td>Stuff</td>
<td align="right">Stuff</td>
</tr>
<td>Stuff</td>
<td align="right">Stuff</td>
</tr>
<td>Stuff</td>
<td align="right">Stuff</td>
</tr>
<td>Stuff</td>
<td align="right">Stuff</td>
</tr>
</table>
</div>
</body>
</html>

May 11 '06 #14
VK

VK wrote:
Big Brother always loves you. Do you love him? :-))


Big Brother is in reference of Microsoft, is a joke, is not intended to
endorse or promote Microsoft box model.

I guess I spelled all disclaimers. :-)

May 11 '06 #15
"VK" <sc**********@yahoo.com> wrote:
Big Brother always loves you. Do you love him? :-))
Is it bad if I often want to stab Big Brother in the eye? I'm thinking
about becoming a garbage man and buying a Mac.
(Just use one of regular hacks to hide expression from other browsers
and - if you care - from CSS Validator)
...
<table style="width:expression(this.clientWidth)">
...


I've considered using expressions like that one (I even spent a day working
out some ridiculously complex expressions to force IE to "override" the way
it handles its box model in Strict), but I was hoping there was a less
non-standard way to do it (wow, so many negatives in the sentence, and yet
it does actually make sense.) Standards are worthless when they're not
standard! (o;
May 12 '06 #16
On Fri, 12 May 2006 12:40:15 -0500 Shadow Lynx <sh**********@yahoo.com> wrote:
| "VK" <sc**********@yahoo.com> wrote:
|> Big Brother always loves you. Do you love him? :-))
|
| Is it bad if I often want to stab Big Brother in the eye? I'm thinking
| about becoming a garbage man and buying a Mac.

I can think of better places than the eye.

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
May 12 '06 #17

"Shadow Lynx" <sh**********@yahoo.com> wrote in message
news:51**************************@FOXVALLEY.NET...
"VK" <sc**********@yahoo.com> wrote in message:
That was discussed rather profoundly in the thread [DOCTYPE Strict uses
"correct" box model - so why is 100% width now useless?], see for
example
<http://groups.google.com/group/comp.infosystems.www.authoring.stylesheets/browse_frm/thread/7bec5fd9a15c3ebc/83a733f399e3f736>

W3C Box Model vs IE Box model is the issue.

In W3C Box Model you cannot use both 100% width and
margin/padding/border without a minor or severe layout damage. You have
to use extra wrappers around of each involved element in such case.

Of course 100% should be the width of the element, not the width of the
content IMHO. But it is as it is: IE Box is reasonable and convenient
but not standard; W3C Box is a pain in one place but standard. A plague
o' both your houses! :-)

I started that very thread (VK, thanks for referencing it) and sadly, the
answer to your question is that there is no answer. I agree 100% (and I
mean 100%, not 102% or 98%) with VK that the IE Box has some advantages
over the W3C box such as this very issue. If you read that thread I
started, you'll see I started to go rather insane about this and said some
rather nasty things that weren't really meant for those responding but
rather outrage at the W3C for their "perfect" box model.

All that aside, I did figure one thing out at the end that did help a bit,
which has already been mentioned - adding a single specific margin to a
parent DIV. See this page for an example:
http://www.digitolle.net/google/hotboxmodelaction.htm.


Something like this might work

html div structure

<div id="outer">
<div id="left"></div>
<div id="right"></div>
</div>

css for this

outer {padding-left: [left's left margin and padding and right margin and
padding added together];
padding-right: [right's left margin and padding and right margin and
padding added together]
margin: 0; width: auto}
left {width: 50%; position: relative; left: -[left's right margin and
padding]}
right {width: 50%; position: relative; left: [right's left margin and
padding]}

--
Martin Eyles
May 15 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by =?Utf-8?B?VGhvbWFzWg==?= | last post: by
4 posts views Thread by David C. Ullrich | last post: by

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.