HighDots Forums  

Two DIV with 50% width each = problem?

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss Two DIV with 50% width each = problem? in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Terry
 
Posts: n/a

Default Two DIV with 50% width each = problem? - 10-29-2004 , 09:57 PM






I'm trying to have two divs side-by-side, each taking up 50% of the
body. Sounds simple enough, right?
http://novodom.net/div.html

The code validates as XHTML 1.1 Strict.
Looks fine in Firefox, but in IE 6.x, the second DIV is below the
first one! Using 49% for each resolves the problem but I wouldn't call
that a 'solution'.

Is there something wrong with my CSS? Can anyone suggest something?
Thanks.

Reply With Quote
  #2  
Old   
Terry
 
Posts: n/a

Default Re: Two DIV with 50% width each = problem? - 10-30-2004 , 01:34 AM






My design can definitely tolerate it, don't worry.
But I'd like to have some feedback from the 'tables-for-layout-must-die'
crowd ... how do you suggest getting around that kind of problem? This
is exactly why I've stuck with tables until now: some things that take
me 2 minutes to do with tables take me hours of fidgeting to achieve
with css... arrrgh.


Original :: brucie :: 2004-10-30 02:02

Quote:
In comp.infosystems.www.authoring.stylesheets Terry said:

I'm trying to have two divs side-by-side, each taking up 50% of the
body. Sounds simple enough, right?
http://novodom.net/div.html
Looks fine in Firefox, but in IE 6.x, the second DIV is below the
first one!

IE cant do maths. you'll come across it every now and then with
different things.

Using 49% for each resolves the problem but I wouldn't call
that a 'solution'.

if your design cant tolerate a 2% variance you're in deep shit




Reply With Quote
  #3  
Old   
Invalid User
 
Posts: n/a

Default Re: Two DIV with 50% width each = problem? - 10-30-2004 , 03:59 AM



Once upon a time *Terry* wrote:
Quote:
My design can definitely tolerate it, don't worry.
But I'd like to have some feedback from the 'tables-for-layout-must-die'
crowd ... how do you suggest getting around that kind of problem? This
is exactly why I've stuck with tables until now: some things that take
me 2 minutes to do with tables take me hours of fidgeting to achieve
with css... arrrgh.


Original :: brucie :: 2004-10-30 02:02

In comp.infosystems.www.authoring.stylesheets Terry said:

I'm trying to have two divs side-by-side, each taking up 50% of the
body. Sounds simple enough, right?
http://novodom.net/div.html
Looks fine in Firefox, but in IE 6.x, the second DIV is below the
first one!

IE cant do maths. you'll come across it every now and then with
different things.

Using 49% for each resolves the problem but I wouldn't call
that a 'solution'.

if your design cant tolerate a 2% variance you're in deep shit
Set the width to 50% only for the floating div. Then the other div takes
up what's left of the screen, should be close enough to 50% even in IE

--
/Arne
http://w1.978.telia.com/~u97802964/


Reply With Quote
  #4  
Old   
Gus Richter
 
Posts: n/a

Default Re: Two DIV with 50% width each = problem? - 10-30-2004 , 04:34 AM



Terry wrote:
Quote:
I'm trying to have two divs side-by-side, each taking up 50% of the
body. Sounds simple enough, right?
http://novodom.net/div.html

The code validates as XHTML 1.1 Strict.
Looks fine in Firefox, but in IE 6.x, the second DIV is below the
first one! Using 49% for each resolves the problem but I wouldn't call
that a 'solution'.

Is there something wrong with my CSS? Can anyone suggest something?
Thanks.
An alternative is use the Tantek Box Model Hack (or some other) to
compensate specifically for IE's deficiency
http://tantek.com/CSS/Examples/boxmodelhack.html
whereby you give one value for IE and another for others.

--
Gus


Reply With Quote
  #5  
Old   
Gus Richter
 
Posts: n/a

Default Re: Two DIV with 50% width each = problem? - 10-30-2004 , 05:14 AM



brucie wrote:
Quote:
In comp.infosystems.www.authoring.stylesheets Gus Richter said:


An alternative is use the Tantek Box Model Hack (or some other) to
compensate specifically for IE's deficiency
http://tantek.com/CSS/Examples/boxmodelhack.html
whereby you give one value for IE and another for others.


much easier:

blah{width:X;} /* for IE */
blah,[nul]{width:Y;} /* for everyone else */

Now that wasn't so hard was it? Quicker than the aforegoing verbal diarrhea.

--
Gus


Reply With Quote
  #6  
Old   
PDannyD
 
Posts: n/a

Default Re: Two DIV with 50% width each = problem? - 10-30-2004 , 05:56 AM



"Terry" <a165287 (AT) yahoo (DOT) com> wrote

Quote:
I'm trying to have two divs side-by-side, each taking up 50% of the
body. Sounds simple enough, right?
http://novodom.net/div.html
Float the left <div> to the left, float the right <div> to the right.
Does that work for your real page? It does for my copy of your test page.

I used the code snippet below to give an interesting overlap effect on my
local version of your test page. Just uploaded it to the validator page and
it seems ok.
The 'lorem ipsum...' text has been removed to keep the line length short.

