The second floating offspring aligns with the subsequent line of the main element

I'm currently working on resolving an issue with a parent div containing 3 floating children. I previously asked for help, but the solution provided only partially fixed the problem. For more information, you can click here.

The issue arises because the width of the second child div is unknown, while the first and third child divs have fixed widths. Additionally, both the first and second child divs have fixed heights.

To address this issue, the third child div is set to display: block !important; clear: both; width: 100%; so that it moves to the next row and occupies the entire space of the parent div.

The main challenge lies in ensuring that the second child div expands horizontally while remaining aligned with the first child div.

In relation to my previous question, using display: inline-table; does not allow content to be scrollable if it overflows.

.container {
  background: #ccc;
  overflow: hidden;
  float: left;
  padding:5px;
}
.floating-box {
  float: left;
  width: 150px;
  height: 75px;
  margin: 5px;
  border: 3px solid #73AD21;
}
.floating-box2 {
  float: left;
  width: auto;
  height: 75px;
  margin: 5px;
  border: 3px solid #73AD21;
}
.floating-box3 {
  float: left;
  clear: both;
  width: 100%;
  height: 75px;
  margin: 0;
  background: magenta;
}
<div class="container">
  <div class="floating-box">Floating box</div>
  <div class="floating-box2">Floating box Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minus necessitatibus adipisci quisquam ducimus dolor fugit, officia perferendis harum temporibus laborum iure numquam, assumenda dignissimos neque, quod doloribus nihil autem dolores!</div>
  <div class="floating-box3">Floating box</div>
</div>

JSFiddle

Answer №1

If you're looking to achieve this layout using Flexbox, you can do so by following these steps:

/* Resetting browser defaults */
* {margin:0;padding:0;box-sizing:border-box}
html, body {width:100%}

.flex-container {
  display: flex;
  flex-wrap: wrap;
}

.flex-container > div {border:1px solid}

.one {
  flex: 0 0 200px; 
}

.two {
  flex: 0 1 auto;
  max-width: calc(100% - 200px);
  word-wrap: break-word;
}

.three {
  flex: 1 1 calc(100% - 200px); 
}

.one, .two {height:100px} 
<div class="flex-container">
  <div class="one">1</div>
  <div class="two">2
    ..........Your content here..........
  </div>
  <div class="three">3</div>
</div>

Answer №2

Thank you, @VXp. I used a CodePen as reference and experimented with flexbox to achieve a result that is very close to my desired outcome.

    body {
      padding: 2em; 
    }

    .wrapper {
      display: flex;  
      flex-flow: row wrap;
      font-weight: bold;
      text-align: center;
    }

    .wrapper > * {
      padding: 10px;
      flex: 1 100%;
    }

    .aside-1 {
      background: gold;
      flex: 1 auto;
      height: 155px;
      max-width: 155px;
    }

    .main {
      text-align: left;
      background: deepskyblue;
      flex: 3 0px;
      order: 2;
      height: 155px;
    }

    .footer {
      background: lightgreen;
      order: 3;
    }
    <div class="wrapper">
      <aside class="aside aside-1">Aside 1</aside>
      <article class="main">
        <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>  
      </article>
      <footer class="footer">Footer</footer>
    </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript's method .focusout() is used to trigger when

Looking to create a custom select box. Is there a way to hide the <ul> when the mouse is clicked outside of the list element? Ideally, this should be accomplished without using jQuery and considering that "onblur" does not capture mouse clicks that ...

Characters with accents appear larger compared to regular letters

Currently, I am working on a website that includes special characters like č, ď, ň, ř, š, ž. However, these special letters are appearing larger than the normal letters. For example: https://i.sstatic.net/WBNQg.png I have a .properties file where I ...

Why is it common to come across <input name="next" /> in HTML forms? Explaining the purpose of the 'name' attribute in input tags

For a long time, I struggled to understand the purpose of the 'name' attribute in html forms. After referring to John Duckett's book on HTML and CSS, I finally found some clarity: When users input data into a form, it is essential for the s ...

Achieve visibility of sibling <div> without the need for JavaScript by utilizing the :checked CSS pseudo class

