Tips for designing a flexible structure with 2 columns, each containing an additional 2 columns within

Is it possible to create a 4-column responsive layout?


| column left | column right | column left| column right|

I would like to achieve a single row layout on larger devices as shown below

| column left | column right | column left| column right|

and on medium & small devices, it should look like this:

| column left | column right |

| column left | column right |

Answer №1

If you want to utilize the bootstrap grid system, here's how you can do it:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-lg-3 col-md-6 col-sm-6">col 1</div>
<div class="col-lg-3 col-md-6 col-sm-6">col 2</div>
<div class="col-lg-3 col-md-6 col-sm-6">col 3</div>
<div class="col-lg-3 col-md-6 col-sm-6">col 4</div>
</div>

Give it a try by clicking on "Run code snippet." You'll be able to see the demo for small screens. Then, click on "Full page" to view it on larger screens.

Bootstrap's grid system is designed for four screen sizes:

  1. lg for laptops and desktops - screens equal to or greater than 1200px wide
  2. md for small laptops - screens equal to or greater than 992px wide
  3. sm for tablets - screens equal to or greater than 768px wide
  4. xs for phones - screens less than 768px wide

The screen is divided into 12 parts, so the number after each screen size specifies how many parts the div should cover.

For example, in the code provided above, the divs will cover 3 parts on large screens and 6 parts on small screens.

For more details on the bootstrap grid system, check out this resource.

Answer №2

If you want to improve your webpage layout, consider using the bootstrap grid system. This system utilizes containers, rows, and columns to organize and align content in a flexible and responsive manner. Take a closer look at the example below to understand how the grid functions:

<div class="container">
  <div class="row">
    <div class="col-lg-3 col-md-6 col-sm-6"">
      This is one of three columns
    </div>
    <div class="col-lg-3 col-md-6 col-sm-6"">
      This is one of three columns
    </div>
    <div class="col-lg-3 col-md-6 col-sm-6"">
      This is one of three columns
    </div>
    <div class="col-lg-3 col-md-6 col-sm-6"">
      This is one of four columns
    </div>
  </div>
</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

Encountering a Javascript Error when trying to begin

As a beginner in Javascript, I am venturing into designing a simple website that incorporates Javascript. Currently, my focus is on building a calculator. However, upon loading my website, nothing seems to initiate and there are no error messages displayed ...

Disabling directional focus navigation in CSS: A comprehensive guide

Is there a way to disable directional focus navigation properties, such as 'nav-up', 'nav-right', 'nav-down', 'nav-left', for elements on an HTML page? button { position:absolute } button#b1 { top:0; left:50%; ...

Arranging input elements horizontally

this issue is connected to this post: Flex align baseline content to input with label I am grappling with the layout of my components, specifically trying to get all inputs and buttons aligned in a row with labels above the inputs and hints below. The CSS ...

Automate the login process for a website and programmatically fill out and submit a form

I am currently trying to automate the login process on Skype's website using Selenium in C#. Everything goes smoothly until I reach the password field, which seems to be elusive to Selenium. I have tried various methods to locate the password field bu ...

Nesting maps in JavaScript is a powerful way to transform

I'm in the process of developing a budgeting app using React and JavaScript. At the moment, I have successfully generated a table displaying various costs. Name Budget Used $ Used % Available Food 300 300 100 0 Streaming services 600 600 100 ...

specifying the input value pattern restriction in HTML5

Struggling to set a minimum and maximum value for an input text box. Despite my efforts, I haven't been able to make it work. How can I resolve this issue? The current pattern restricts values up to 10 but I need to allow values from 100 to 100000. Wh ...

The landscape orientation media query does not adhere to the specified maximum width

I am currently working on creating a mobile landscape design for a website specifically tailored for iPhone SE and iPhone 12. In the process, I encountered an issue that caught my attention: Within two different breakpoints, I made adjustments to the top ...

Implementing swipe functionality to Bootstrap carousel

This is the code snippet I am working with: <div class="container"> <div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="3000"> <!--Indicators--> <ol class="carousel-indicators"> ...

issues with alignment between bootstrap div and canvas

I am currently working on a project with a canvas inside a div using three.js. My goal is to display a purple bar for user settings on the right side of the three.js window. However, I am encountering an issue where Bootstrap is not recognizing that I want ...

"Showcase a Pair of Images with Just a Single Click. Leveraging PHP and

With two div boxes, one for Input and the other for Output as displayed below: My goal is to upload an image using PHP and store it in both the Input and Output folders. Upon clicking the Submit button, I want the image from the Input folder to be shown ...

What is the best way to eliminate excess space on the right side in Bootstrap 4 while in mobile view?

I'm struggling to understand why this layout is not responsive on mobile devices, triggering a bottom scroll bar at around 616px. I'm looking for a solution to hide the scroll bar at least until 414px for iPhones and other smartphones. I've ...

Is the second parameter of the function being used as a condition?

Why is it necessary to validate the helpText argument within the function to be non-equative to null when its ID is linked with the span tag? The functions task is to set and clear help messages in the form field using built-in CSS classes. <input id ...

How come the mouseover effect on the div remains even after the mouse has been removed?

How can I keep the original CSS class when the mouse moves away? function highlight( x, y) { var sel=document.getElementById(y); sel.style.borderBottom= "2px solid "+x; sel.style.opacity="1"; sel.style.transition="all eas ...

Choosing a single radio button value within a nested ng-repeat loop in AngularJS

Help needed with selecting only one radio button value in nested ng-repeat. Please review the source code and suggest any potential mistakes. <form ng-submit="save()"> <div ng-repeat="x in surveyLst"> <div class="row"> < ...

What is the best way to navigate a carousel containing images or divs using arrow keys while maintaining focus?

Recently, I have been exploring the Ant Carousel component which can be found at https://ant.design/components/carousel/. The Carousel is enclosed within a Modal and contains multiple child div elements. Initially, the arrow keys for navigation do not work ...

Are tabs best displayed as an overlay?

I've been searching high and low for a tutorial on how to create an overlay with tabs similar to the Google Chrome webstore. If anyone knows of a tutorial or a combination of tutorials that can help me achieve this, please let me know! Link Any guida ...

obtain the text content from HTML response in Node.js

In my current situation, I am facing a challenge in extracting the values from the given HTML text and storing them in separate variables. I have experimented with Cheerio library, but unfortunately, it did not yield the desired results. The provided HTML ...

Is it possible to achieve a smooth transition to the right using CSS

I'm attempting to create a sliding box effect from left to right using only transitions, similar to this: #box { width: 150px; height: 150px; background: red; position:absolute; transition: all 2s ease-out; right:auto; } .active{ bac ...

Reveal or conceal elements with a touch of animation

I am in the process of building my own website and I've been working on implementing a button that can toggle the visibility of a specific div element. While the functionality is there, I really want to incorporate an animation to enhance it. I attem ...

Basic HTML and JavaScript shell game concept

After spending several days working on this project, I am struggling to understand why the winning or losing message is not being displayed. The project involves a simple shell game created using HTML, JavaScript, and CSS. I have tried reworking the JavaSc ...