11 Replies Latest reply: Jan 18, 2010 10:39 AM by janken71 RSS

    CSS Width percentage layout issues

    janken71 Community Member

      In attempting to design backward to at least IE6, I encountered a problem using widths for my navigation menu.

       

      See here: http://www.accu-sembly.com/test/services.html

       

      It appears fine in IE7+, Firefox, Chrome, and Opera, but in IE6 it seems to set all my button widths to width:auto rather than the percentage I set for them, which was width:16.6%.

       

      I attempted to use fixed pixels previously and found IE6 overflowing the last button into the next line (a sizing misinterpretation?) and so I thought percentages was the answer.

       

      I understand that IE6 doesn't know how to calculate the percentages from the containing div, and so it defaults to the width:auto style.  Is there anything I can do to force IE6 to recognize the percentages calculated from its container, or do I need to just live with the overflow with a fixed pixel layout?

        • 1. Re: CSS Width percentage layout issues
          pziecina CommunityMVP

          Hi

           

          There are a number of things that 'may' work, but there are no guarantees.

           

          See - http://www.positioniseverything.net/explorer/percentages.html.

           

          PZ

          • 2. Re: CSS Width percentage layout issues
            janken71 Community Member

            I tried some of the work-arounds, to no avail =(

             

            What is the usual solution for a percentage based navigation?  Or are the fixed-pixel widths preferred for exactly this compatibility reason?

            • 3. Re: CSS Width percentage layout issues
              pziecina CommunityMVP

              Hi

               

              You could use IECC's for just IE6 using pixels widths, that way all other browsers would still have a percentage based layout.

               

              IECC's - http://www.quirksmode.org/css/condcom.html.

               

              PZ

              • 4. Re: CSS Width percentage layout issues
                janken71 Community Member

                I attempted to wrap the appropriate CSS in those conditional comments, but something still doesn't seem to be working right.  The widths are still being calculate off the main CSS:

                 

                #navcontainer {

                     float:left;

                     font-family: Arial, Helvetica, sans-serif;

                     width: 1002px;

                      background-color:#05406E;

                      overflow:hidden;

                }

                 

                /* to stretch the container div to contain floated list */

                #navcontainer:after {

                        display: block;

                        line-height: 1px;

                        font-size: 1px;

                        clear: both;

                }

                 

                <!- -[if IE 6]>

                ul#navlist li {

                     display: block;

                     float: left;

                      width:100px;

                     margin: auto;

                     padding: 0 0 0 0;

                }

                 

                ul#navlist li a {

                     display: block;

                     width: 100px;

                     padding: 0.4em;

                     border-width: 3px;

                     border-color: #05406E;

                     border-style: solid;

                     color: #FFFFFF;

                     text-decoration: none;

                     background: #003366;

                }

                 

                <![endIf]-->

                 

                ul#navlist {

                     list-style: none;

                     padding: 0 0 0 0;

                     margin: auto;

                     /*width: 1002px;*/

                     font-size: 10pt;

                }

                 

                 

                ul#navlist li {

                     display: block;

                     float: left;

                    width:167px;

                     /*width: 16.6%;*/

                     margin: auto;

                     padding: 0 0 0 0;

                }

                 

                ul#navlist li a {

                     display: block;

                     width: 167px;

                     padding: 0.4em;

                     border-width: 3px;

                     border-color: #05406E;

                     border-style: solid;

                     color: #FFFFFF;

                     text-decoration: none;

                     background: #003366;

                }

                 

                #navcontainer>ul#navlist li a {

                     width: auto;

                }

                 

                ul#navlist li#active a {

                     background: #003366;

                     color: #FFFFFF;

                }

                 

                ul#navlist li a:hover, ul#navlist li#active a:hover {

                     color: #003366;

                     background: #A8CBE9;

                }

                Did I do something wrong?

                • 5. Re: CSS Width percentage layout issues
                  pziecina CommunityMVP

                  Hi

                   

                  Did you format the IECC correctly and enclose the css inside this, e.g. -

                  <!--[if IE6]>
                  <style type="text/css">
                  /* place css fixes for the version of IE here */
                  </style>
                  <![endif]-->

                   

                  PZ

                  • 6. Re: CSS Width percentage layout issues
                    janken71 Community Member

                    Yes I used the conditional comments:

                    <!--[if IE 6]>

                    ul#navlist li {

                         display: block;

                         float: left;

                          width:100px;

                         margin: auto;

                         padding: 0 0 0 0;

                    }

                     

                    ul#navlist li a {

                         display: block;

                         width: 100px;

                         padding: 0.4em;

                         border-width: 3px;

                         border-color: #05406E;

                         border-style: solid;

                         color: #FFFFFF;

                         text-decoration: none;

                         background: #003366;

                    }

                     

                    <![endIf]-->

                    I assume that by doing this, IE 6 will use these styles instead of the ones outside of the comments?  Or do I need to do something else?

                     

                    Also, I placed them in the external stylesheet.  Does it need to be in the main HTML document?

                    • 7. Re: CSS Width percentage layout issues
                      pziecina CommunityMVP

                      Hi

                      You missed the -

                      <style type="text/css">

                      and

                      </style>

                       

                      inside the iecc.

                       

                      PZ

                      • 8. Re: CSS Width percentage layout issues
                        pziecina CommunityMVP

                        Hi

                         

                        Once you have the iecc working, you can move the styles to an external link, and replace the css with the link to the css file -

                        <!--[if IE6]>
                        <style type="text/css"> /* <-- remove this line if linking to css file but leave if importing it */
                        /* place the link here */
                        </style> /* <-- remove this line if linking to css file but leave if importing it */
                        <![endif]-->

                         

                        PZ

                        • 9. Re: CSS Width percentage layout issues
                          janken71 Community Member

                          EDIT: Didn't see your new post.  I tried it both externally and internally and it still didn't work.

                           

                          This is what's occuring in IE6, by the way:

                          ie6widthissue.JPG

                          The widths aren't changing no matter how small I make them ( I dropped them as low as 30px with no change).

                          • 10. Re: CSS Width percentage layout issues
                            janken71 Community Member

                            Actually, scratch my last post.  It does seem to be working with the IECC placed internally rather than in my external stylesheet.  Thanks so much for your help, once again =)

                            • 11. Re: CSS Width percentage layout issues
                              pziecina CommunityMVP

                              Hi

                               

                              Thank you for the image, it helped as I could not get the page to render in super preview, try -

                              display: inline;

                              white-space: nowrap;

                               

                              PZ