Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    5
    Member #
    39517

    [CSS] floated Divs same height

    Hi Community,

    I know there are a few tricks to get 2 Divs in the same height but I think my problem is a bit difficult.

    First of all here is a picture of my current situation:

    box_heights.jpg

    I want to stretch the right box to the bottom box. And therefor I need it to be the same height as the left column. But when I have more boxes in both columns I think this would be extremly difficult. Does anyone have any idea?

    And here is the important code:

    HTML
    HTML Code:
    <div id="content_top">
        <div class="content_box">
            <h1>Title Top</h1>
        </div>
    </div>
    <div id="content_columns">
        <div id="content_left">
            <div class="content_box">
                <h1>Title Left 1</h1>
            </div>
            <div class="content_box">
                <h1>Title Left 2</h1>
            </div>
        </div>
        <div id="content_right">
            <div class="content_box">
                <h1>Title Right</h1>
            </div>
        </div>
    </div>
    <div style="clear:both"></div>
    <div id="content_bottom">
        <div class="content_box">
            <h1>Title Bottom</h1>
        </div>
    </div>
    CSS
    HTML Code:
    #content_top {
        width: 100%;
    }
    
    #content_columns {
        width: 100%;
    }
    
    #content_left {
        height: 100%;
        width: 50%;
        float: left;
    }
    
    #content_right {
        height: 100%;
        width: 50%;
        float: right;
    }
    
    #content_left .content_box {
        margin-right: 20px;
    }
    
    #content_right .content_box {
        margin-left: 20px;
    }
    
    #content_bottom {
        width: 100%;
    }
    
    .content_box {
        margin-bottom: 20px;
        padding: 20px;
        text-align: justify;
        background-color: #f2f2f2;
        -webkit-box-shadow: 3px 4px 5px 0px rgba(191, 191, 191, 0.75);
        -moz-box-shadow:    3px 4px 5px 0px rgba(191, 191, 191, 0.75);
        box-shadow:         3px 4px 5px 0px rgba(191, 191, 191, 0.75);
    }

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    There is a way to do it with CSS, but it's an over-complicated mess. I prefer the JS route:
    Code:
    var left = document.querySelector('.content_left');
    var right = document.querySelector('.content_right');
    var leftHeight = e.clientHeight;
    
    function setHeight(){
    right.style.height = leftHeight + 'px';
    }
    
    window.onload = setHeight;
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    It's not a bad idea, but the problem with it is that it really can't be done practically. Here's why...screen font sizes are relative, and unless you use a monospaced web font your result is going to be all over the map. People resize their text quite a bit...especially older Windows users (a lot of them like their text at 125% of the normal size).

    About your only alternative is a CSS faux background, but even that's going to be messy.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  5. #4
    Junior Member
    Join Date
    Jun 2014
    Posts
    5
    Member #
    39517
    Thank You for your ideas, but I can't programm in JS and if this code wont work isn't there any other solution?

    I have an idea but don't know if it would work in JS.

    My Idea:

    If the situation would be that there were 5 left and 3 right boxes and the last boxes would have the class "last_content", couldn't I add all left heights together and all right heights together and look which one is higher? Then I could take the lower height column and substract the last box, then take the heigher column substrakted by the height before and give this result to the height of the last box in the lower column?

    I'm sorry if this is not good described, but I hope that you can help me with this problem.

  6. #5
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    I'm having a bit of a hard time following. Are you looking for the actual height of the content to be the same, or the height of the divs? The code I gave you does successfully equalize the height of the divs, but it won't make the content the same length.

  7. #6
    Junior Member
    Join Date
    Jun 2014
    Posts
    5
    Member #
    39517
    Ok I'll try to explain it better:

    I want that each column can have so many boxes they need and the last boxes of each column should be stretched to the bottom of the higher column.

  8. #7
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    What you're wanting to do won't work quite like you're hoping. Unfortunately, floats won't work that way. There is a JS library called Masonry that can kinda do what you're wanting, but the columns don't always end up the same length.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  9. #8
    Junior Member
    Join Date
    Jun 2014
    Posts
    5
    Member #
    39517
    And if I set the wrapper of both colums to "display:table;" and both columns to "display:table-cell;"? With that they were not be floated, but they were left and right.
    Would there be a solution with that situation? That problem is difficult but it is important to work! without this the website is ruined!


Remove Ads

Posting Permissions

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

Search tags for this page

same height floated divs

Click on a term to search for related topics.
All times are GMT -6. The time now is 11:02 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com