Results 1 to 2 of 2

Thread: Center floated divs inside other div

  1. #1
    cunyao is offline New Member: Posts Will Be Moderated
    Join Date
    Jun 2011
    Posts
    1

    Center floated divs inside other div

    Hello,

    I have several divs within a div that I want to center but I can not, I did many tests and internet search. I want all divs inside the div "cartelleria" be likw now but centered. I mean that the left margin of the first div and the right margin of the last to have the same size on the div "cartelleria". I hope you understand. Here is the code:

    HTML:
    Code:
    <html>
    <head>
    <link type="text/css" rel="stylesheet" href="prova.css">
    <head>
    <body>
          <div id="cartelleria" class="clearfix" >
            <div class="cartell" id="ed2001"><a href="edicio2001.html">2001</br><img src="imatges/cartell2001.jpg"></a></div>
            <div class="cartell" id="ed2002"><a href="edicio2002.html">2002</br><img src="imatges/cartell2002.jpg"></a></div>
            <div class="cartell" id="ed2003"><a href="edicio2003.html">2003</br><img src="imatges/cartell2003.jpg"></a></div>
            <div class="cartell" id="ed2004"><a href="edicio2004.html">2004</br><img src="imatges/cartell2004.jpg"></a></div>
            <div class="cartell" id="ed2005"><a href="edicio2005.html">2005</br><img src="imatges/cartell2005.jpg"></a></div>
            <div class="cartell" id="ed2006"><a href="edicio2006.html">2006</br><img src="imatges/cartell2006.jpg"></a></div>
            <div class="cartell" id="ed2007"><a href="edicio2007.html">2007</br><img src="imatges/cartell2007.jpg"></a></div>
            <div class="cartell" id="ed2008"><a href="edicio2008.html">2008</br><img src="imatges/cartell2008.jpg"></a></div>
            <div class="cartell" id="ed2009"><a href="edicio2009.html">2009</br><img src="imatges/cartell2009.jpg"></a></div>
            <div class="cartell" id="ed2010"><a href="edicio2010.html">2010</br><img src="imatges/cartell2010.jpg"></a></div>
            <div class="cartell" id="ed2011"><a href="descarrega/programa.pdf">2011</br><img src="imatges/cartell2011.jpg"></a></div>
          </div>
    
    </body>
    </html>
    CSS:

    Code:
    #cartelleria {
      background-color: #2acfe2;
      padding-top: .5em;
      padding-bottom: 0.5em;
      text-align: center;
      width: 800px;
      margin: 0 auto;
    }
    
    .cartell {
      text-align: center;
      font-size: small;
      float: left;
      margin-right: 2em;
    }
    
    .cartell a {
      border: none;
      color: white;
      text-decoration: none;
      font-weight: bold;
    }
    
    .cartell img {
      border: 1px solid #41b0a1;
    }
    
    .cartell img:hover {
      border: 1px solid white;
    }
    
    /**
     * Markup free clearing.
     *
     * @see http://perishablepress.com/press/2009/12/06/new-clearfix-hack
     */
    .clearfix:after {
      content: ".";
      display: block;
      height: 0;
      clear: both;
      visibility: hidden;
    }
    /* IE6 */
    * html .clearfix {
      height: 1%;
    }
    /* IE7 */
    *:first-child + html .clearfix {
      min-height: 1%;
    }

  2. #2
    Irishfaithful is offline New Member: Posts Will Be Moderated
    Join Date
    Jun 2011
    Posts
    3
    margin: auto sets equal width margins on both sides. margin-left: auto will push the div to the the left and for margin-right as well. you can also <div align="center">

Similar Threads

  1. How do I stop floated divs from wrapping?
    By BoroDrummer in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 01 Mar 2011, 08:01 AM
  2. Center a div inside another div
    By Lynxo in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 12 Jan 2007, 07:20 AM
  3. footer won't clear floated nested divs
    By gela in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 10 Dec 2005, 10:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •