Creating a sleek and dynamic grid system using Sass for columns ranging from small to large sizes

I'm having trouble locating the information I need on Google. I'm attempting to establish a flexible grid system that employs columns similar to foundation or bootstrap. Specifically, I am aiming to implement column column-med column-lg, but I'm unsure of how column-med should take precedence over column-lg when breakpoints shift. I recognize that it must relate to a breakpoint in some manner, but my goal is to utilize a sass map for this purpose without relying heavily on media queries. Can anyone provide guidance on how to approach this situation?

Answer №1

To begin, you should create a mixin specifically for handling media queries. Here is an example:

@mixin small {
    @media screen and (min-width: 768px) {
        @content;
    }
}
@mixin medium {
    @media screen and (min-width: 1024px) {
        @content;
    }
}

Repeat this process for any other sizes you may require. To use the mixin in your .scss file, follow these steps:

@include small {
  //Your css rules here
}

@include small {
  //Your css rules here
}

When creating a grid layout, it is recommended to utilize flexbox for column organization. Begin with defining your default columns like so:

.col {
  flex-grow: 0;
  flex-shrink: 0;
  max-width: 100%;
  padding-left: 10px;
  padding-left: 10px;
  box-sizing: border-box; //ensures padding is included in size calculation
}

.col-6 {
  flex-basis: 50%;
  max-width: 50%;
}

This setup will result in two columns for any window size using the classes 'col' and 'col-6'. If desired, the 'col' class can be omitted to remove gutters.

Next, define classes with corresponding media queries as shown:

@include small {
  .col-sm-6 {
    flex-basis: 50%;
    max-width: 50%;
  }
}

@include medium {
  .col-md-4 {
    flex-basis: 33.333333%;
    max-width: 33.333333%;
  }
}

By applying the classes 'col', 'col-sm-6', and 'col-md-4', your layout will automatically adjust to display one column under 768 pixels wide, two columns from 768 to 1023 pixels, and three columns at 1024 pixels or more.

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

Bootstrap4: Multi-image Carousel Design

I have been trying to modify this Bootstrap 4 multi-image carousel to display 4 images instead of 3. Can anyone help me figure it out? Here is the code I am currently working with: ...

What is the best method for flipping the sequence of elements in media queries?

I am facing an issue with two divs, left and right, on my webpage. When the screen size is less than 500px, I want the left div to move to the bottom and the right div to move to the top. Essentially, I need to swap the positions of these divs in the DOM. ...

Tips for highlighting the final word in the headline using an underline

I'm attempting to create a title style similar to what is shown below https://i.sstatic.net/Qao4g.png The issue I'm facing is achieving the underline effect. I tried using title:after but it didn't give me the exact result I'm looking ...

tips for expanding the size of your images

Hey there, I'm looking for some help with the code below. I need to increase the width of the images and remove the border of the slider div which is currently showing a white border that I want to get rid of. I am using JavaScript to display the imag ...

CSS: element misplaced at the top instead of the bottom where it belongs

The component with the ID of "#bottom-nav" actually appears at the top. I just designed this on CSS-board, so feel free to review the HTML and CSS code Take a look at it on CSS-desk here It is positioned at the very end of the page and includes a ' ...

Challenged with selecting an item within select2 due to the presence of a lower-down multiple select

Why am I unable to select options 2 & 3 when I open #s1? Instead, when I click on them, the cursor goes into #s2. How can I resolve this issue? I initially considered that it might be related to the z-index, but after attempting to adjust it, the prob ...

"Issue with scaling on Responsive Canvas leading to blurriness

I am working on a Canvas project and I want to make sure it is easily navigated on any device, whether it's a desktop or mobile. To achieve this, I decided to make the canvas responsive. Originally, the canvas was set at 800x800 which looked fine but ...

Does anyone know of a media query specifically designed for desktops that targets devices in 1366*768 landscape mode only?

I managed to create a design that works perfectly for the iPad Pro in landscape mode with a resolution of 1366x1024. It doesn't affect the viewport of my device with a resolution of 1366x768. Take a look at the code snippet below: @media only screen ...

Manipulating the DOM by nesting an icon within a button element in HTML

Currently working on my todo list project and I have a question about using innerHTML. I'm curious if I can include an icon inside of a button tag like this: btn.innerHTML = '<i class="fas fa-times fa-lg"></i>'; So, wo ...

Custom sized box causing Bootstrap Navbar to be unresponsive

I am having trouble loading the Bootstrap 3 navbar inside a .box class with specific CSS rules: .box { height: 600px; width: 320px; position: relative; border: 2px solid #eee; } Unfortunately, it is not displaying re ...

Move the div to the bottom of its container

Is there a way to place a div at the bottom of its containing div? <style> .outside { width: 200px; height: 200px; background-color: #EEE; /*for visibility*/ } .inside { position: absolute; bottom: 2px; } </style> <div c ...

Modify the CSS style for the hyperlink within my asp:menu

I recently updated the style of my asp.net menu, but I am struggling to change the style of the < a href > link. As shown in the image above, the link size does not cover the entire size of the < td > element. Is there a way to resolve this is ...

Saving a dynamic form to the database and editing it later

I have developed a dynamic form builder using jQuery UI that allows users to drag form inputs anywhere on the screen and generate a report. Now, I am trying to figure out the best approach for saving this layout to a SQL database. How can I save the struct ...

Fixed menubar is being used to display section headings

Despite my usual avoidance of CSS, this time I had to work with it and ran into a peculiar issue. Whenever I click on the menu in the header, the titles of the sections start going behind the menu. If anyone can help, here is the code snippet: http://jsf ...

The toggle button is having issues functioning properly within a While loop

Is there a way to enable slideToggle for all my queries? Currently, it is only working on the first query. Any suggestions on how to resolve this issue? JS code $(document).ready(function(){ $("#SendCopy").click(function(){ $("#users").slideToggle("s ...

Error message: Cannot define _menu property on Bootstrap select picker due to Uncaught TypeError

I've encountered an issue with the bootstrap selectpicker. When I try to click on the dropdown list, an error appears and I'm unable to use data-live search. I attempted to change the bootstrap version, but unfortunately, that did not resolve the ...

<td> issue with IE not rendering overflow:hidden properly

In an effort to display text in a TD, I've implemented the overflow property set to hidden for the td element. Surprisingly, this code works flawlessly in Chrome, Safari, and Mozilla browsers, but unfortunately falls short in IE. Despite attempting to ...

What is the best way to center three columns using CSS?

Seeking assistance in creating an HTML organization chart with CSS, specifically looking to adjust the spacing between <li> tags. Code for reference: https://jsfiddle.net/8q9uxzb6/ Attempting to set the margin-left value on line 89 of the CSS to 3 ...

What is the best way to align content in the center when its parent element has a position property

JSBIN Is it possible to center the number row without using JavaScript to calculate its position, considering its parent has a fixed attribute? I've tried using CSS properties like margin and text-align with no success. Any suggestions on achieving t ...

Guide: "Adding markers to user-uploaded images - A step-by-step tutorial"

I'm struggling to create a website that allows users to upload images and use specific tools. However, I am facing an issue where the marker I want to add is appearing all over the webpage instead of just on the image itself. How can I confine it to o ...