Creating a Grid layout with an abundance of visual elements and minimal text content

I am working with a grid component from Material UI:

Item element

const Item = styled(Paper)(({theme}) => ({
    ...theme.typography.body2,
    padding: theme.spacing(2),
    textAlign: 'center',
    color: "black",
}));

Structure

    <div className="wrapper">
        <Typography variant="h3" component="h3">
            List of friends
        </Typography>

        <div className="friends">

            <Grid container
                  direction="row"
                  rowSpacing={1}
                  spacing={{xs: 2, md: 3}} columns={{xs: 4, sm: 8, md: 12}}
                  alignItems="center"
                  justifyContent="center"
            >
                {
                    friends.map((friend, i) => {
                        return <Grid item xs={4} sm={6} md={6} mt={5}>
                            <Item className="item"><span>{i}</span>{friend.name}</Item>
                        </Grid>
                    })
                }
            </Grid>
        </div>
    </div>

With custom CSS styles:

.wrapper{
    width: 100%;
    position: relative;
    align-items: center;
    display: flex;
    flex-direction: column;
    background:#eaeaea
}

.friends{
    position: relative;
    width: 75%;
}

This is how it currently looks:

https://i.stack.imgur.com/BaePi.png

But I want the friend numbers to be on the left and highlighted like this:

https://i.stack.imgur.com/h1PDL.png

How can I style the <span> element to achieve this? When I tried styling span with:

span{ position: absolute; left: 0 width:25%; height: 100% }

The span appeared somewhere else due to Material UI's extensive styling. Is there a simpler way to achieve this effect?

Alternatively, is there another component I can use instead of the Item (Paper) element?

Thank you for your assistance!

Answer №1

To implement a grid layout for the Paper element, you can apply the following CSS:

<Paper
  sx={{
    display: 'grid',
    grid: 'auto / 25% 75%',
    height: 50,
    '& > div': {
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      width: '100%',
      height: '100%',
    },
  }}
>
  <Box>1</Box>
  <Box>Name</Box>
</Paper>

Alternatively, you could achieve a similar layout using flex: 1 and flex: 3, but the grid method offers a more straightforward setup with all the styling logic in one line.

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

"Troubleshooting problems with the display:none property in a media

Encountering a small dilemma with media queries within my HTML. One of the sections in my code contains the following: <div class="header-left"> </div> <div class="header-center"> <ul> <li class="end"> ...

Text that disappears upon clicking on show/hide按钮

Could someone please help me figure out how to prevent the "See more" text from disappearing when clicked in the example below? I want it to stay visible. Thank you! ...

Cannot get object state to update using React hook

I'm not very experienced with React. I attempted to set the state as an object by fetching data from an API. The fetching process returns the correct object, but for some reason setting the state is not functioning correctly. const [info, setInfo] = ...

Utilizing AppBar in material-ui for navigating through MenuItems

I have been working on integrating a navbar into the AppBar component in Material-UI. Here is the code snippet I am currently using: Currently, my project is utilizing version 3.9.2 of @material-ui/core. class Header extends Component { handleMenuOpen ...

The Transition Division Is Malfunctioning

I've encountered an issue where I am trying to move a div by adjusting its left property, but no transition is taking place. Regardless of the changes I make to my code, the result remains the same. Below is the current state of the code. Can anyone i ...

Utilizing material-ui's LocalizationProvider to display times in a different time zone

My application requires material-ui date and time pickers to function based on a remote time zone specified by the server. I want the today circle on the date picker to accurately reflect today in the remote time zone, and I need to convert the datetimes i ...

Updating style of an element by hovering over another

What is the best way to change the CSS of one element when hovering over another element in CSS? We can achieve this using the following code: .example .example2 li:hover .element If our HTML looks like this: <div class='example'><di ...

The Price Filtering feature in the MERN Stack for Products is currently experiencing technical difficulties

Hey there! I am currently working on developing an Ecommerce Application using the MERN Stack with redux. I've encountered a problem while trying to send a price array argument in my fetching function. The error message states: XHR GET http://localhos ...

What could be causing the issue with saving form data to local storage in React?

I am facing an issue with the code I have written to store data in local storage. Sometimes it works fine, but other times it saves empty data or erases the previous data when the Chrome window is closed and reopened. Any idea what could be causing this in ...

Update the text for the filter search placeholder in the Ant Table component

Is there a way to alter the default placeholder text in the Ant Table? I've set up a functioning example in documentation but couldn't find any prop for customization besides the customized filter dropdown, which I didn't want to implement. ...

Error message: The 'target' property cannot be read because it is undefined - react

←→1 out of 3 errors found on the page Error: The property 'target' is undefined and cannot be read This error occurred in the following section: App.inputChangeHandler src/App.js:37 34 | 35 | inputChangeHandler(index,event){ 36 | ...

Is AngularJS causing issues with Foundation modals? Any solutions to this problem?

Wondering how to manage Foundation4 modals with AngularJS? I've noticed that when I navigate from a modal to a new view, the old modal disappears but the page stays darkened as if it's still there in the background. I tried adding a class attribu ...

The Coinbase Pay application fails to compile properly due to a missing Babel loader

Currently, I am working on integrating the coinbase pay sdk into my project. Although I have successfully created a button utilizing their provided examples, I am encountering an issue during the build process which seems to be internal to their SDK. Spec ...

Ensure that the form values are populated using redux-thunk and useSelector only after the data has been fully loaded

Hey there! I'm working with redux-thunk and using useSelector to fetch some data for populating a form. I've noticed that there is a delay in getting the data, so initially it's undefined. Then, once the data is loaded, the form doesn' ...

Error: Compilation was unsuccessful due to module not found. Unable to resolve in ReactJS

As I was wrapping up this task, an unexpected error popped up: Module not found: Can't resolve './components/Post' in ./src/pages/index.js I've tried everything to troubleshoot it but no luck. Here's a rundown of my code snippets ...

Custom cellRenderer prevents Ag Grid's autoHeight and wrapText features from functioning properly

I've been attempting to adjust the formatting of a long cell value by wrapping the text. According to the documentation, setting autoHeight=true and wrapText=true works fine without any cellRenderer components. However, when using a cellRendererFramew ...

Switch out the checkboxes in Material-Table for radio buttons instead

Currently utilizing the material-table to display data. My goal is to select one row at a time and pass that row's data to another component. Multi-row selection is not desired, so using radio buttons instead of checkboxes is the suggested solution. I ...

What is the reason for sending a single file to the server?

A function called "import File" was developed to send multiple files to the server, but only one file is being received. Input: <input type="files" id="files" name="files" multiple onChange={ (e) => this.importFile(e.target.files) } ...

The passing of React parent component props to the child component is not functioning as expected

Retrieving data through an ajax call and saving it to the state of the component _fetchDataFromServer(){ reqwest({ url: 'http://127.0.0.1:8000/api/example/' , type: 'json' , method: 'get' , contentType: &ap ...

What is the most effective method for locating and capturing a specific element (such as an input box) in Python Selenium using either Xpath or CSS selector

I am currently using selenium to scrape a website, primarily relying on xpath or CSS selectors to extract elements. However, I have noticed that these selectors are dynamic, which contradicts what I have read online about CSS selectors being stable. As a b ...