Wrox Programmer Forums
|
BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3
This is the forum to discuss the Wrox book Beginning CSS: Cascading Style Sheets for Web Design by Richard York; ISBN: 9780764576423
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2006, 01:36 PM
Registered User
 
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default IE div columns width glitch

I hope this has been addressed already, if so just point me in the direction.

I want these two columns to be side by side. They are in Firefox but IE 6 wants to put them on different lines and IE 5.2 puts them on the same line but seems to consider 100% as starting over in the second <div>. Any help would be much appreciated.

Here's the code:
Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>
    <div style="float:left;  border-collapse:collapse; width:178px; margin:0; padding:0; border: 1px solid black; background-color:#9933FF;">Hi mom</div>
    <div style=" border-collapse:collapse; width:100%; margin:0; padding:0; border: 1px solid black; background-color:#999FFF;">Hi dad</div>
    </body>
    </html>
 
Old February 11th, 2006, 06:26 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Yep, I've seen that bug before. I discussed it in Beginning CSS on page 510 and 511. Let me know if you have any further questions about it.

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old February 11th, 2006, 06:36 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Also, just wanted to point out the border-collapse property applies only to tables.
http://www.w3.org/TR/CSS21/tables.html#borders

<div> elements, as generic block-level elements also have no margin or padding applied by default.

Although I can see you're probably just including those to try and get around the annoying behavior in IE :-)

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old February 16th, 2006, 12:30 PM
Registered User
 
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!

After reviewing the pages you mentioned it appears that whether I float or use position:absolute on the first column, the second column will behave as if it is on an entirely different screen with the original width.

Yes, I tried the same exercise using absolute positioning but this makes the same thing happen on all browsers, not just IE.

I am able to get the desired effect using <table>, but would like to do it using <div>.

The basic situation I'd like to make happen is as follows (graphics are poor but the main concern is getting this to fit cleanly within the browser window without the scroll bar coming up and the width being left column + full window width):
http://www.madisc.org/CSS%20Studies/...umn%20CSS.html

Code:
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test 2 Column CSS</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style>
<!--
body {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
font-weight:normal;
width:100%;
margin:0;
padding:0;
border:0;
background-image:url(images/boss_bg.gif);
border-collapse:collapse;}

.main {
width:100%;
margin:0;
padding:0;
border:0;
border-collapse:collapse;}

.col1 {
position:absolute;
width:200px;}

#topleft {
vertical-align:top;
border-collapse:collapse;}

.col2 {
width:100%;
position:absolute;
margin:0 0 0 200px;    
border-collapse:collapse;}

img {
margin:0;
padding:0;
border:0;
border-collapse:collapse;}
-->
</style>
</head>
<body>
<div class="main">
    <div class="col1">
        <div>    
            <table id"topleft" cellpadding="0" cellspacing="0">
                <tr>
                    <td><img src="images/lftbyhdr.gif" style="width:30px; height:270px;" alt="top left header photo" /></td>
                    <td><img src="images/rtbyhdr.gif" style="width:170px;" alt="top left header photo" /></td>
                </tr>
            </table>
        </div>
    </div>
    <div class="col2">
        <div>
            <div style="width:100%; background-color:#6699CC;"><img src="images/header_spacer.gif" style="height:126px; width:100%;" alt="top right header graphic" /></div>
    </div>
</div>
</body>
</html>
This is a great feature of WROX books; being able to get answers from the authors. Do all authors frequent their books forums? I just ordered two more WROX books for PHP5 and LAMP.

Thanks again for your help with this.


 
Old February 23rd, 2006, 05:51 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Hi discgolfer, I'm reviewing your code and trying to see what's what.

First what I'm seeing is a tendency for you to use 100% width, although you probably don't want that. <div> elements are block elements by default. As block elements, their width is expand-to-fit, so they already take up all the space available to them horizontally, by default. Percentage width also introduces some inconsistencies, a <div> with auto width is not the same as a <div> with a width of 100%. Auto width lets the <div>'s content width shrink as things like border, padding and margins are applied.

