What is the best way to create a layout containing a <div> split into three columns, with the middle column having rows?

I'm currently working on a <div> layout that I need to split into rows. The challenge is creating a design that is fluid and can adapt to various screen sizes, including mobile devices. While using an HTML table might be a quick fix, it's not the ideal solution for responsiveness.

In the "What I want" section of the image, my goal is for columns ONE and SEVEN to automatically adjust their height to match the combined height of rows THREE through SIX. Columns ONE and SEVEN will remain empty, while rows THREE, FIVE, and SIX will contain text of different lengths, and row FOUR will feature an image with dimensions set to width: 1020px and height: 1024px.

The total width occupied by rows Three through Six should be 80% of the screen width, whereas columns ONE and SEVEN should each occupy 10% of the screen width.

I am currently utilizing bootstrap 3.3.6. Here is the code snippet along with the corresponding CSS code for the "what I'm getting" part of the image:

https://i.stack.imgur.com/iSbfC.jpg

.wrapper {
    width: 100%;
    height: 100%;
}
.one {
    display: inline-block;
    width: 10%;
    height: 100%;
    background: blue;
}
.two {
    display: inline-block;
    width: 80%;
    height: auto;
}
.three {
    width: 80%;
    height: auto;
    background: orange;
}
.four {
    width: 80%;
    height: auto;
    background: purple;
}
.five {
    width: 80%;
    height: auto;
    background: yellow;
}
.six {
    width: 80%;
    height: auto;
    background: green;
}
.seven {
    display: inline;
    width: 10%;
    height: 100%;
    background: red;
}
<div class="wrapper container-fluid">
    <div class="one">ONE</div>
    <div class="two">
        <div class="three">THREE</div>
        <div class="four">FOUR</div>
        <div class="five">FIVE</div>
        <div class="six">SIX</div>
    </div>
    <div class="seven">SEVEN</div>
</div>

Answer №1

For those utilizing bootstrap and with the container-fluid class, it is simple to create a responsive layout using Bootstrap's predefined classes such as .row and col-*-*, along with setting display:flex in the .row.

