The Bootstrap grid systems categorize dimensions into two distinct screen size categories

I am currently exploring ways to customize my Bootstrap 3 grid for desktop size (wider screens) and laptop size (smaller screens). At the moment, I have a box positioned in the center of the container using the following code snippet:

<div className="col-md-8 col-md-offset-2 col-sm-12 col-xs-12">
  ...
</div>

While this setup looks good on desktops (wider screens), it maintains an equal space on the left and right sides. How can I adjust it to fill the entire width (col-md-12) without any space on the left and right for laptops (smaller screens)? Upon inspecting the element in devtools for both devices, I noticed that they are being assigned the col-md classes based on Bootstrap’s media query, resulting in smaller devices still getting the

col-md-8 col-md-offset-2 col-sm-12 col-xs-12 classes
.

Answer №1

Grid breakpoints are determined by the minimum width media queries, which means they only apply to that specific breakpoint and all larger ones (e.g., .col-sm-4 applies to small, medium, large, and extra-large devices, but not the initial xs breakpoint)

To achieve the desired layout for each screen size, you can combine different classes.

UPDATE: I have modified the code snippet and included a complete code example that produces the intended outcome-

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>


  <div class="row bg-danger" style = "height:200px;">
    <div class="col-md-0 col-lg-2"></div> <!--This will leave correct space on the sides of screen according to screen size-->
    <div class="col-md-12 col-lg-8 bg-success text-center" style = "top:50px;height:50px;">
      Your box
    </div> <!--Consider this div to be your box-->
  </div>


</body>
</html>

The provided code snippet will adjust the size of the div as follows -

  • 8 grids for large desktop screens (screens with a width equal to or greater than 1200px)
  • For medium-sized screens (laptops with a width equal to or greater than 992px), it assigns 12 grids to the div.

You can mix and match grid classes in a similar way to cater to various screen sizes and achieve the desired layouts.

I trust this resolves your query!

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

Utilizing CSS to create dynamic 3D cube transformations

Exploring the realm of CSS 3D transforms to showcase cubes and cuboids featuring cross-sections has been my current venture. In this endeavor, I'm aiming at compatibility with Chrome, Firefox, and MSIE 11. It has come to my attention that in order to ...

What is the method for converting a JSON string into an [object][object] format using Angular 6?

Is there a way to transform the data shown below into the [[object][object]] structure using Angular 6? resultArray = [{Q_id: "5bbee2fbbb34b98be0464c73", opt_id: 111},{Q_id: "5bbee2fbbb34b98be0464c73", opt_id: 113}] ...

Adding a PDF generated from an HTML div to an email using Java

I am looking for a solution to convert the contents of an HTML div tag into a PDF file while preserving its associated CSS. This is essential as I will be using Java on the back-end to send emails, and I need to attach the PDF with the CSS intact when send ...

Optimal Method for altering Material UI Icon's height

Placing two icons from Material UI Icons side by side in a row reveals that although their heights are both set to 24px, the actual height of the paths within each icon differs - one being 18px and the other being 22px. This inconsistency in height is not ...

Box surrounding the image with a shade of gray, all thanks to

Despite trying to set "outline: none" and tweaking the border, I'm unable to resolve the issue. For reference, you can visit the page here: . I've shared the link because I'm unsure of what exactly needs fixing or adding on the page. Any gui ...

Stencil - React Integration Does Not Support Global CSS Styling

As per the guidance provided in the Stencil docshere, I have established some global CSS variables within src/global/variables.css. This file is currently the sole CSS resource in this particular directory. Upon attempting to incorporate my components int ...

Detecting hidden child divs due to overflow: hidden in Angular6

Below is the particular issue I am aiming to address. <div class="row" style="overflow:hidden;"> <app-car *ngFor="let car of cars; trackBy: trackByFunction" [car]="car" > </app-car> </div> <button> ...

Opting for a name selector over an id for more specific styling

Is there a way to modify the code below in order to make it function based on a name selector instead of an id? <div id="light" class="change_group_popup"> <a class="close" href="javascript:void(0)">Close</a> JavaScript $('.ch ...

Implementing a collapsible menu feature in Bootstrap 3 when clicked

Experiencing an issue with a Bootstrap menu where I want the menu to collapse after clicking on one of the sections. This is the HTML code: <div class="container" id="home"> <nav class="navbar navbar-default navbar-fixed-top" role="navig ...

Issues with the Stylesheet Unresponsiveness in Bootstrap

I'm having an issue with applying my external CSS file to the HTML code. I've tried changing the order of loading the bootstrap style first, but it doesn't seem to work. HTML FILE: <!DOCTYPE html> <html> <head> <meta ...

Using jQuery to enhance the functionality of the drop-down select feature

I am facing an issue with my index file code. When I select something from the drop-down menu, I expect to see a related dropdown appear. Although I have added this code to my file, I am unable to get the drop down to show after selecting the main type. ...

Creating a semi-circular shaped rectangle using CSS

Is it possible to achieve the unique rectangle borders shown in the image using border-radius or any other CSS property? Here's what I'm trying to create: https://i.sstatic.net/YKPEW.png Currently, this is what I've been able to achieve us ...

Styling Your HTML Background with CSS and Enhancing it with JavaScript

I am lost when it comes to understanding the design of I have spent hours researching how to create backgrounds using shapes and css, but I haven't been successful. Can someone please help me figure out how to create a background similar to . Thank ...

What is the process for modifying CSS in Laravel?

New to Laravel over here, currently working in Homestead. When I need to make changes to my CSS, I typically edit the app.scss file located in resources/assets/sass and then recompile the css with Mix using the command npm run dev. I'm not entirely ...

What is the best way to position a div at the bottom of the main div?

How can I position a div with the class "boxLinks" at the bottom of the main box with the class "main-box"? Here's my idea: The main class has a width of 1200px; within this main class, there are 5 divs with each div having a width of 25%. .main- ...

Is there a way to incorporate an 'ended' feature into the .animate() function?

I'm currently working on a jQuery statement where I want to activate pointer events once the button animation is finished. However, I'm unsure how to incorporate an ended or complete function. Any suggestions on how to approach this? $('#ce ...

Issue with dropdown menu display in Internet Explorer

Having trouble with a CSS dropdown menu displaying incorrectly in IE, while working fine on other browsers. <body> <div id="container"> <header> <div id="hlogo"> <a href="index.html">title ...

Suboptimal placement of second submenu in Navbar

This question is inspired by a discussion on Stack Overflow that you can read here. Everything seems to be working fine, except when the 2nd level item is not at the top. In the example provided, the item with the 2nd level menu is the first item. If you m ...

Adjusting the margin on an element causes a shift in the entire page's

Why is the margin of an h2 element on my page displacing the entire body downward? This seems abnormal since the h2 element is within a div container. Is there a way to address this issue? https://i.sstatic.net/E3CLW.png ...

Struggling with combining CSS stylesheets?

I am looking to incorporate the vertical timeline feature from CodyHouse into a project utilizing a Bootstrap template hosted on Github. I have successfully transferred the HTML content, however, there are some complications with the CSS files. The issues ...