A guide to implementing div wrapping in HTML

I'm in the process of using flexbox on my website. I have 10 div elements that I want to wrap around each other closely without any gaps between them.

My goal is to have "4" positioned to the right of "1", instead of creating a new row and moving down. How can I achieve this effect? Are there any jQuery plugins that can simplify this process? However, I prefer understanding the basic concept behind it rather than relying on plugins.

Check out my code on JSFiddle

.container{
    display:flex;
    flex-wrap:wrap;
    flex-direction:row;
    height:900px;
    background:gray;
    max-height:900px; 
}

.box{
    color:white;
    font-size:30px;
    text-align:center;
    background:black;
    width:200px;
    height:200px;
    margin:2px;
}
.type1{
    height:300px;
}
.type2{
    width:500px;
}
.type3{
    height:40px;
    width:50px;
  }
.type4{
    height:600px;
}
<div class="container">
  <div class="box type1">1</div>
  <div class="box type2">2</div>
  <div class="box">3</div>
  <div class="box type3">4</div>
  <div class="box">5</div>
  <div class="box type4">6</div>
  <div class="box">7</div>
  <div class="box">8</div>
  <div class="box">9</div>
  <div class="box">10</div>
</div>

Answer №1

To arrange sections side by side, use separate div containers for each section and ensure that the container div with class "container" has the desired width.

Follow this principle: https://jsfiddle.net/414yhvxd/1/

<div class="container">
  <div>
    <div class="box">1</div>
    <div class="box">2</div>
    <div class="box">3</div>
  </div>
  <div>
    <div class="box type3">4</div>
    <div class="box">5</div>
    <div class="box type4">6</div>
    <div class="box">7</div>
    <div class="box">8</div>
    <div class="box">9</div>
    <div class="box">10</div>
  </div>
</div>  

.container{
   display:flex;
  flex-wrap:wrap;
  flex-direction:row;
  height:900px;
  background:gray;
  max-height:900px;
}

.box{
  color:white;
  font-size:30px;
  text-align:center;
  background:black;
  width:200px;
  height:200px;
  margin:2px;
}
.type1{
  height:300px;
}
.type2{
  width:500px;
}
.type3{
  height:100px;
  width:50px;
  }
.type4{
  height:600px;
}

If you need to adjust the layout further, use this as a starting point to customize it according to your requirements.

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

ASP.NET MVC - AjaxContext is a powerful feature provided by the

I recently attempted to delve into the AjaxContext utilized by ASP.NET-MVC in scenarios such as Ajax Actionlinks and their clientside functions like onSuccess and onComplete. However, I must admit that I found it quite confusing... Is there any documentati ...

Expandable Checkout Form for Woocommerce

I need help troubleshooting a WooCommerce collapsible checkout form using Bootstrap Collapse. Below is the HTML markup I am currently using: <div class="panel-group" id="checkout-accordion"> <div class="panel panel-default" id="panel-billing"&g ...

What is the best way to alter the text of a button when the mouse hovers over it?

I'm looking to create a button that can dynamically change the text inside it when the cursor hovers over it, and then revert back to the original text when the cursor moves away from it. I attempted this in VScode using "document.getElementById().inn ...

Update the Kendo window scrolling feature to include fixed update and cancel buttons

I've encountered an issue while using ASP MVC and the latest version of Kendo. When I add too much content to a Kendo window, it starts scrolling vertically, which ends up hiding the cancel/update buttons at the bottom. This is not ideal as the user s ...

Multi-line D3 chart that dynamically updates and intersects with the axis

I am attempting to create a multiline d3 chart that can be updated with new datasets. I have developed a method to plot the new data on the existing d3 frame, but I am encountering issues when trying to update the chart with mocked data. The new data is no ...

What is the best way to attach to the beforeSubmit event of a dynamically loaded AJAX form in Yii?

Recently, I encountered an issue with dynamically loading a form via AJAX and attempting to bind the beforeSubmit event. Strangely, the event didn't seem to work as expected, causing the form to submit and the browser to navigate to a new page. This b ...

Transmitting data using ajax to php without the need to refresh the entire page, while still triggering the execution of php code within

I created an index.php page featuring buttons that generate tables. The PHP code/script below is generated upon clicking these buttons. All the code you see here is located in the admin.php file but visible on the index.php page. Using PHP, I generated ...

Is it possible to include choices in the number option for slash commands in discord.js v13?

I am currently working on creating a custom slash command that includes a numerical option. Utilizing the .addNumberOption() method for this purpose. Is there a method to restrict users from inputting numbers outside the range of 0-5 after entering the Di ...

Neglect the styling of the element wrapper

Imagine I have two divs set up like so: <div name="parent" style="color:blue;padding:5px"> <div name="child" style="background:red"> Text that disregards the color:blue and padding:5px properties, yet still follows the background:red set ...

Display secret content upon hovering with a stylish animation

My current structure is as follows: HTML: <ul> <li> <span>asd</span> adsafsadlvjnsd </li> </ul> CSS: span { width: 0; } li:hover span { width: 60px; } In this setup, the content inside the span tag is h ...

CSS transforms fluidly transition between absolute and relative positioning

Can CSS transitions be used to combine "position: relative" and "position: absolute" in a smooth manner? I have developed a compact widget called the Deck, which has both a collapsed and expanded state. Currently, it is working well by using absolute posi ...

What is the best way to create a React text box that exclusively accepts numeric values or remains empty, and automatically displays the number keypad on mobile devices?

While there are numerous similar questions on StackOverflow, none of them fully address all of my requirements in a single solution. Any assistance would be greatly appreciated. The Issue at Hand Within my React application, I am in need of a text box tha ...

Enhance container and typography for layouts converted to 1920px width to improve overall design

Greetings to all! I need some assistance with converting a design file that is 1920px wide into an HTML layout. Can someone provide tips on optimizing containers and typography for responsiveness? Specifically, I would like the font-size and line-height ...

What steps should be taken when encountering the "Cannot Get" error message on a webpage?

Currently, I am in the process of creating an HTML file within xcode with the intention of displaying its contents in the browser. With an empty file as my starting point, the following code was added: <html> <head> <title>HTML is S ...

Embedding HTML within a PHP conditional statement

I recently encountered an issue while trying to display a source image using PHP. The initial code worked perfectly: <html> <h3>First Test</h3> <img src="example1.php" /> </html> However, I wanted to implement user validatio ...

Adjusting the grid for various mobile screen sizes

I am currently working on designing a user interface (UI) for mobile screens that includes a header, grid, and buttons. I want the UI to look consistent across all mobile devices. Here are screenshots from various mobile screens: Samsung S5 Pixel 2 XL I ...

How can jQuery-based Ajax/PHP be leveraged for synchronization effects?

I am currently in the process of creating a groceries application that allows for synchronization with other family members who are part of a 'family' group. When one member updates the grocery list on their device, the changes should automatical ...

Issue with PrimeNG DataTable contextMenu alignment inside TabView

I encountered an issue with displaying a DataTable - contextMenu when it is placed within a TabView. The contextMenu was appearing off-center. However, the DataTable - contextMenu worked perfectly fine when it was not wrapped in a TabView. To address this ...

Setting the x-api-key header with HttpInterceptor in Angular 4: A guide

I am attempting to use HttpInterceptor to set the header key and value, but I am encountering the following error: Failed to load https://example.com/api/agency: Response to preflight request doesn't pass access control check: No 'Access ...

Fields that change dynamically on websites

I am currently working on enhancing a User profile page by adding 2 additional field types, but I am encountering difficulties in implementing them. Essentially, both field types are dynamic in nature. One involves a selection from a list, with the option ...