.row {
  display: flex
}
.one {
  background: blue;
}
.three {
  background: orange;
}
.four {
  background: purple;
}
.five {
  background: yellow;
}
.six {
  background: green;
}
.seven {
  background: red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="wrapper container-fluid">
  <div class="row">
    <div class="col-xs-2 one">ONE</div>
    <div class="col-xs-8 two">
      <div class="three">THREE</div>
      <div class="four">FOUR</div>
      <div class="five">FIVE</div>
      <div class="six">SIX</div>
    </div>
    <div class="col-xs-2 seven">SEVEN</div>
  </div>
</div>

Answer №2

For this layout, you have the option to utilize either flex or table for the display property: (breakpoints added around 600-720px for flex & 660px for table version)

To observe the behavior, run the snippet in full-page mode.

.wrapper {
   width: 100%;
   height: 100%;
 }
 .one {
   background: blue;
 }
 .two {
   width: 80%;
 }
 .three {
   background: orange;
 }
 .four {
   background: purple;
 }
 .five {
   background: yellow;
 }
 .six {
   background: green;
 }
 .seven {
   background: red;
 }

.flex  {
   display: flex;
   flex-wrap: wrap;
 }
.flex > div {flex: 1 1 10%}
.flex .two {
  min-width: 600px;
  max-width: 100%;
  flex: 1 1 80%
}

.table {
   display: table;
   table-layout: fixed;
 }
.table > div{
   display: table-cell;
 }
@media (max-width: 660px) {
  .table > div {
    display: block;
    width: 100%;
  }
}
<div class="wrapper container-fluid flex">
    <div class="one">ONE</div>

    <div class="two">
      <div class="three">THREE</div>
      <div class="four">FOUR</div>
      <div class="five">FIVE</div>
      <div class="six">SIX</div>
    </div>

    <div class="seven">SEVEN</div>
  </div>
 
<hr/>


  <div class="wrapper container-fluid table">
    <div class="one">ONE</div>

    <div class="two">
      <div class="three">THREE</div>
      <div class="four">FOUR</div>
      <div class="five">FIVE</div>
      <div class="six">SIX</div>
    </div>

    <div class="seven">SEVEN</div>
  </div>

Answer №3

Using media queries has been a key part of my design strategy for quite some time.

.container {
    margin: 10%;

    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    display: -webkit-flex;
    -webkit-flex-wrap: wrap;
    -webkit-justify-content: center;
}
@media (max-width: 900px) {
    .container {
        width: calc(100% - 12px);
    }
}
.column {
    width: calc(45% - 6px);
    height: auto;
    float: left;
}
@media (max-width: 600px) {
    .column {
        width: calc(100% - 6px);
    }
}

Here is the example in HTML:

<div class="container">
    <div class="column"></div>
    <div class="column"></div>
</div>

You can achieve a similar layout with divs (3 columns) by adjusting the calc equation in .column to ((100% / 3) - 6px). For every additional column, modify the division accordingly. Keep in mind that columns will get smaller as you add more.


Credit goes to @Adam Buchanan Smith

Fluidity with Cards of Different Lengths

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

Using jQuery to encode an ampersand in a URL

I am facing an issue where some URLs with & in them need to be converted to HTML entities using jQuery. The original code looks like this: <div id="box"> <a href="http://domain.com/index.html&location=1">First URL</a> &l ...

One of the quirks of Angularjs is that the ng-enter animation will only be

The initial animation only occurs the first time. I am utilizing Angularjs version 1.2.22 Here is the CSS that I am using : .ng-enter { animation: bounceInUp 2s; } .ng-leave { animation: bounceOutUp 2s; } And this is the route configuration : ...

I am unsuccessful in transferring the "side-panel content" to the side panel located on the main menu page

I am facing an issue where I want to pass My left and right Panel to the main menu page (dashboard), but it is not working as expected. The problem arises because the first page that needs to be declared is the login page (/ root) in my case. If I pass it ...

Utilize the display property with grid to effortlessly expand a block to occupy the entire width

I am currently exploring the grid system and I have a specific challenge. I would like the third block to expand to its full width without the need for extra classes. Can this be achieved using only internal CSS? .grid { margin: 36px auto; height: ...

Having trouble with the tool tip not showing up correctly in Internet Explorer?

Check out the code snippet below: <table> <tr> <td class="bgimg" valign="middle" width="10%" title="some title" nowrap> <img src="images/SomeLogo.gif"/> </td> </tr> </table ...

Tips for aligning a Bootstrap container in the middle of the viewport vertically

I'm struggling to center a Bootstrap container vertically in the viewport. You can view my code at http://www.bootply.com/C8vhHTifcE All of my attempts at centering have been unsuccessful. Does anyone have a solution? Just to clarify: I want the co ...

Creating a function to update data in a Node.js/MongoDB environment

Hey there! I'm new to working with nodejs and mongodb, and I'm trying to create a function that updates the win, lose, and draw record in my UserSchema. Here's my Schema: UserSchema = new mongoose.Schema({ username:'string', ...

Element sticking on scroll down and sticking on scroll up movements

I am currently working on a sticky sidebar that catches and stays fixed at a certain scroll point using JavaScript. However, I am facing an issue where I need the sidebar to catch when scrolling back up and not go further than its initial starting point. ...

trouble with overlapping mdl-sheet instances

Hey there! I have a quick question - Is it possible to have multiple mdl-sheets on one page that all share the same form? I tried implementing this but ended up with them overlapping each other instead of displaying next to each other from left to right. ...

What is the best way to retrieve a value from a form and incorporate it into a controller?

Here is the code I've been working on: http://pastebin.com/AyFjjLbW I started learning AngularJS and was making progress, but now I'm facing a challenge. I'm trying to use a drop-down menu to select both a priority level and a type of job t ...

The "initialized" event in angular2-tree-component fires prior to the data being loaded

Utilizing the angular2-tree-component, my goal is to display an already expanded tree. According to Angular docs, the initialized event should be used for expanding the tree after the data has been received: This event triggers after the tree model has ...

In order to display the particle-slider logo effect, the JavaScript on the page needs to be refreshed

I have a website frontend integrated from WordPress using an HTML 5 Blank Child Theme. The site features a logo effect utilizing particle slider for screen sizes greater than 960px, and a flat logo image for screen sizes less than 960px. Everything works p ...

Using the Loop Function in Node.js with EJS Templates

Seeking help with a node.js application that utilizes bootstrap. I am trying to display the bootstrap cards in rows of 3, with each row containing data from my dataset in columns. However, my current implementation using two for loops is leading to repeate ...

Attempting to grasp the fundamentals of angular Routing, however, upon attempting to reload the page, nothing appears to be displayed

While working in the Bracket editor, I created a file structure with various files located under the 'scripts' tags within the Index.html file. The root folder is named 'projectAngular', inside which there are subfolders like 'appC ...

Selenium encountered an error: Element not found - Could not locate element: {"method":"CSS selector","selector":"*[data-test="email-input"]}

Recently, my application has been encountering an error when trying to log in through a web form. The issue seems to be with locating the email input field: "no such element: Unable to locate element: {"method": "css selector", "s ...

Clicking on links will open them in a separate tab, ensuring that only the new tab

Is there a way to open a new tab or popup window, and have it update the existing tab or window whenever the original source link is clicked again? The current behavior of continuously opening new tabs isn't what I was hoping for. ...

Utilizing .NET MVC for incorporating HTML attributes with @HTMLTextAreaFor

I'm encountering an issue when trying to add HTML attributes to a text area using the @HTML command. Specifically, I am attempting to include a class name, but it doesn't seem to be working as expected. Below is the code snippet that I am workin ...

Pressing the different buttons on a form does not result in the form being submitted

I have a form with multiple buttons that, when submitted, will redirect to a different page and pass along some variables. echo " <form method=\"POST\" action=\"sightWordsTest.php\"> ...

HTML validation produces mistakes

I encountered an issue when using Google Fonts and received the following error related to a specific link: <link href="http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic|Montserrat:700|Mer ...

Is it possible that the div's height is not being set to 0 pixels

<div style="height:0px;max-height:0px"> </div> It appears that setting the height of a div to 0 pixels is not having the desired effect. The div is still expanding to display its contents, so how can we stop this from occurring? ...