Bootstrap 5 utilizes an 8-column system specifically designed for tablets, while defaulting to a 12-column system for both desktop and mobile versions

Currently, I am utilizing the Bootstrap grid system with its 12-column setup, which is working well. However, my designer has requested that I make the Tablet view an 8-column system, with each column taking up 100% of the width and no gutters in between.

Is this achievable? And if so, what specifications should I provide?

Attached is a screenshot illustrating the required grid system. The mobile 4-column setup is not a concern, as the default column system works fine. The challenge lies in adapting to the tablet view, especially with elements that require 3 or 5 columns - a translation to the 12-column system seems tricky in such cases.

https://i.sstatic.net/53dpF.png

Answer №1

Regrettably, achieving this layout is not feasible with the default Bootstrap Grid system. Given that Bootstrap's grid is based on a 12-column structure, creating blocks with a width of 1.5 columns each poses a challenge.

My suggestion would be to utilize CSS-Grid instead for this scenario:

:root {
  --col: 4;
}

@media only screen
  and (min-width: 786px) {
    :root {
      --col: 8;
    }
}

@media only screen
  and (min-width: 1440px) {  
    :root {
      --col: 12;
    }
}

.container {
  display: grid;
  grid-template-columns: repeat(var(--col), 1fr);
  gap: 0.5em;
}


/* for demonstration purpose only */
.container > div {
  border: 2px dashed red;
  min-height: 1vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
<div class="container">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
  <div>7</div>
  <div>8</div>
  <div>9</div>
  <div>10</div>
  <div>11</div>
  <div>12</div>
</div>

If you require support for older versions of IE and must utilize Flexbox, the following formula should be utilized:

(100% - ((columns - 1) * gap-size)) / columns

:root {
  --col: 4;
  --gap: 0.5em;
}

@media only screen
  and (min-width: 786px) {
    :root {
      --col: 8;
    }
}

@media only screen
  and (min-width: 1440px) {  
    :root {
      --col: 12;
    }
}

.container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
}

.container > div {
  width: calc((100% - ((var(--col) - 1) * var(--gap))) / var(--col));
}


