Is it feasible to create rows within columns using Bootstrap framework?

Is it possible to achieve this layout using rows within columns with Bootstrap:

https://i.sstatic.net/DC0f4.png

I attempted the following without success:

<div className="col-lg-3 col-12">
    <div className="row">
        <displaySquare  />
    </div>
    <div className="row">
        <displaySquare  />
    </div>
    <div className="row">
        <displaySquare  />
    </div>
</div>

<div className="col-lg-9 col-12">
    <div className="row">
        <displayBigSquare   />
    </div>
    <div className="row">
        <displaySquare  />
        <displaySquare  />
    </div>
</div>

Thank you

UPDATE (23/08/2021): It works better with CSS grid. I decided to drop Bootstrap and use GRID instead which allows for defining grid-related properties (GRID explanations on https://developer.mozilla.org/fr/docs/Web/CSS/grid).

HTML code:

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Griiiiid!</title>
    <link rel="stylesheet" href="index.css" />
  </head>
  <body>
    <h1 class="centre">Welcome</h1>
    <div class="container">
      <div class="items item1">1</div>
      <div class="items item2">2</div>
      <div class="items item3">3</div>
      <div class="items item4">4</div>
      <div class="items item5">5</div>
      <div class="items item6">6</div>
    </div>
  </body>
</html>

CSS code:

*,
::before,
::after {
  box-sizing: border-box;
}
body {
  background-color: #333;
  margin: 0;
  padding: 0;
  font-family: Georgia, "Times New Roman", Times, serif;
}
h1 {
  color: salmon;
}

.centre {
  text-align: center;
}

.container {
  padding: 30px ;
  width: 100%;
  background-color: #eee;
  margin: 30px auto;

  display: grid;
  grid-template-rows: 150px;
  grid-template-columns: repeat(3, 150px);

  grid-auto-rows: 150px;

  gap: 30px;
}

.items {
  padding: 20px;
  font-size: 30px;
  font-family: sans-serif;
}

.item1 {
  background-color: lightcoral;
}
.item2 {
  grid-row: 1/3;
  grid-column: 2/4;
  background-color: lightgreen;
}
.item3 {
  background-color: lime;
}
.item4 {
  background-color: chocolate;
}
.item5 {
  background-color: darkgoldenrod;
}
.item6 {
  background-color: darkseagreen;
}

Result: https://i.sstatic.net/bnuvz.png

Answer №1

According to the latest version of Bootstrap, v5.0.2, the answer is currently no. To create a multi-row orange rectangle like in your example, you would need to utilize CSS Grid styling, which is not yet integrated into Bootstrap.

However, in the upcoming release v5.1.0, there will be an optional feature to switch from the current flexbox-based grid system to a CSS Grid-based one. While it may have some initial challenges and may not fully support your specific needs at the moment, the option to explore CSS Grid will soon be available. Documentation on how to enable and use this feature will be provided once the new version is released. In the meantime, you can review the feature's PR for more information.

Answer №2

If you desire to achieve that specific layout, it will require two rows:

The square's margin bottom should be double the gutter size

.square {
  width: 100%;
  padding-top: 100%;
  background: orange;
  margin-bottom: 30px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<div class="container">
  <div class="row">
    <div class="col-4">
      <div class="square"></div>
      <div class="square"></div>
    </div>
    <div class="col-8">
      <div class="square"></div>
    </div>
  </div>
  <div class="row">
    <div class="col-4">
      <div class="square"></div>
    </div>
    <div class="col-4">
      <div class="square"></div>
    </div>
    <div class="col-4">
      <div class="square"></div>
    </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

What is the best way to choose a date and time in a custom format within my React application?

I'm currently developing the front-end of my application using React. I am looking for a way to capture the date and time in the specific format shown in this image. Any suggestions or solutions would be greatly appreciated! ...

Adaptable Bootstrap4 Navbar smoothly adjusts text during resizing

Just starting out with bootstrap 4 and I'm trying to create a responsive navbar using the code below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=devic ...

Modify the background color of a tooltip using a different class

I have a question regarding the version of Bootstrap being used in my package.json file: { "_from": "bootstrap@^4.5.0", "_id": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="34565b5b40474 ...

CSS drop down menu malfunctioning

Trying my hand at anchor tags and drop down menu. I'm encountering an issue in the code below - the dropdown doesn't seem to be working as intended. It should display the text "This is dropdown menu" directly beneath the text "This is text. Its i ...

JavaScript encoding the text

Looking for a straightforward JavaScript function to encrypt text data from a textarea using a key (the key being the user's password stored as a hashed session variable, outputted by PHP into a field). The objective is to have the content of the tex ...

Animation in CSS Appears Jumpy in Chrome

For some reason, the text inside a moving div (which is transitioning using CSS) seems to jitter and shake in Chrome. However, this issue does not occur in Firefox, where the movement is very smooth and achieves the desired effect. #hidexpert { display: b ...

What is the best way to configure an EmailId validator in Angular 6 to be case insensitive?

My register and login page include a form validator pattern matching for the registration form. this.registerForm = this.formBuilder.group({ firstName: ['', Validators.required], emailId: ['', [Validators.required, Validators.patt ...

Error encountered: Trying to access the property 'top' of an undefined object while selecting a menu item to navigate to a different page

Whenever I try to use my menu on a mobile device, I encounter some issues. The menu functions perfectly on a desktop, but as soon as I switch to a mobile phone, I find myself unable to navigate to different pages. The only functionality that seems to work ...

Using Javascript to display different div elements based on the type of mobile device

My goal is to use JavaScript to accomplish the following: 1- Check the mobile device type, if it is an ANDROID device, show the ANDROID_USERS div. If it is an IPHONE device, show the IOS_USERS div. 2- Display the above div only once during the first visit ...

Do you think my approach is foolproof against XSS attacks?

My website has a chat feature and I am wondering if it is protected against XSS attacks. Here is how my method works: To display incoming messages from an AJAX request, I utilize the following jQuery code: $("#message").prepend(req.msg); Although I am a ...

Is there a way to effortlessly generate a mini-website from Markdown files?

Can a tool be found that creates a mini-website from locally-stored Markdown files complete with automatically generated navigation? I'm hoping for a service that can sync with my Dropbox, analyze the file structure, read the Markdown files, and effo ...

Creating a grid of dot plots using R

I have collected data on the weight and sex of newborn siblings, and I would like to create a 2x2 dot plot in R similar to the one shown in Stata here: 2x2 plot of birthweight of first compared to second child This is the Stata code used: egen sex1sex2=g ...

Tips for positioning tables on a page

I have 4 tables and a submit button. How can I make them more compact? Maybe like this: </img> This is my HTML code: <body> <form action="/cgi-bin/form.py" id="myform"> <table class="table-fill"> ... ...

Determination of the input parameters

Currently, I am developing an Angular application that includes a matInput field for user input. The issue I am encountering is that when the user enters a positive or negative value in the field (e.g. +5 or -5), the final output does not reflect the inten ...

Strange height problem detected in embedded YouTube video

Currently, I have a page with an embedded YouTube video that is intended to be placed in a container with a variable width. When the video is outside of the container, the aspect ratio appears normal. However, once it is placed inside the container, the he ...

What is the best way to translate these CSS properties into Mui?

I am currently in the process of transitioning my CSS code to utilize MUI's sx prop and styled() function. However, I have not been able to find any documentation on how to properly convert the following code to MUI syntax. Can someone assist me with ...

Loading an HTML page using jQuery's .load() method that contains embedded JavaScript

I'm facing an issue with loading .html pages (including JavaScript) into a div element. Below is my div setup: <div class="content"></div> This is my php code: <?php if(!$_POST['page']) die("0"); $page = (int)$_POST[&a ...

Ways to specify the encoding for a text iframe embedded in a webpage

Can anyone help me with document embedding in HTML? In my current project, I am directly embedding my update logs as text files into the webpage, along with a selection menu to view all the updates. However, I ran into a minor issue where the Firefox cons ...

Tips for utilizing ngx-bootstrap typeahead in conjunction with an asynchronous HttpClient request

Currently, I'm facing a challenge in populating nxg-bootstrap typeahead with asynchronous results from a REST backend in Angular 4. The example provided on their website () demonstrates how to achieve this using mock observable data, but implementing ...

Exclude strong tag inside div using Jsoup Select

Here is a sample of HTML code: <div class="address"> <strong>John Doe </strong> <br>Main Street 5 <br>12345 Anytown </div> This is the code snippet I am using: html = html.r ...