Styling HTML divs to fit together like a puzzle in CSS

I'm attempting to fit these divs together like a jigsaw puzzle. My goal is to position div 4 between div 1 and 3. Currently, div 4 starts below div 3. What would be the solution to make the divs seamlessly fit into each other?

<div style='overflow:hidden;width:500px;'>
            <div style='float:left;width:200px;height:400px;border:1px solid #707070'>1</div>
            <div style='float:left;width:200px;height:300px;border:1px solid #707070'>2</div>
            <div style='float:left;width:200px;height:400px;border:1px solid #707070'>3</div>
            <div style='float:left;width:200px;height:300px;border:1px solid #707070'>4</div>
            </div>

I prefer not to rely on position absolute. The code shared here is just an example. In reality, the code exists within a loop and the size of content varies dynamically.

Answer №1

JQuery Brickwork. Pure CSS lacks the dynamism required for such functionality.

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

Is there a way to adjust a vertical split layout within a section to display horizontally on mobile devices?

Within the xop-container section, there is a vertical split between two sides; however, I am struggling to use a media query to change the split into horizontal for mobile view. <section class="xop-container"> <div class="xop-left"> ...

Personalizing Material-UI Components using Styled-Components

My attempt to modify the props of a material-ui Grid component using styled-components was not successful. I initially tried: const NavGrid = styled(Grid)` direction: 'row'; ` Unfortunately, this approach did not yield the desired result. T ...

What is the best way to ensure that the CSS padding for a button matches the width of the column consistently?

I have encountered an issue where I am unable to maintain consistent padding for a button relative to the column width. This is crucial for me because the button's background changes when a user hovers over it. However, using a fixed value for the but ...

Div element positioned outside of another div element

I hate to bug you with more css issues, but I'm really struggling with this one. The problem I'm facing is that a sub div is overflowing the boundaries of its parent div. I tried using: display: inline-block;` but then the outer div goes haywir ...

The hamburger menu on the navigation bar only functions the first time it is clicked

I've encountered an issue with my hidden menu nav bar. The hamburger and close buttons only work once. Should I organize the events within a function and call it at the end, or perhaps use a loop for the button events? It's worth noting that I d ...

Updating the content within a div following the submission of a contact form 7

I'm struggling with my contact form. I want the content of my contact form div to change after clicking submit on the form. I've been searching for a solution, but so far, no luck. Here is what I have: Form (div1) with input fields, acceptance c ...

Dropdown menus integrated into a responsive navigation bar

The issue: When in responsive view, the dropdown button does not transition to the visible navigation bar from the menu icon after clicking any of its dropdown content. More details: In responsive view (screen width below 730px), the navigation bar is rep ...

What could be causing the issue with the JQuery .hide() function not functioning properly with the bootstrap spinner?

As I implement a basic spinner feedback for a server response to an ajax query, I encounter an issue. I utilize the JQuery .show() function before initiating the ajax call, and then invoke the .hide() function within the .always() callback of the request. ...

Ordering styles in Material UI

I've spent countless hours customizing this element to perfection, but the more I work on it, the more of a headache it gives me. The element in question is an outlined TextField, and my focus has been on styling its label and border. Initially, I th ...

Header that sticks to the top of the page while the image slowly fades

Can anyone help me with my jsfiddle? I have a sticky header that shrinks when scrolling down, along with a png overlay that also shrinks. However, the current animation looks bad. I tried using fadeIn with jQuery but it's not working as expected. How ...

Tips for incorporating CSS styling into imported joint js bpmn elements

Our dashboard now includes components from a company supplying us with Business Process Model And Notation (BPMN) json objects. We bring in the BPMN json object using "fromJSON()" onto the joint.dia.Paper. Everything is functioning properly. However, I ...

The scroll bar goes beyond the page boundaries

I am encountering a scrollbar issue with a bootstrap list group on my single-page website. Despite setting the page to occupy 100% of the view using flexbox, the scrollbar is extending beyond the view, and the html/body scrollbar is being utilized instead. ...

The dynamic links in Knockout.js are unresponsive to clicks

I've been working on a new project that utilizes knockout js. The main issue I'm facing is with setting up a table to display images and information from a form, being stored in an observable array. Each image is wrapped in an anchor tag, and the ...

Cursor vanishes until mouse movement detected (Chrome browser)

In the HTML page I created, the mouse cursor is initially set to none. However, there are certain circumstances where I need it to switch to crosshair. The issue I am facing is that the cursor does not appear unless the user moves the mouse. If the mouse r ...

Showing a tooltip on the right side of a control with an arrow pointing towards it in a colored

Can someone help me with displaying a tooltip to the right end of a control, with the arrow facing the same direction and changing the background color of the arrow to red? Here is my attempt so far <input id="age" title="test tooltip"> $( documen ...

How can you use JavaScript/jQuery to scroll to the top of a DIV?

When a link is clicked, I have a <div> popup that appears. This popup contains scrollable content when there is overflow. If the same link is clicked again, I want the <div> to be positioned at the top of the scrollable area. While this functi ...

Tips for customizing icons when hovering in CSS

I'm trying to make a default icon light up on hover using CSS, but I'm having trouble getting it to work. Any suggestions on how I can achieve this effect? Thank you! HTML <ul class='nav nav-main nav-sidebar'> <li role=&apos ...

Ways to align text in a table row in a way that it remains positioned at the center of the screen's visible area

Can anyone assist me with this task? I need help centering text within a table row ('Some text here...') so that it always appears in the middle of the screen. The table will have horizontal scrolling. .compare-content { max-width: 480px; ...

Bootstrap: Problem arises when columns do not total up to 12 and are pushed onto separate rows

So, I've been working with Bootstrap to structure columns and rows. It seems like I have the container, rows, and columns set up correctly for each post. However, I am puzzled as to why a new row is created for every post I make, causing them to stack ...

Vue.js: Incorporating Multiple CSS Templates in a Single Application

As a beginner in Vuejs, I am trying to figure out how to incorporate multiple templates into one application. For example, I want to use the Flatkit template for my SignIn page and a different template (Dashboard) for the Admin dashboard. How can I integra ...