What is the best way to adjust the layout for smaller screens using material ui?

  • Just starting out with responsive material design.
  • On smaller screens, the Sports Status needs to remain in the right corner.
  • 4Standard, 5Standard, 6Standard, 7Standard, 8Standard, 9Standard should wrap to the next line.
  • I came across this code snippet for media queries while researching online, the color changes, but struggling with altering the layout:

    ["@media (min-width:780px)"]: {
       // eslint-disable-line no-useless-computed-key
       backgroundColor: "red"
    }
    
  • Can the layout structure be changed with CSS alone or does it require JavaScript?

  • Could someone provide guidance on how to resolve this? I've included a sandbox and code snippet below.

Small screen demo: https://codesandbox.io/s/material-demo-xkwyl

Large screen demo:

sportsCardHeaderItem: {
    color: "black",
    margin: "10",
    textAlign: "left",
    paddingLeft: 16,
    backgroundColor: "green",
    ["@media (min-width:780px)"]: {
      // eslint-disable-line no-useless-computed-key
      backgroundColor: "red"
    }
  },
  sportsCardHeaderItemSecond: {
    margin: "10",
    textAlign: "left",
    paddingLeft: 24
  },
  sportsCardHeaderItemHeading: {
    fontSize: 14,
    color: "#455A64"
  },
  sportsCardHeaderItemHeadingValue: {
    fontWeight: "bold",
    fontSize: 20,
    color: "#263238"
  },

Below is the markup

   <div
          style={{ flexGrow: "0" }}
          className={classes.sportsCardHeaderItemSecond}
        >
          <div className={classes.sportsCardHeaderItemHeading}>3Standard</div>

          <div className={classes.sportsCardHeaderItemHeadingValue}>jkjkjk</div>
        </div>

        <div
          style={{ flexGrow: "0" }}
          className={classes.sportsCardHeaderItemSecond}
        >
          <div className={classes.sportsCardHeaderItemHeading}>4Standard</div>

          <div className={classes.sportsCardHeaderItemHeadingValue}>jkjkjk</div>
        </div>

        <div
          style={{ flexGrow: "0" }}
          className={classes.sportsCardHeaderItemSecond}
        >
          <div className={classes.sportsCardHeaderItemHeading}>5Standard</div>

          <div className={classes.sportsCardHeaderItemHeadingValue}>jkjkjk</div>
        </div>

        <div
          style={{ flexGrow: "0" }}
          className={classes.sportsCardHeaderItemSecond}
        >
          <div className={classes.sportsCardHeaderItemHeading}>6Standard</div>

          <div className={classes.sportsCardHeaderItemHeadingValue}>jkjkjk</div>
        </div>

Answer №1

To implement a responsive design, consider the advice provided in "Adaptive page layout with Media Queries" by Mathieu Nebra and Emily Reese.

@media screen and (max-width: 1280px)
{
    /* Add your CSS properties here */
}

For instance:

If your page width is set to 900 px and the content is centered:

#bloc_page
{
    width: 900px;
    margin: auto;
}

You may want to introduce a media query like this:

@media all and (max-width: 1024px)
{
    #bloc_page
    {
        width: auto;
    }
}

This media query addresses window width less than 1024 px across all devices. It ensures the page adjusts its width automatically instead of staying fixed at 900 px.

By allowing the page to expand to fit the available space, you prevent horizontal scrollbars on smaller screens.

If your CSS is structured correctly, you can implement a similar approach.

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

What could be causing a functional component's child component to be using stale props?

I am currently working with Next JS, but the process is similar. I have refined the code and eliminated irrelevant parts. My goal is to create a form where new fields (child components) can be added dynamically. The default setting will be 1 field, with a ...

Utilizing React-Engine and Express to Transfer Server-Side Variables to Client-Side

I'm fairly new to working with React and React-Engine. I have a server-side configuration that contains certain values that need to be passed to the client-side. However, I rely on NODE_ENV to determine which specific configuration to use. var config ...

Having trouble installing the React app through the terminal

I've encountered an issue while trying to install a react app using the terminal. Each time I attempt, it gives me an error stating that node is not recognized as an internal batch file. Oddly enough, when I run node --version, it shows v12.8.3. http ...

Ensuring File Size and Format Compliance in Angular's HTML and TypeScript