You also used a lot of margin: 0;, border: 0;, padding: 0; on <div> elements (no doubt to try and figure out why the content was growing larger than the screen). <div> elements have no border, margin, or padding applied by default, so these declarations are unnecessary.

I've taken a stab at what I think you're trying to get to.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test 2 Column CSS</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style>

body {
    font: normal 11px Verdana, Arial, Helvetica, sans-serif;
    margin: 0;   /* <body> does have default margin or padding depending on the browser, so it's good to remove this */
    padding: 0;
    background:url(images/boss_bg.gif);
}

/* border-collapse has no effect on any element but <table> and <td> elements. */
.col1 {
    position: absolute;
    width:200px;
    top: 0;
    left: 0;
    min-height: 500px;  /* When you don't include any content, the element has zero height, 
                           this minimum height ensures we see the background I've applied.
                        */
    background: gold;   /* Just included this so I could see the dimensions of the <div> */
}
.col2 {
    position: absolute;
    top: 0;
    left: 200px;
    right: 0;     /* The left and right combination of offset properties is used to imply width, 
                     this is necessary since absolutely positioned block elements use 
                     shrink-to-fit width instead of expand-to-fit width, as it would if 
                     the <div> were statically positioned.

                     Explorer doesn't support this, so we'll have to include a hack.
                  */
    min-height: 500px; 
    background: lightyellow;  /* Again, just including a background so I can see 
                                where the edges of the columns are.
                              */
}
img {
    border: none;
}
</style>

<!--[if lt IE 7]>
    <style type='text/css'>
    .col2 {
        width: expression(document.getElementById('doc').offsetWidth - 200); 
             /* Explorer's proprietary expression() feature can be used to simulate
                certain things that Explorer doesn't support, such as the combination
                of opposing offset properties to imply width or height.
                I'm on a Mac right now, so I don't have access to Explorer to test, 
                you may need to increase or decrease the amount being subtracted from 
                the offsetWidth of the <body> element to make output match Firefox.
             */
        height: 500px;
             /* Height in Explorer can be used to simulate the standard min-height property */
    }
    .col1 {
        height: 500px;
    }
    </style>
<![endif]-->
</head>
<body id='doc'>
<div class="main">
    <div class="col1">
        <div>
            <table id="topleft" cellpadding="0" cellspacing="0">
                <tr>
                    <td><img src="images/lftbyhdr.gif" style="width:30px; height:270px;" alt="top left header photo" /></td>
                    <td><img src="images/rtbyhdr.gif" style="width:170px;" alt="top left header photo" /></td>
                </tr>
            </table>
        </div>
    </div>
    <div class="col2">
        <div>
            <div style="background: #69C;"><img src="images/header_spacer.gif" style="height:126px; width:100%;" alt="top right header graphic" /></div>
    </div>
</div>
</body>
</html>
> This is a great feature of WROX books; being able to get answers from the authors. Do all authors frequent their books forums? I just ordered two more WROX books for PHP5 and LAMP.

Some Wrox authors do, some are nowhere to be found. I see Imar Spaanjaars, Joe Fawcett, Nicholas Zakas in the forums quite frequently. I haven't seen the Beginning or Professional PHP5 books' authors on, but the authors of Beginning PHP5, Apache, and MySQL Web Development are active in the forums.

I hope that helps! Please let me know if you have more questions.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design





Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Sizing Div Width with window resizing javs Javascript 1 March 20th, 2008 01:13 AM
accessing dynamic div width data Ma7T Javascript 1 August 18th, 2005 03:50 PM
Dynamic div - width Ma7T Javascript How-To 2 August 18th, 2005 09:40 AM
Visible property glitch bmains VS.NET 2002/2003 3 May 5th, 2004 02:36 PM
Width in pixels from width in percentage bsausser Classic ASP Basics 1 December 31st, 2003 02:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.