We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26931
    • 2,314 Posts
    Hi everybody,

    i’m trying to get three equally wide divs stretch across the whole browser width with a 2px gap between each...does anyone know how i could achieve this, or point me in the right direction smiley ?

    you can see a demo here: www
    right now all three divs stretch 100% of the browser width, safari produces a little gap (IE6 can totally be ignored)

    thanks, j

    *edit: oh...and they need to have 100% height
      • 19889
      • 616 Posts
      you could float them to the left using a with of 33.33 % - then I’d add another div inside and use either margin or padding of 1px.
        • 26931
        • 2,314 Posts
        thanks mmjaeger,

        but somehow i can’t apply a margin or padding to a nested div...looks like it’s not possible to mix % with px width
          • 19889
          • 616 Posts
          I don’t think there should be an issue applying a padding or margin to the inner div - not the one with the percentage but a child-element.
            • 22840
            • 1,572 Posts
            I would have thought something like this would work but I’ve not tested it:

            XHTML:
            <div id="outer-one">
               <div id="inner-one"></div>
            </div>
            
            <div id="outer-two">
               <div id="inner-two"></div>
            </div>
            
            <div id="outer-three">
              <div id="inner-three"></div>
            </div>
            


            CSS:

            * { /* to reset all padding and margin */
            margin: 0;
            padding: 0;
            }
            
            #outer-one, #outer-two, #outer-three {
            float: left;
            width: 33.3%;
            margin: 0;
            padding: 0;
            background: #000;
            height: 200px;
            }
            
            #inner-one, #inner-two, #inner-three {
            width: 100%;
            height: 196px;
            margin: 2px;
            background: #fff;
            }
            
              • 19889
              • 616 Posts
              #inner-one, #inner-two, #inner-three {
              height: 196px;
              margin: 2px;
              background: #fff;
              }
              


              no need to set the width of the inner div - setting it to 100% and add a margin would be wider than just 100%;
              as a block element, the div element uses the whole with anyway.
                • 26931
                • 2,314 Posts
                laugh thanks guys - we’re making progress here smiley

                -> http://www

                checked it with FF3.5 / Safari4 / IE7 / Opera10 & Chrome ... looking good

                the scalable background doesn’t work at the moment since it’s positioned absolute...(i try to wrap the outer divs in another wrapper div):
                #supersize{position:fixed;}
                #supersize img{height:100%;position:absolute;width:100%;z-index:0;}

                <div id="supersize">
                <img src="skaleablebg.jpg" />
                </div>

                *edit: okay, seems to work - thanks! / hopefully i won’t be back for more questions wink
                  • 4971
                  • 964 Posts
                  You can use a CSS Framework, try BlueTrip http://bluetrip.org/,
                  it is a conglomaration on BluePrint, Tripoli and another one I do not remember.

                  Then you just have to set your divs as columns and that is it, really easy, fast and
                  convenient...
                    Website: www.mercologia.com
                    MODX Revo Tutorials:  www.modxperience.com

                    MODX Professional Partner
                    • 26931
                    • 2,314 Posts
                    You can use a CSS Framework, try BlueTrip http://bluetrip.org/
                    oh thanks, i’ll look into that
                      • 1169
                      • 312 Posts
                      Have you found solution to your problem if not you could try

                      to modify (by changing %’s) in http://matthewjamestaylor.com/blog/perfect-3-column.htm percentage view
                        DEVELOPMENT ENV:- Ubuntu 12.04 | MODx Revolution 2.2.8 | LAMP 2i Apache 2.2.22 | Php 5.3.10 | Mysql 5.5.31 MySQL client version: 5.5.31