Issues with Boostrap grid system on smaller screens

I'm attempting to design a flexible web layout that displays differently on various device screens. Here's the breakdown:

  1. 2 rows 6 columns (large screens, iPad Pro, and other devices)
  2. 3 rows 4 columns (iPhone 6/7/8 plus)
  3. 4 rows 3 columns (iPhone 6/7/8 and smaller devices)

This is what I've attempted so far:

<div class="row">
    <div class="col-xs-2 col-md-2">
        <img src="https://icons.iconarchive.com/icons/iconka/meow/96/cat-purr-icon.png" alt="">
    </div>
    <div class="col-xs-2 col-md-2 ">
        <img src="https://icons.iconarchive.com/icons/iconka/meow/96/cat-purr-icon.png" alt="">
    </div>
    <!-- Repeat for each column -->
</div>

On large screens, I have 2 rows and 6 columns, but on iPhone 6/7/8 plus and smaller devices, I only see one column. I'm unsure how to resolve this issue. Any assistance would be appreciated. Thank you!

Answer №1

In the world of bootstrap, the layout axis is divided into 12 equal parts

If you want to customize your div class attributes, consider updating them as follows:

 class="col-xs-4 col-sm-3 col-md-3 col-lg-2 col-xl-2"

Alternatively, you can utilize vanilla CSS to specifically target various screen sizes

@media only screen and (max-width: 600px) {
  body {
    background-color: lightblue;
  }
}

To cater to different device sizes, you can use the following max-width breakpoints:

- Mobile devices: 320px - 480px

- iPads, Tablets: 481px - 768px

- Small screens, laptops: 769px - 1024px

- Desktops, large screens: 1025px - 1200px

- Extra large screens, TV: 1201px and above

Answer №2

Discover all the predefined breakpoints offered in Bootstrap 4.5 by checking out this link: https://getbootstrap.com/docs/4.5/layout/overview/#responsive-breakpoints

To summarize:

  • For extra small devices (portrait phones, less than 576px)
    • media query: none
    • column class name: col-*
  • For small devices (landscape phones, 576px and up)
    • media query: @media (min-width: 576px)
    • column class name: col-sm-*
  • For medium devices (tablets, 768px and up)
    • media query: @media (min-width: 768px)
    • column class name: col-md-*
  • For large devices (desktops, 992px and up)
    • media query: @media (min-width: 992px)
    • column class name: col-lg-*
  • For extra large devices (large desktops, 1200px and up)
    • media query: @media (min-width: 1200px)
    • column class name: col-xl-*

The Bootstrap Grid system utilizes 12 columns per row: https://getbootstrap.com/docs/4.5/layout/grid/#grid-options


In essence, to achieve what you desire, you would need:

  • 3 columns per row (iPhone 6/7/8 and smaller device)
    • 12 / 3 = 4
    • column class name: col-4
  • 4 columns per row (iPhone 6/7/8 plus)
    • 12 / 4 = 3
    • column class name: col-sm-3
  • 6 columns per row (large screen, iPad Pro and other devices)
    • 12 / 6 = 2
    • column class name: col-md-2

<div class="container-fluid">
    <div class="row">
        <div class="col-4 col-sm-3 col-md-2">
            </img />
        </div>
        ...
    </div>
</div>

demo: https://jsfiddle.net/davidliang2008/aoc3ksve/3/


You can apply .img-fluid to images for responsive image display as well:

demo: https://jsfiddle.net/davidliang2008/aoc3ksve/5/

Answer №3

The grid system in Bootstrap3 is divided into four distinct classes:

xs (designated for phones with screens less than 768px wide)

sm (designed for tablets, screens equal to or greater than 768px wide)

md (specifically for small laptops, screens equal to or greater than 992px wide)

lg (tailored for laptops and desktops, screens equal to or greater than 1200px wide)

.img-responsive {
  margin: 0 auto;
}

/* Dimensions of iPhone 6/7/8 Plus - 414px and 736px width */

@media only screen and (min-width: 414px) and (max-width: 736px) {
  .col-xs-4 {
     width: 25%;
  }
}
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="/jquery.js"></script>
  <script src="/bootstrap.min.js"></script>

<div class="row">
    <div class="col-xs-4 col-sm-3 col-md-2">
        <img src="/cat-image.png" alt="" class="img-responsive">
    </div>
    <div class="col-xs-4 col-sm-3 col-md-2 ">
        <img src="/cat-image.png" alt="" class="img-responsive">
    </div>
    <div class="col-xs-4 col-sm-3 col-md-2">
        <img src="/cat-image.png" alt="" class="img-responsive">
    </div>
    <div class="col-xs-4 col-sm-3 col-md-2">
        <img src="/cat-image.png" alt="" class="img-responsive">
    </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

change the css style with the !important rule to muiStyle

