www.webdeveloper.com
Results 1 to 4 of 4

Thread: css div spacing proving within div ...

Hybrid View

  1. #1
    Join Date
    Aug 2013
    Posts
    4

    css div spacing proving within div ...

    Hello:

    I am trying to get all my divs inside 1 main one ( .pepe ), but it is not working properly. I am basically having problems with the .pepe part as I want all the others to fit inside that main div. I know this is simple but I am still struggling. Any help would be appreciated.


    PS: I know it is suppose to be external css file, but for testing I like to place inside the document so that the refreshing always loads the style. I also know the naming sucks, but again, it is just part of the testing part of this. I also know that I should NOT use tables for styling, and I won't as these will be data tables later in life. I would move away from data tables, but for now, I just have to get this working and any advice on that would also be appreciated.


    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Search Results</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <link href="pepe.css" rel="stylesheet" type="text/css">
    
    <style type="text/css">
    
    
    .pepe
    {
       border: 1px solid pink;
       padding:  25px;
       margin-bottom:  50px;
       margin: 0 auto;
    }
    
    
    #peter01
    {
    width: 25%;
    border: 1px solid green;
    height:  50px;
    float: left;
    }
    
    
    #peter02
    {
    width: 74%;
    border: 1px solid yellow;
    height:  175px;
    float: left;
    }
    
    #peter03
    {
    width: 84%;
    border: 1px solid pink;
    height:  55px;
    }
    
    #peter04
    {
    width: 45%;
    border: 1px solid red;
    height:  45px;
    float: left;
    }
    
    #peter05
    {
    width: 45%;
    border: 1px solid blue;
    height:  45px;
    float: left;
    }
    
    
    
    @media ( max-width:680px )
    {
       #peter05
       {
          clear: both;
          width: 75%;
          border: 1px solid blue;
          height:  45px;
          float: left;
       }
    }
    
    </style>
    
    </head>
    
    <body>
    
    
    
    <div class="pepe">
       <div id="peter01">PICTURE</div>
       <div id="peter02">
          <div id="peter03">4 COLUMNS</div>
          <div id="peter04">1 TABLE</div>
          <div id="peter05">1 TABLE</div>
       </div>
    
    
    
    
    
    
    
    </div>
    
    
    </body>
    </html>

  2. #2
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    If you're talking about the main <div> not properly containing its children, you could sort that out with a clearing element:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Search Results</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <link href="pepe.css" rel="stylesheet" type="text/css">
    
    <style type="text/css">
    
    
    .pepe
    {
       border: 1px solid pink;
       padding:  25px;
       margin-bottom:  50px;
       margin: 0 auto;
    }
    
    
    #peter01
    {
    width: 25%;
    border: 1px solid green;
    height:  50px;
    float: left;
    }
    
    
    #peter02
    {
    width: 74%;
    border: 1px solid yellow;
    height:  175px;
    float: left;
    }
    
    #peter03
    {
    width: 84%;
    border: 1px solid pink;
    height:  55px;
    }
    
    #peter04
    {
    width: 45%;
    border: 1px solid red;
    height:  45px;
    float: left;
    }
    
    #peter05
    {
    width: 45%;
    border: 1px solid blue;
    height:  45px;
    float: left;
    }
    
    
    
    @media ( max-width:680px )
    {
       #peter05
       {
          clear: both;
          width: 75%;
          border: 1px solid blue;
          height:  45px;
          float: left;
       }
    }
    
    </style>
    
    </head>
    
    <body>
    
    
    
    <div class="pepe">
       <div id="peter01">PICTURE</div>
       <div id="peter02">
          <div id="peter03">4 COLUMNS</div>
          <div id="peter04">1 TABLE</div>
          <div id="peter05">1 TABLE</div>
       </div>
    
    	<div style="clear: both;"></div>
    
    </div>
    
    
    </body>
    </html>
    JavaScript: Learn | Validate | Compact | bionoid

  3. #3
    Join Date
    Sep 2006
    Location
    new york
    Posts
    265
    I'm not in a position right now (no access to Dreamweaver or such) to test your code, and I'm not swift with math calculations. But wonder why the main container is a .class and not a unique #ID div? Also when using margin shorthand with 2 values [margin: 0 auto;], the first value represents the -top and -bottom margins and the second value represents the -right and -left margins. You should not also specify margin-bottom: 50px; You can use shorthand for all 4 margins in a clock-wise manner (top, right, bottom, left) using 4 values like margin: 0 auto 50px auto;

    You could also have <br clear="all">, but that might be deprecated?

    When you figure the measurements, remember to calculate left and right padding, border, margin (x 2).
    Last edited by auntnini; 12-26-2013 at 05:19 PM. Reason: typo

  4. #4
    Join Date
    Sep 2006
    Location
    new york
    Posts
    265
    Looking at another forum (http://www.dynamicdrive.com/forums/s...thin-div-issue), I now realize the issue was a "collapsing" parent div containing floated child elements. I'd go with adding an overflow: hidden; to the parent div.

    Following up on reference to CSS box-model shorthand for margins (also borders, padding): 3 values would represent -top [right/left sides] -bottom.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles