5

I am trying to make these blocks of info the same size regardless of the number of words each one holds. As seen in the example, when one block has less text than the other, one gets a bit smaller and the other remains a different size.

Now my question is, How do I achieve having these blocks the same size regardless of its content or image? I am also going to use another pair right below them.

Blocks aren't equal for some reason

Here is the CSS code:

 /***********All containers**************/
   .bottomContainers{
position: absolute;
margin-left: 0%;

display: inline-box;
  }

 /**********Small Containers*************/
  .container{
    max-width: 30%;
    max-height: 30%;
    margin-top:5%;
    margin-bottom: 5%;
    margin-left: 10%;
    padding-left: 2%;
    padding-right: 2%;
    padding-bottom: 2%;
background-color: #ecf0f1;
color: grey;
display: inline-block;
/*display: inline-block;*/
border-radius: 5px;
border-bottom: 2px solid grey;
 }

Here is the HTML code:

    <div class="bottomContainers" role="moreInfo">
     <!--Small Inner Containers for Information-->
     <div class="container" id="firstContainer">
          <br />
          <center><img src="img/map.png"></center>
          <br>
          <article>
             Some random text is in this block, It doesnt size like the next one
          </article>
     </div>
     <div class="container" id="firstContainer">
        <br />
        <center><img src="img/money.png"></center>
        <br>
        this is another block which also doesnt scale to the other block regardless of text inside of it
     </div>

What did I possibly do wrong here ?

1

4 Answers 4

1

I am heavily refactoring your original code in this solution. If this is a static width website then having static width cells won't be a problem. If you want this solution to be responsive you will have a lot of issues with it:

http://jsfiddle.net/VET6x/1/

I positioned the image and its corresponding text using absolute. Again that will work with a static layout, once it goes responsive there will be problems.

<div class="bottomContainers">

    <div class="container">
        <div>
            <img src="http://placekitten.com/g/80/80" />
        </div>
        <div>
            Some random text is in this block, It doesnt size like the next one
        </div>
     </div>

     <div class="container">
        <div>
            <img src="http://placekitten.com/g/80/80" />
        </div>     
        <div>
            This is another block which also doesnt scale to the other block regardless of text inside of it
        </div>
     </div>

</div>

.bottomContainers { overflow:hidden; }

.container { 
    width:200px;
    height:200px;

    float:left;
    position:relative;

    margin:5% 5%;
    padding:2%;

    background-color: #ecf0f1;
    color: grey;

    border-radius: 5px;
    border-bottom: 2px solid grey;
 }

.container > div { position:absolute; bottom:10px; }
.container > div:first-child { position:absolute; top:10px }

If it were me I would find someway to avoid static height cells.

6
  • Actually, my site is Responsive, The entire page is compatible with Tablets, Mobile browsers and desktop. One more thing, in JSFiddle the blocks are in a Vertical position which i mostly want them in a Horizontal line.
    – Samarey
    Commented Feb 18, 2014 at 1:09
  • Perhaps I should delete this answer then. It won't work very well in a responsive layout.
    – Lowkase
    Commented Feb 18, 2014 at 1:10
  • How Would i go into doing it in a Horizontal position?
    – Samarey
    Commented Feb 18, 2014 at 1:11
  • Yeah, The Blocks, In JSFiddle they are in a vertical position in which i am trying to acvchieve a Horizontal Position for both blocks
    – Samarey
    Commented Feb 18, 2014 at 1:16
  • Increase and decrease the width of your browser and jsfiddle cells. At some point the .container elements overflow its parent so they end up wrapping.
    – Lowkase
    Commented Feb 18, 2014 at 1:18
0

Here is one solution that may work for you:

Demo Fiddle

I changed up your code a bit. Using the center tag is frowned upon, also it looks like the br tags were there for spacing, which could be done with margin. I ended up giving .container a specified height, the main drawback in that being if the window is sized down too far the overflow text will be hidden.

HTML:

 <div class="bottomContainers" role="moreInfo">
     <div class="container" id="firstContainer">
        <img src="http://www.placehold.it/100x100">
        <p>
          Some random text is in this block, It doesnt size like the next one
        </p>
     </div>
     <div class="container" id="firstContainer">
       <img src="http://www.placehold.it/100x100">
       <p>
         this is another block which also doesnt scale to the other block regardless of text inside of it
       </p>
     </div>
 </div>   

CSS:

 .container{
    // your current styles here

    overflow: hidden;
    height: 200px;
    display: block;
    float: left;
 }

.container img {
    display: block;
    margin: 10px auto 0px;
} 
0

This is a quick fix, but setting an explicit height on the objects will have them all be the same height. This requires some playing around with the best size and such but it will fix your problem. I'm curious how a professional would fix this problem.

Some other things with your code. Centering the <img> using HTML is discouraged, use css instead. Also, where are the <br> tags and why are some closed but some aren't?

1
  • You're right, I am trying to now use full css for the centering instead of using plain ol html like the Center tag. As for the <br> tag, I don't know, i use them since they make a break within what needs to be divided. I feel they come useful but if it means using css to do that, i will go ahead and look into that.
    – Samarey
    Commented Feb 18, 2014 at 1:04
0

Maybe you can use display:table;, display:table-row; and display:table-cell;. This way, your div will act like column of a table. They will stay at the same height.

Take a look at this jsfiddle!

Not the answer you're looking for? Browse other questions tagged or ask your own question.