<div style="position:relative; width:100%">
<div style="width:75%; position:absolute; top:0: left:0">your text
here</div>
<div style="width:75%; position:absolute; top:0: right:0">your text
here</div>
</div>

I'm still wet behind the ears when it comes to website design so are there
any reasons not to use the above?

--
FZS600 - Silver/Black
GS125 - Black/Rust
Ford 100E Prefect - Black, naturally
Whisky - Aberlour Cask Strength




Reply With Quote
  #7  
Old   
Jan Roland Eriksson
 
Posts: n/a

Default Re: Two DIV with 50% width each = problem? - 10-30-2004 , 09:28 AM



On Sat, 30 Oct 2004 11:56:44 +0100, "PDannyD"
<dan1970 (AT) REMOVETHISBITscenicplace (DOT) freeserve.co.uk> wrote:

Quote:
"Terry" <a165287 (AT) yahoo (DOT) com> wrote in message
news:7a3cf1b5.0410291857.3c207467 (AT) posting (DOT) google.com
I'm trying to have two divs side-by-side, each taking up 50% of the
body. Sounds simple enough, right?
http://novodom.net/div.html

Float the left <div> to the left, float the right <div> to the right.
Does that work for your real page? It does for my copy of your test page.
No, that's not consistent. It works for some settings of the Win-IE
window width but not for others.

Try to adjust the width of your IE browsing window to find out.

--
Rex




Reply With Quote
  #8  
Old   
PDannyD
 
Posts: n/a

Default Re: Two DIV with 50% width each = problem? - 10-30-2004 , 11:57 AM



"Jan Roland Eriksson" <jrexon (AT) newsguy (DOT) com> wrote

Quote:
On Sat, 30 Oct 2004 11:56:44 +0100, "PDannyD"
dan1970 (AT) REMOVETHISBITscenicplac...reeserve.co.uk> wrote:

"Terry" <a165287 (AT) yahoo (DOT) com> wrote in message
news:7a3cf1b5.0410291857.3c207467 (AT) posting (DOT) google.com
I'm trying to have two divs side-by-side, each taking up 50% of the
body. Sounds simple enough, right?
http://novodom.net/div.html

Float the left <div> to the left, float the right <div> to the right.
Does that work for your real page? It does for my copy of your test
page.

No, that's not consistent. It works for some settings of the Win-IE
window width but not for others.

Try to adjust the width of your IE browsing window to find out.
Weird! When I resized it previously I must have by chance landed on an even
number of pixels a few times.

I tried it again with the body width set to 800px and it looked fine. I then
set the body width to 801px and the right-hand <div> was below the left-hand
<div>.

So IE6 can't correctly work out 50% of 801px. There's a rounding error
somewhere in IE6. It also shows if you use the other example where
absolutely positioned elements are enclosed within a relatively positioned
element.
The right-hand text doesn't move smoothly left as the window size is
decreased, it joggles left and right.

--
FZS600 - Silver/Black
GS125 - Black/Rust
Ford 100E Prefect - Black, naturally
Whisky - Aberlour Cask Strength




Reply With Quote
  #9  
Old   
C A Upsdell
 
Posts: n/a

Default Re: Two DIV with 50% width each = problem? - 10-30-2004 , 01:27 PM



"PDannyD" <dan1970 (AT) REMOVETHISBITscenicplace (DOT) freeserve.co.uk> wrote in
message news:cm0h6a$fnt$1 (AT) newsg4 (DOT) svr.pol.co.uk...
Quote:
No, that's not consistent. It works for some settings of the Win-IE
window width but not for others.

Try to adjust the width of your IE browsing window to find out.

Weird! When I resized it previously I must have by chance landed on an
even
number of pixels a few times.

I tried it again with the body width set to 800px and it looked fine. I
then
set the body width to 801px and the right-hand <div> was below the
left-hand
div>.

So IE6 can't correctly work out 50% of 801px. There's a rounding error
somewhere in IE6. It also shows if you use the other example where
absolutely positioned elements are enclosed within a relatively positioned
element.
Instead of 50%, use 45% or 46%. I had a similar problem, and found that
reducing the width fixed the IE problems.





Reply With Quote
  #10  
Old   
Terry
 
Posts: n/a

Default Re: Two DIV with 50% width each = problem? - 10-30-2004 , 04:00 PM



Original :: brucie :: 2004-10-30 02:41

Quote:
In comp.infosystems.www.authoring.stylesheets Terry said:

But I'd like to have some feedback from the 'tables-for-layout-must-die'
crowd ... how do you suggest getting around that kind of problem?

what problem? its not worth worrying about. how many people are going to
come across your page and run away in horror because they notice the
halves are 49 and not 50%?

you'll probably have margins/padding on the halves so just reduce them
to compensate or present 49 to IE and 50 to other browsers.

stop trying to be a control freak.



Thanks for the psychological advice brucie.
Thanks to all those who also responded with technical advice.
Thje final solution I retained was to make the floated div 50% and leave
the other one's width unspecified. Seems to work for now. I, for one,
cannot WAIT until non-compliant browsers are out of the picture... seems
far fetched but so was the global domination of Google when it came out.

Take care.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.