Currently implementing the latest Material-UI library in my project. I am in the process of migrating old CSS files to new MuiStyles. I am converting it within my MuiStyle object using JavaScript as shown below: const muiStyle = { fabStyle: { displ ...

Design a sophisticated background using CSS

https://i.sstatic.net/yILwL.png I am wondering if there is a way to create a CSS3 background similar to the one shown in the image link above. The gradient should smoothly transition from white to black, spanning across a header div, and remain consistent ...

Different methods to incorporate Glyphicons without relying on Bootstrap CSS

For a recent client project, I utilized basic HTML and CSS. However, the client expressed a desire for Glyphicons to be included in the website menus. Attempting to incorporate Glyphicons with Bootstrap CSS posed challenges as it affected other aspects of ...

Create a hover effect for a list item that displays an image and text simultaneously

Is there a way to create an on-hover effect for my icon when hovering over a list item in my dropdown menu? I've shared a codepen link where you can see the issue I'm facing. Everything highlights except the image because I'm only changing ...

Is it possible to utilize v-html with message data in Vue without any limitations on the <title> element?

Currently utilizing Vue.js 2 and my SDK is IntelliJ: I am attempting to bring HTML content into a Vue.js file. The main objective is to include the <title></title> attribute, as it seems that Vue doesn't have direct support for this feat ...

Switch from Index.html to Index.html#section1

Currently, I am working on a website and sending someone a draft for review. However, the Home screen is designed as a 'a href' link with "#home". The issue arises when the website opens from my computer; it goes to ...../Index.html instead of .. ...

How can I create an image link with a hover effect using HTML and CSS?

I've streamlined my code to focus on the issue at hand - I have an image that changes when hovered over, but how can I make it so that clicking on the image redirects you to a specific website? http://pastebin.com/h83yi3e3 Here is the code snippet: ...

Is there a way to trigger the opening of a new file or page when a CSS animation comes to an end?

Is there a way to delay the loading of a function or page until after an animation has finished running in JavaScript, HTML, and CSS only? For instance, I'd like to run an animation first and then have a different website or content load afterwards fo ...

Make Webpage Height Adjust to Browser Size

I've been attempting to solve this issue for quite some time now without success. Check out the website here: The problem I'm facing is that when viewing this site on a large browser window where the height exceeds that of the webpage, there is ...

Create unique list markers by utilizing the "::marker" and "content" properties

When attempting to create a list with custom list markers, I encountered an issue. An example from MDN is provided: li::marker { content: '✝ '; font-size: 1.2em; } <p>Group known as Mercury Seven:</p> <ul> <li& ...

Use JavaScript to add a div element to the page ten times every time the button is clicked

Here is the code I have written: $(document).ready(function () { $('<button class="btn more">View More</button>') .appendTo(".listing-item-container") .click(function() { $(this).closest(". ...

Troubleshooting border styling problems on an iPad for a table

I'm encountering a CSS issue specifically on iPad devices when rendering the HTML page. Oddly enough, everything appears fine on other browsers. The problem I'm facing is a small space between the cells in my tables as shown in this image: Stran ...

Bootstrap 4 tooltip/popover with automatic fallback placement (utilizing two possible placement options)

In the past, Bootstrap 3 offered functionality to handle data-placement="left auto", which would display the tip on the left if there was sufficient space, or calculate an automatic placement if not. However, Bootstrap 4 does not support the use of two pl ...

Which specific element of CSS should be adjusted to ensure compatibility with Internet Explorer?

Struggling with my one-page website layout, I made some adjustments to have six sections in the HTML. Everything seemed to work fine on all browsers except for Internet Explorer. It kept redirecting me to a weird spot between the second last and last two s ...

What is the purpose of the tabindex in the MUI Modal component?

Struggling with integrating a modal into my project - it's refusing to close and taking up the entire screen height. On inspection, I found this troublesome code: [tabindex]: outline: none; height: 100% How can I remove height: 100% from the ...

Conceal table rows with JQuery in html

I need assistance in hiding a row in an HTML Table that contains a value of 0.00 in the third column. I've attempted using JQuery and CSS, but so far no success. Below is the code snippet: <%@ page language="java" contentType="text/html; charset= ...

One way to display a div's inner HTML as its background is to apply a CSS rule

Help needed! <div class="container">red</div> <div class="container">green</div> <div class="container">#eeeeee</div> I am trying to dynamically set background colors for multiple divs based on their inner HTML co ...

A slew of problems arises from this horizontal list

Honestly, I've been struggling with this problem for hours - the submenu just won't style properly, and no matter how many lists I compare it to, I can't seem to get it right. The website: - you have to click "enter" to see the list, my ap ...

Steps for eliminating a column from a table

By including the detailPanel option, a new column with an icon button will be automatically added. https://i.sstatic.net/RoNue.png Is there a way to eliminate this additional column that is generated? Appreciate your help! ...

CSS: Header overlapping navigation menu, disrupting hover effects

While working on my website, I noticed an issue with the div#top element covering the menu. As a result, you can only hover over a link when directly under the text. Does anyone have any suggestions on how to resolve this? ...