Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:47:54+00:00 2026-06-15T06:47:54+00:00

I have one div for classroom that contains div for each students. Each student

  • 0

I have one div for “classroom” that contains div for each “students”. Each “student” div contains an image. Here is the HTML:

<div class="classroom">
    <div class="student">
        <img class="student-image" src="http://dnqgz544uhbo8.cloudfront.net/_/fp/img/home/f.AmzRdUdc4pEtCuGvU03WXQ.jpg">
    </div>

    <div class="student">
        <img class="student-image" src="http://dnqgz544uhbo8.cloudfront.net/_/fp/img/home/k.jXX55KhHUWZGTAb-GpPkdg.jpg">
    </div>

    <div class="student">
        <img class="student-image" src="http://dnqgz544uhbo8.cloudfront.net/_/fp/img/home/c.ZKQXc2Kc8-po-OK6AhDbtw.jpg">
    </div>
</div>

I want to display all the “students” divs in one line so I use the following css:

body {
  padding: 0;
  margin: 0;
  overflow: hidden;
}

html, body {
    height: 100%;
}

.classroom {
    position: relative;
    height: 100%;
}

.classroom .student {
    position: relative;
    height: 100%;
    float: left;
}

.classroom .student .student-image {
    height: 100%;
}

In order the students will have enough place in the “classroom” div, I use jQuery in order the calculate the width of the “classroom”:

$(document).ready(function() {
    var w = 0;
    $(".student").each(function() {
        w += $(this).width();
    });
    $(".classroom").width(w);
});

Unfortunately the result is not what I expected. The last “student” div is going down to the next line (as if no float: left; was assigned). More weird is that when increasing the width of “Classroom” div in 1 pixel, the div returns to it position at the end of the first line.
I made those jsfiddles:
Here http://jsfiddle.net/U3gBG you can see the problem. click on the result panel and use the arrows keys in order to scroll down and right.
Here http://jsfiddle.net/U3gBG/1/ you can see the result of adding 1 to the width of the “classroom” div after calculation (the width of “classroom” equals to the sum of “students” width plus 1 pixel). This result is what I need.
I don’t understand why do I need to increase the width of the parent div by 1? Why sum all the child divs width is not enough?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:47:56+00:00Added an answer on June 15, 2026 at 6:47 am

    So based on Eyal’s comment I became curious about what is going on at the root of this problem. On my system I noticed that Chrome wrapped, but IE and FF did not. After more digging I discovered that the wrapping was due to the rendered screen area.

    You are sizing the parent using jQuery, but when dividing by three you are going to get rounding. In some cases a round down causes the container to be too narrow for the images and the third wraps. If it rounds up then you have enough room and no wrapping occurs.

    The solution I posted below is a more robust answer because it automatically recalculates on browser resize. You’d have to run your js constantly and monitor resize events to handle this with JS. Hope that helps.


    Instead of using javascript can you use CSS instead?

    Set student to display:inline. Then set parent to white-space:nowrap. They won’t wrap. Next you have to handle the whitespace between the images. As we have now set them to inline any whitespace in the html causes a gap. So if you set `font-size: 0px’ on the image container it collapses the gap. Remember to set the font back to a positive amount if the containers need to contain text. No messing with js required.

    http://jsfiddle.net/U3gBG/8/

    body {
      padding: 0;
      margin: 0;
      overflow: hidden;
    }
    
    html, body {
        height: 100%;
    }
    
    
    .classroom {
        white-space: nowrap;
        height: 100%;
        font-size: 0px;
    }
    
    .classroom .student {
        height: 100%;
        display: inline;
    }
    
    .classroom .student .student-image {
        height: 100%;
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one div classA that contains inside one sprite element of classB. I
I have one div that should contain text and bellow it one image. I
suppose i have one div and div has img tag like <div><img src='img1.png'/></div> so
i have one div and div has one img tag but image is not
I have a function in Javascript that moves one div depending on the mouse
I have one div; header, and another called headerimg containing an image. I'm trying
So i have one div element that i append on my DOM with a
So let's say i have one div and one image like this <div id=image_wrapper>
I have one Parent div. Top of the Parent div contains two child divs.
I have one div element at the top of my page that is set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.