/* for demonstration purpose only */
.container > div {
  box-sizing: border-box;
  border: 2px dashed red;
  min-height: 1vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
<div class="container">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
  <div>7</div>
  <div>8</div>
  <div>9</div>
  <div>10</div>
  <div>11</div>
  <div>12</div>
</div>

Answer №2

I stumbled upon a clever solution that may seem like an override, but it fits my requirements flawlessly. Below is the uncomplicated code snippet, which you can adjust the class names and media query widths to suit your specifications.

@media (min-width: 750px) and (max-width: 990px) {
    .col-8-c-1 { width: 12.5%; }
    .col-8-c-2 { width: 25%; }
    .col-8-c-3 { width: 37.5%; }
    .col-8-c-4 { width: 50%; }
    .col-8-c-5 { width: 62.5%; }
    .col-8-c-6 { width: 75%; }
    .col-8-c-7 { width: 87.5%; }
    .col-8-c-8 { width: 100%; }

    .col-8-p-0{
        padding: 0;
    }
}

Consider using HTML code similar to the following:

<div class="col-12 col-8-c-6">occupies the entire width and 6 out of 8 columns on tablets<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

The issue with two different link styles displaying correctly in Internet Explorer but not in other browsers is that when a link is clicked, all links appear

Looking for a testing ground? Check out my website: While everything works smoothly on IE, I've noticed a glitch in other browsers. Clicking on one link causes all links on the page to appear as visited links. Take a look at the CSS code below: @ch ...

Incorporate JavaScript to enable the transfer of text from one textarea to another upon clicking a button, while simultaneously clearing the original textarea

After working on the provided code, I have managed to create a functionality where text from one textarea is copied to another textarea when a button is clicked using JavaScript. <head> <script type="text/javascript"> function displayOut(){ ...

WP How can I modify a particular thumbnail size with a custom CSS class?

I have been attempting to use add_image_size for my custom thumbnail resize, but it seems to be having trouble maintaining the thumbnail size at 220 x 220. Instead, it keeps changing the height to 167 pixels. As a workaround, I am exploring a CSS-based sol ...

Create an interactive table in your WordPress website that adjusts to different screen sizes

Having scoured numerous posts on responsive tables in this stack, I am still unable to find a solution to my specific issue. It's quite possible that I didn't know what exactly to look for, hence my resorting to posting a question here. The crux ...

The mouse scurries away once the div height has been adjusted

How can I make the height of #header change when hovering over #hoverme, and then revert back to its original height when the mouse leaves #hoverme? If anyone knows a solution, please check out my jsfiddle as it's not working as I intended. Here is ...

Unable to alter or eliminate the grey background using material-ui

Struggling with a React application that incorporates material-ui. Despite my efforts, I can't seem to get rid of an unwanted grey background in one section of the app. Attempted solutions: body { background-color: #ffffff !important; } * { b ...

What is the proper method for changing the height of this component in HTML?

Hey there! I'm brand new to HTML and I'm embarking on a little project for myself to enhance my skills. I have a question about adjusting the height of some text - I want it to look similar to Twitter, where each "tweet" is clearly separated from ...

What is the reason for translate3d(…) causing a scrollbar to appear on iframes?

Is there a way to hide the tiny, fixed scrollbar that appears at the bottom of an <iframe> with overflow-x: scroll, even when there is no content to scroll, while keeping the transform: translate3d(0px, 0px, 0px) style set? https://i.sstatic.net/kaV ...

Create a Bootstrap multi-bar component for visually displaying the daytime information

I am looking to create a horizontal bar with multiple intervals. Here is what I have tried so far: <div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%;"& ...

Creating a child div that is half the size of its parent

Is there a way for a child div to inherit half the width and half the height of its parent div without using specific values or viewport units? ...

Having trouble with hover effects not working on links due to the container? Here's a solution for you

I would like to create a layout with 3 columns for menu, story, and description. Each story should have its own unique description. Everything was working fine until I added a div to the middle column. The same issue arose with the right column but I manag ...

Incorporate zoom feature into the jQuery polaroid gallery

Currently, I am utilizing a jQuery and CSS3 photo gallery found on this website. My goal is to allow the images to enlarge when clicked, however, the method provided by the author isn't very clear to me, as I'm not an expert in jQuery. I attempt ...

Guide to setting up a Datetime picker in Bootstrap 5 user interface

I've been struggling to implement a datetime picker for Bootstrap 5 (my front end is using Bootstrap 5.1.0). While I came across a solution for Bootstrap 3, unfortunately it doesn't seem to work with Bootstrap 5. ...

Steps for repairing a button positioned at the top of a nested container within a form

My search form includes side filters to help users narrow down their search, with the results appearing on the right. This is just a basic example, as my actual setup involves more filters. However, there is one issue – users have to scroll down the pag ...

Difficulty with the responsiveness of a website due to issues with the bootstrap grid system

I've been working with a Bootstrap grid that you can find at . While it works perfectly on large desktop screens, everything is a bit messy on mobile devices. The "NEW" text specifically is not visible on mobile and doesn't seem to be responsive. ...

Utilizing data attributes over classes for styling in CSS

Programming Languages <span data-bar> ... </span> JavaScript span[data-bar]{ ... } Do you agree with this coding practice? Are there any potential pitfalls? I believe implementing the data- attribute is beneficial when dealing with a large ...

Drop and drag the spotlight

On my website, I am looking to implement a feature that will make it easier for users to identify the drag and drop area. I found a code snippet on JSFIDDLE that works perfectly there. However, when I tried to use it on my local server, it doesn't se ...

Unable to get the desired 100px margin at the bottom

Can someone assist me in positioning the right side image at the bottom of the div tag using CSS? I have tried using the .up class in my style tag but with no success. How can I achieve this by adjusting the margin? <!DOCTYPE html> <html lang=" ...

Encountered an error searching for module 'autoprefixer' while executing the npx tailwindcss init -p command

I am currently working with Vue 3 and attempting to integrate tailwindcss by following this helpful tutorial: https://tailwindcss.com/docs/guides/vue-3-vite#install-tailwind-via-npm I have successfully installed the necessary dependencies using the comman ...

Tips for inserting a rotated image using CSS

I've created the following code snippet. However, there is a new requirement stating that the image needs to be rotated by 180 degrees. How can I make this happen? #cell { background-image: url("../images/logo.PNG"); background-attachment: fixed; b ...