CSS Gurus inside please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jwerd
    Confirmed User
    • Jun 2003
    • 1953

    #1

    CSS Gurus inside please

    For those that know CSS pretty well should have no issue at all with this, but it's something I've never taken the time to learn how to do properly.

    I want to create 4 boxes per row, in CSS, based on a specified sized wrapper.

    So let's say we have a wrapper of 500px, how can I add in the CSS so that no matter how many boxes it creates, it only positions 4 per row (at around 120px each with 5 pixel padding).

    What's the easiest way to accomplish this?

    I've seen it done with listed items, but I can't remember how it's been done.

    The reason I want to do this in the first place is I've always done it with tables, but I want to get away from tables as much as I can and it's less backend coding if I'm doing it the CSS route.

    Thanks in advance!
    Last edited by jwerd; 01-03-2009, 01:58 PM.
    Yii Framework Guru - Seasoned PHP vet - Partner @ XXXCoupon.com
  • TheDoc
    Too lazy to set a custom title
    • Jul 2001
    • 13827

    #2
    Code:
    <div style="width:500px;">
    <div sytle="width:120px:float:left;padding:0 2px;">content</div>
    <div sytle="width:120px:float:left;padding:0 2px;">content</div>
    <div sytle="width:120px:float:left;padding:0 2px;">content</div>
    <div sytle="width:120px:float:left;padding:0 2px;">content</div>
    <div sytle="width:120px:float:left;padding:0 2px;">content</div>
    <div sytle="width:120px:float:left;padding:0 2px;">content</div>
    <div sytle="width:120px:float:left;padding:0 2px;">content</div>
    <div sytle="width:120px:float:left;padding:0 2px;">content</div>
    <br style="clear:both" />
    </div>
    ~TheDoc - ICQ7765825
    It's all disambiguation

    Comment

    • Deej
      I make pixels work
      • Jun 2005
      • 24386

      #3
      float FTW

      Deej's Designs n' What Not
      Hit me up for Design, CSS & Photo Retouching


      Icq#30096880

      Comment

      • jwerd
        Confirmed User
        • Jun 2003
        • 1953

        #4
        Originally posted by TheDoc
        Code:
        <div style="width:500px;">
        <div sytle="width:120px:float:left;padding:0 2px;">content</div>
        <div sytle="width:120px:float:left;padding:0 2px;">content</div>
        <div sytle="width:120px:float:left;padding:0 2px;">content</div>
        <div sytle="width:120px:float:left;padding:0 2px;">content</div>
        <div sytle="width:120px:float:left;padding:0 2px;">content</div>
        <div sytle="width:120px:float:left;padding:0 2px;">content</div>
        <div sytle="width:120px:float:left;padding:0 2px;">content</div>
        <div sytle="width:120px:float:left;padding:0 2px;">content</div>
        <br style="clear:both" />
        </div>
        Hey thanks for some help, but it's not quite what I'm looking for actually.

        I'm shooting more for this:
        [ ] [ ] [ ] [ ]
        [ ] [ ] [ ] [ ]
        [ ] [ ] [ ] [ ]
        [ ] [ ] [ ] [ ]
        Yii Framework Guru - Seasoned PHP vet - Partner @ XXXCoupon.com

        Comment

        • skrinkladoo
          Confirmed User
          • Oct 2007
          • 629

          #5
          Originally posted by TheDoc
          Code:
          <div style="width:500px;">
          <div sytle="width:120px:float:left;padding:0 2px;">content</div>
          <div sytle="width:120px:float:left;padding:0 2px;">content</div>
          <div sytle="width:120px:float:left;padding:0 2px;">content</div>
          <div sytle="width:120px:float:left;padding:0 2px;">content</div>
          <div sytle="width:120px:float:left;padding:0 2px;">content</div>
          <div sytle="width:120px:float:left;padding:0 2px;">content</div>
          <div sytle="width:120px:float:left;padding:0 2px;">content</div>
          <div sytle="width:120px:float:left;padding:0 2px;">content</div>
          <br style="clear:both" />
          </div>
          *** Andrew Love ***

          Services: (1) Web Design, (2) Graphic Design, (3) E-commerce, (4) Database Development,
          (5) Web Analytics, (6) Targeted Lead Generation, (7) Marketing and Consulting

          Mainstream: Successful Website Landing Page Design | ICQ: 360-83-9627

          Comment

          • nicedreams
            Confirmed User
            • Apr 2004
            • 298

            #6
            Originally posted by lamerhooD
            Hey thanks for some help, but it's not quite what I'm looking for actually.

            I'm shooting more for this:
            [ ] [ ] [ ] [ ]
            [ ] [ ] [ ] [ ]
            [ ] [ ] [ ] [ ]
            [ ] [ ] [ ] [ ]

            Put the br line after every 4th content line.

            Jimmy

            Nice Dreams Cash
            http://www.nicedreamscash.com

            Comment

            • jwerd
              Confirmed User
              • Jun 2003
              • 1953

              #7
              Originally posted by nicedreams
              Put the br line after every 4th content line.

              Jimmy
              Tried that,

              Before:
              []
              []
              []
              []
              []
              []
              []
              []

              After:
              []
              []
              []
              []

              []
              []
              []
              []

              Yii Framework Guru - Seasoned PHP vet - Partner @ XXXCoupon.com

              Comment

              • Brujah
                Beer Money Baron
                • Jan 2001
                • 22157

                #8
                Show us the page? I use the same thing and it works ok for me.

                Comment

                • Brujah
                  Beer Money Baron
                  • Jan 2001
                  • 22157

                  #9
                  Example:
                  http://www.expire.biz/test.html
                  Code:
                  <div style="width:500px">
                  <div style="float:left;width:100px;">content</div>
                  <div style="float:left;width:100px;">content</div>
                  <div style="float:left;width:100px;">content</div>
                  <div style="clear:both"></div>
                  <div style="float:left;width:100px;">content</div>
                  <div style="float:left;width:100px;">content</div>
                  <div style="float:left;width:100px;">content</div>
                  <div style="clear:both"></div>
                  <div style="float:left;width:100px;">content</div>
                  <div style="float:left;width:100px;">content</div>
                  <div style="float:left;width:100px;">content</div>
                  <div style="clear:both"></div>
                  </div>

                  Comment

                  • jwerd
                    Confirmed User
                    • Jun 2003
                    • 1953

                    #10
                    First one:

                    http://www.virbed.com/gfy/cssboxes.html

                    Second one: (with br every 4 divs)
                    http://www.virbed.com/gfy/cssboxes2.html
                    Yii Framework Guru - Seasoned PHP vet - Partner @ XXXCoupon.com

                    Comment

                    • jwerd
                      Confirmed User
                      • Jun 2003
                      • 1953

                      #11
                      I'm using Firefox 3 on OS X, just for some background on what I'm testing with. I also tested with Safari
                      Yii Framework Guru - Seasoned PHP vet - Partner @ XXXCoupon.com

                      Comment

                      • Brujah
                        Beer Money Baron
                        • Jan 2001
                        • 22157

                        #12
                        Your code has a typo

                        div sytle

                        Comment

                        • jwerd
                          Confirmed User
                          • Jun 2003
                          • 1953

                          #13
                          Originally posted by Brujah
                          Your code has a typo

                          div sytle
                          haha, didn't catch that, just copied and pasted The Doc's code to test it and didn't change anything else.

                          Thanks Man!!!
                          Yii Framework Guru - Seasoned PHP vet - Partner @ XXXCoupon.com

                          Comment

                          • Badmaash
                            Confirmed User
                            • Jan 2007
                            • 2695

                            #14
                            Hi
                            .... are the boxes going to hold images?

                            You might want to have a look at doing it using a list....

                            Lats say you make the list holder 500px wide and the boxes using li's 100px wide but wide margin you will be able to fit 4 boxes in each row as the 5th box will fall under.

                            So make teh ul = 500px, li=100px, float the li's to the left, get rid of list styling and you margins and voila.


                            <style type="text/css">

                            ul {
                            width:500px;
                            min-height:400px;
                            list-style:none;
                            padding:0;
                            margin: up to you***
                            }

                            li {
                            float:left;
                            width:100px;
                            height: up to you
                            border:1px solid #FFFFFF your choice here this will outline the boxes;
                            margin: ur choice to not have all the boxes clumped together;
                            }

                            </style>

                            <ul>
                            <li></li>
                            <li></li>
                            <li></li>
                            <li></li>
                            <li></li> <!-- this one will fall under forming the next row -->
                            <li></li>
                            </ul>



                            Obviously you gonna have to screw around with the above to get your own look and feel.


                            Ciao
                            best cbd oil uk - Hit me up on ICQ 400607632

                            Comment

                            • TheDoc
                              Too lazy to set a custom title
                              • Jul 2001
                              • 13827

                              #15
                              You have to have that funky spelling of hmtl to get my example to work
                              ~TheDoc - ICQ7765825
                              It's all disambiguation

                              Comment

                              • potter
                                Confirmed User
                                • Dec 2004
                                • 6559

                                #16
                                Code:
                                <div style="display: table;">
                                 <div style="display: table-row;">
                                  <div style="display: table-cell;"></div>
                                  <div style="display: table-cell;"></div>
                                  <div style="display: table-cell;"></div>
                                  <div style="display: table-cell;"></div>
                                 </div>
                                 <div style="display: table-row;">
                                  <div style="display: table-cell;"></div>
                                  <div style="display: table-cell;"></div>
                                  <div style="display: table-cell;"></div>
                                  <div style="display: table-cell;"></div>
                                 </div>
                                </div>
                                Code:
                                <div>
                                 <div style="float: left;"></div>
                                 <div style="float: left;"></div>
                                 <div style="float: left;"></div>
                                 <div style="float: left;"></div>
                                <div style="clear: both;"></div>
                                 <div style="float: left;"></div>
                                 <div style="float: left;"></div>
                                 <div style="float: left;"></div>
                                 <div style="float: left;"></div>
                                </div>
                                Code:
                                <div>
                                <div style="float: left;"></div>
                                <div style="float: left;"></div>
                                <div style="float: left;"></div>
                                <div style="float: left;"></div>
                                </div>
                                <div>
                                <div style="float: left;"></div>
                                <div style="float: left;"></div>
                                <div style="float: left;"></div>
                                <div style="float: left;"></div>
                                </div>
                                You could also do it using ul/li. As someone stated above me. I dunno, there's easily another twenty different ways to do this. Choose one.

                                Comment

                                • Zayne E.
                                  Confirmed User
                                  • Apr 2002
                                  • 1383

                                  #17
                                  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>
                                  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                                  <title>Untitled Document</title>
                                  <style type="text/css">
                                  ul#container_4 { list-style-type: none; width: 415px; margin: auto; }
                                  ul#container_4 li { float: left; display: block; background: #000; width: 100px; height: 100px; margin-right: 5px; margin-bottom: 5px; }
                                  ul#container_4 li.omega { margin-right: 0px; }
                                  </style>
                                  </head>
                                  <body>
                                  <ul id="container_4">
                                  	<li></li>
                                   <li></li>
                                   <li></li>
                                   <li class="omega"></li>
                                  	<li></li>
                                   <li></li>
                                   <li></li>
                                   <li class="omega"></li>
                                  	<li></li>
                                   <li></li>
                                   <li></li>
                                   <li class="omega"></li>
                                  	<li></li>
                                   <li></li>
                                   <li></li>
                                   <li class="omega"></li>
                                  </ul>
                                  </body>
                                  </html>

                                  Comment

                                  Working...