I've been attempting to implement the technique demonstrated in this article, but I'm struggling to achieve the desired effect of revealing new elements after a radio button is selected. .reveal-if-active { opacity: 0; max-height: 0; ove ...

The seamless integration of an HTML dropdown list in a form with a PHP email feature

Take a look at this HTML code snippet with PHP integration. How can I achieve this? I'm fairly new to coding. I'm currently developing a contact form that includes a dropdown menu for selecting an email address related to a specific physician. I ...

Steps for creating a fade effect between two different elements when the mouse is interacting with one of them

I want to create a unique effect with an image in the background and a button above it. When the mouse hovers over the button, I want its opacity to decrease while the image's opacity increases simultaneously. I have experience applying fade effects ...

Transform several dropdown menus on a single webpage into multiple unordered lists

Looking for assistance with customizing the output of variant select boxes on my webshop. Instead of displaying the variants as a select box, I would like them to appear as text or in a ul/li format. <div class="stock proid"> <p>0-6 mdr.& ...

Detecting collisions using CSS animation

I'm currently working on a unique "game" project. Check out the code snippet here: jsfiddle function update() { coyote.applyForce(gravity); coyote.edges(); coyote.update(); cactus.update(); if (coyote.intersects(cactus)){ alert("colisio ...

I'm curious about the specific sequence of CSS properties order recommended by Stylelint. Where can I locate

With Stylelint's CSS order option enabled, I'm having trouble getting Visual Studio Code to display the errors. Where can I locate the declaration/property order being used? Below is a snippet of my .stylelintrc.js configuration file: module.exp ...

How can I turn off pop-up notifications?

Would it be feasible to close a popup when clicking anywhere on the window using just pure Javascript? function popItUp() { var popup = document.getElementById("myPopup"); popup.classList.toggle("show"); } The CSS for the popup is as ...

The Multipart Parser encountered an unexpected end of stream error while in the starting state

i encounter this issue when attempting to submit a form link(rel='stylesheet',href='/stylesheets/home/profile/home_menu.css') script(type='text/javascript',src='/javascripts/perfil_editar.js') #logo_usuario img ...

Implementing Jquery to Repurpose a Function Numerous Times Using a Single Dynamic Value

Important: I have provided a functional example of the page on my website, currently only functioning for the DayZ section. Check it out here Update: Below is the HTML code for the redditHeader click event <div class="redditHeader grey3"> & ...

Using Bootstrap 4 to create a fixed-top navbar and other sticky-top elements

Check out the reproduction here: https://jsbin.com/lawafu/edit?html,output Could this be a bug, an error, a challenge, or an unattainable concept? Prior to scrolling: After scrolling: What I require: Essentially, I need the sidebar to remain visible a ...

Display the footer of the table on the bottom of the final page

I have implemented a table as a footer on all my pages, which seems to work fine in Firefox. You can view the project on JS Fiddle: https://jsfiddle.net/j9k2xzze/ If you want to see how it looks properly, right click on the output pane, select "This Frame ...

Arrange fixed-position elements so that they adhere to the boundaries of their adjacent siblings

Is there a way to keep two fixed elements aligned with their sibling element on window resize? <div class="left-img"> IMAGE HERE </div> <!-- fixed positioned --> <div class="container"> Lorem ipsum... </div> <div class=" ...

Trying to retrieve a CSS property using jQuery

Having trouble retrieving the correct CSS value for a background using a spectrum.js color picker. No matter which color is chosen, rgba(0,0,0,0) is always selected. Strangely enough, when checking the background in the console, it shows up correctly in th ...

Borderless thumbnails in the stunning blueimp Gallery

My website is utilizing blueimp Gallery, however, the thumbnails are displaying with a white border. The live demo does not have this border. I have attempted to adjust the thumbnail size to match the demo (86x86px), but that did not fix my issue. After re ...

Can the information from a form be automatically submitted to the server upon selection?

<div class="modal-body modal-body-step-2"> <form action="prenotazioni.php" method="post"> <div class="input-group"> <input type="radio" name="spettacolo" value="Lo Schiaccianoci">Lo Schiaccianoci<br> ...

How can I invoke a PHP script using AJAX?

I am currently working on implementing a feature that involves multiple tables where users can move table rows between the tables. I want to use ajax to call a php script that will update the database with the new values, specifically assigning a new paren ...

I am facing issues with the snap-scroll CSS feature, despite trying everything I can think of. I'm at a loss as to what the problem could be, and I suspect

I'm having trouble getting this to work properly. I can't figure out what I'm doing wrong. I've set the snap start and parent container with snap type styling in my current project using react, gatsby, and scss. Here is my code: index. ...