Can you explain the significance of xs, md, and lg within the CSS Flexbox framework?

Currently in the process of developing an application using React and looking to apply some styles to my components. I stumbled upon which delves into a fluid grid system. A snippet from the example is shown below:

<Row>
  <Col xs={12} sm={3} md={2} lg={1} />
  <Col xs={6} sm={6} md={8} lg={10} />
  <Col xs={6} sm={3} md={2} lg={1} />
</Row>

I'm curious about the significance of xs, sm, and lg. Can someone provide some clarification on this?

Answer №1

Let's imagine that our display is divided into 12 columns.

The classes like xs, small, medium, and large will determine how much space each column takes up based on the screen size in CSS.

Here's an example:

<Row>
  <Col xs={12} sm={3} md={2} lg={1} />
  <Col xs={6} sm={6} md={8} lg={10} />
  <Col xs={6} sm={3} md={2} lg={1} />
</Row>

For this example, we'll call these columns col-1, col-2, and col-3

On extra small screens:

col-1 occupies all 12 columns while the other two take 6 each on a new row https://i.sstatic.net/9iHbH.png

On small screens:

col-1 and col-3 take up 3 columns each, while col-2 takes up 6 columns https://i.sstatic.net/uNmZg.png

Similarly

On medium screens: https://i.sstatic.net/sbiTg.png

On large screens: https://i.sstatic.net/4qqYF.png

P.S. The images show screenshots of the link provided (by adjusting the browser size for each screen)

Answer №2

React Flexbox Grid is a powerful tool for creating responsive websites, inspired by the grid system used in Bootstrap.

This grid system divides the screen into 12 columns, allowing you to specify how much width components should take up on mobile devices, tablets, and desktops. The breakpoints for xs, sm, md, lg, and xl are set at 576px, 768px, 992px, and 1200px respectively.

To visualize the impact of these breakpoints, simply resize your browser window while visiting https://example.com/react-flexbox-grid/

You can think of this as similar to using media queries:

// xs --- Extra small devices (portrait phones, less than 576px)
// Default in Bootstrap

// sm --- Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }

// md --- Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }

// lg --- Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }

// xl --- Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }

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

Mastering ReactJS: Error Encountered - Unexpected import Token

Just getting started with ReactJS and trying out some code from egghead.io. Unfortunately, I keep running into this error: Uncaught SyntaxError: Unexpected token import I've tried loading babel again and making sure to follow the lesson step by step ...

Incorrect column alignment in Tailwind CSS

I am working on a straightforward flexbox layout with a two-column grid setup. <div class="flex relative"> <div class="columns-2 gap-4 space-y-4"> <div class="bg-red-500 p-10">1</di ...

A total of 63 security weaknesses were discovered while developing a new React

Hey there! I'm venturing into the world of creating a react app, but it seems like I've encountered 63 vulnerabilities. As a new user of React, I would greatly appreciate any experienced individuals who can assist me in setting up my project. Tha ...

What is the best way to transfer state information from a hook to be displayed in the App component in React

Is there a way to transfer the state(data) of info to the App hook, in order to showcase the properties within div elements? The function setInfo(info) saves the data intended for display on the Map hook and inspecting console.log(info) within _onClick rev ...

Save property using the useState hook

I am working on implementing a sorting function in the child component, where the props are passed in from the parent through an axios call. Should I: Store the prop in the child component's useState? Pass the parent's setState function as a pro ...

Footer overlapping occurs on a single page

My webpage is having an issue where the footer is overlapping. It seems to be fine on all other pages except for this one. I would prefer not to make any changes to the footer since it's working correctly on other pages. Is there a way to adjust the C ...

Is it possible to send data using React and Express together?

I am currently developing a login/register system using React for the front-end and Node/Express for the back-end. In the event of a registration failure, my goal is to reload the registration page and send the error messages back to the React front-end. ...

Is it possible to display two separate pieces of content in two separate divs simultaneously?

import React from "react"; import ReactDOM from "react-dom"; ReactDOM.render( <span>Is React a JavaScript library for creating user interfaces?</span>, document.getElementById("question1") ) ReactDOM.render( <form class="options"> ...

The functionality of "Body Onload" for sending "ScrollHeight" is malfunctioning in Chrome and Safari

I came across an issue where the iframe_resize function in my code was not working as expected. After investigating further, I realized that the problem did not lie with the function itself. So, I decided to post a new question. Within my index.html file ...

Search across the entire table in your React application with Global

Having trouble implementing global search with the new Material UI Next table component. I have a handleSearch method that takes an event as a parameter and uses regex to check if the event.target.value matches any data in the table. However, when I dele ...

Activating setState in another component within the same level

As I work on creating a ToDo list, I have an input field in a child component and the array state stored in the parent. To enable re-rendering of the list based on completion status with a click, I am thinking of moving the array to its sibling component, ...

Changing position of element upon appearance of span in React

Currently, I am working with React and facing an issue where a span element appears whenever a user hovers over a text element. The problem is that the existing text shifts leftwards when the span appears (to the right of the text). The desired behavior ...

Looping through color transitions upon hover using CSS

I am trying to create a color transition effect on hover, where the background changes from yellow to red and then back to yellow in a loop. I'm having trouble figuring out how to make this transition repeat continuously. Do I need to incorporate Java ...

Error: The constructor for JsSHA is not valid for the TOTP generator

Attempting to create a TOTP generator similar to Google's timed-based authenticator using the React framework. I am utilizing the bellstrand module for TOTP generation, but I am encountering issues when trying to import it into my React code. Here is ...

Tips for extracting the index of the chosen item from a dropdown using ReactJs and Material UI

This is the code snippet for Dropdown component implementation: <DropDownField name={formElement.name} label={formElement.name} value={formik.values[formElement.name] || ''} dropDownItems={formElement.name === &apo ...

The alignment of links is not meeting the centering requirement

I'm facing a challenge with aligning my "buttons" on the pages, although they are essentially text links designed to resemble buttons using CSS. These buttons are utilized within an unordered list structure (refer to the HTML snippet below). The rele ...

Having trouble sending data to my server using a POST request with Axios

Below is the React code I've written for form submission: const handleSubmit = (e) => { e.preventDefault(); console.log('item:', item); Axios.post('http://<MY_SERVER>/item/add', {name:item}) .then(resp ...

Error TS2322: The function expecting a type of 'FormEventHandler<HTMLFormElement>' cannot be assigned the type '(data: TicketFullDTO) => Promise<void>'

I am currently working on creating an edit form to modify data from a database based on its ID. Here is my approach: import React, {FormEvent, useEffect, useState} from "react"; import TextField from "@material-ui/core/TextField" ...

Ensure that the CSS element pseudo-class does not override the styling of its child

Looking to style an anchor element that contains other HTML elements. Here is the basic code structure: HTML: <div class="container" id="sub-menu"> <div class="row" data-bind="foreach: subMenu"> ...

Please disregard clicking on see-through areas of images

Currently working on a game project that involves layering multiple images (tiles) on top of each other to create a sense of depth. However, I have encountered an issue when attempting to click on these overlapping tiles. Due to their transparency, click ...