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 7866691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:28:41+00:00 2026-06-03T00:28:41+00:00

Let me explain, I’ve got several floats in a parent div, it may be

  • 0

Let me explain, I’ve got several floats in a parent div, it may be possible that some go to new line due to parent width restriction, is it possible to do it in CSS ?

For example : style all the div like div3 and div5 and all the next div which may be break ?
(please notice width and height are not fixed in real just in my example)

http://jsfiddle.net/frntz/aMzF7/1/

Thank you.

  • 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-03T00:28:42+00:00Added an answer on June 3, 2026 at 12:28 am

    You can’t do it with just CSS. You’ll need to use some JavaScript to calculate the width of the container against the widths of your divs. The divs which would be wrapped to the next line could be determined by the accumulated div width exceeding the wrapper width, etc. JavaScript could then easily reset the width accumulation and apply the class and continue with the iteration of the child nodes until all ‘wrapped’ divs are found and styled.

    Here’s an example with jQuery:

    var maxWidth = $('#parent').width(),
        accWidth = 0;
    
    $('#parent').children().each(function(){
        accWidth += $(this).width();
        if (accWidth > maxWidth) {
            $(this).addClass('newline');
            accWidth = $(this).width();
        }
    });​
    

    Demo 1: http://jsfiddle.net/AlienWebguy/77NTw/

    Demo 2: http://jsfiddle.net/AlienWebguy/77NTw/1/

    And here’s an example with vanilla JS:

    var maxWidth = document.getElementById('parent').offsetWidth,
        accWidth = 0,
        nodes    = document.getElementById('parent').childNodes,
        i;
    
    for (i in nodes) {
        if (nodes[i].hasOwnProperty('offsetWidth')) {
            accWidth += nodes[i].offsetWidth;
            if (accWidth > maxWidth) {
                nodes[i].className += ' newline';
                accWidth = nodes[i].offsetWidth;
            }   
        }
    }
    

    Demo 3: http://jsfiddle.net/AlienWebguy/77NTw/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First let me explain. I have several addresses on the page that I put
Let me explain: There are some apps (like the Facebook app) that send emails
Let me explain with an example. If n=4 and r=2 that means all 4
Quite new to maven here so let me explain first what I am trying
Possible Duplicate: ListView.SelecctedItems shows 0 selected ok..Let me explain in better way My requirement
Let me explain the tree structure: I have a network directory where several times
Let me explain my problem, and hopefully someone can offer some good advice. I
Let me explain what I mean with that question: Lets say I have to
Let me explain what I mean in my title. Let's say, that for example
let me explain my problem. I have a mouseout event assigned to a div

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.