I'm currently tackling a file upload feature on an ASP.net webpage using Angular. I have a question: How can I verify if the uploaded file is either a PDF or JPG and does not exceed 2MB in size? If these conditions are not met, I would like to displa ...

Error: Unable to locate named export for 'express'

I am facing an issue with my CRUD project developed using react and nodejs. When I attempt to run index.js, a strange error pops up: Named export 'express' not found (please refer to the image for details). The code in my index.js file is as fol ...

Is it possible that the use of excessive React.Fragment could impact performance negatively?

After a recent review of our company's code, I discovered that the performance is not up to par. One common pattern I noticed in the code is something like this: condition ? <SomeComponent /> : <></> I see that Fragments are being u ...

Reduce the length of the text and display it upon hovering with the mouse

I am trying to figure out how to truncate text and have it expand on mouseover in a paragraph element. I attempted to truncate the content using a specific code, but I encountered an issue. While my current code expands the content when clicking on the el ...

Ways to make a div fill the whole screen and allow for scrolling as well

Issue I'm facing an issue with the login.php screen and the addphoto.php screen. I want these screens to cover the entire page, but despite using the following code: .login-screen, .form-screen { position: fixed; top: 0; left: 0; disp ...

Is it possible to get this numeric input working properly? [HTML5]

How can I create a button that generates a random number between 0 and a specified value x when clicked? Currently, my implementation is returning NaN instead of the desired random number. function generateRandomNumber() { document.getElementById("num ...

.htaccess file is causing js and css files to not load

I followed an MVC tutorial by howcode on YouTube, but I encountered an issue where my CSS and JS files were not loading due to the htaccess configuration. .htaccess file: RewriteEngine On RewriteRule ^([^/]+)/? index.php?url=$1 [L,QSA] I attempted vario ...

Integrating a feature for displaying No Results Found

I am struggling to modify a script for auto-completing search fields. My goal is to include a "No Results Found" option along with a hyperlink when no matching results are found. I'm having difficulty figuring out how to add an else statement to displ ...

Leverage the power of Bootstrap by showcasing several carousels in a sleek grid layout

How can I display dynamically generated carousels in a grid format using Bootstrap4? Current formation: https://i.sstatic.net/H3du7.png I want to showcase multiple carousels containing one or more images in a clean grid layout instead of the current hor ...

What is the process for detaching and attaching click animations using the on() method?

I am encountering an issue with a recursive loop that executes a simple animation. These animations are controlled by the page load and clicking on controls .carousel_item. Click here for live sample JSFiddles for demonstration purposes Challenge: The pr ...

How can I retrieve the width of a responsive React element during its initial rendering phase?

In my React project, there is a component called ResultList which is used to display products in a gallery format. The challenge I'm facing is determining the appropriate number of products to show per row based on the available width for the ResultL ...

AngularJS and Bootstrap carousel combined for a dynamic multi-item per slide display

Currently, I am utilizing Bootstrap to showcase a carousel on my website, where multiple items are displayed per slide as demonstrated in this example. The use of static images has yielded satisfactory results, as evidenced by the jsFiddle example found he ...

The Express server is failing to establish a connection with Node.js due to an error in the

import React, { useState, useRef, useEffect } from 'react' import user from '../components/Client'; import Editor from '../components/Editor'; import { initSocket } from '../socket'; import ACTIONS from '../acti ...

Ways to Create a Webpage with a Single Color Palette

Struggling to update the background color on my webpage and hitting a wall. Even with content, the black background only extends as far as the content does. I've experimented with extending the content, using the body selector, and universal selector ...

React: Issue with input values not correctly updating across multiple fields when changing state toggles

I am working on a React component that needs to update input values for multiple players independently. However, I am facing an issue where toggling a state causes the first input's value to incorrectly propagate to all other inputs. Additionally, cle ...

Assign the value of "td" to the variable "val"

I am trying to set the value of my td element from my JavaScript JSON, but for some reason it doesn't seem to be working when I inspect the element. The HTML is functioning fine, it's just the value that isn't updating. I've tried chang ...

Uploading a file to a .NET Framework API Controller using React

I am trying to figure out how to send files in the request body to an API controller in .NET framework using React. My goal is to achieve this without changing the request headers, so I want to send it as application/json. What I am looking for is somethi ...