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

I am looking to superimpose one rectangle over another rectangle

I am looking to create something similar using CSS and TypeScript/JavaScript: Could someone please guide me on how to achieve this? My attempt with a flex container looks like this: I am new to front-end development. Can anyone point out what I might be ...

Show or hide a fixed position div using jQuery when clicked

I am new to jQuery and I am trying to create a "full page menu" on my own. However, I am struggling to hide the menu on the second click. I tried using .toggle() but I found out that it has been deprecated. Can someone assist me with this? Thank you so muc ...

An unauthorized token was detected upon the return of the forked project

After completing my coding boot camp, I was excited to showcase my final React project on my Github for potential employers. I decided to fork the project from my school's Github repository and everything was running smoothly until then. However, I wa ...

Successfully passing props to the image source using React/Next.js

Currently, in my implementation with React and Next.js, I am utilizing next-images for importing images. I am looking for a solution to pass data directly to the img src attribute, like so: <img src={require(`../src/image/${data}`)} /> It appears t ...

How can you style text with a circular border using CSS?

I'm struggling to locate an example of what I need. My goal is to make a circle around my text using CSS. While I've seen examples of circles with the text inside, in this case, I aim to have a circle surrounding the text. Here's an illustr ...

When you hover over HTML tables, they dynamically rearrange or shift positions

Issue: I am encountering a problem with multiple tables where, upon hovering over a row, the tables are floating rather than remaining fixed in place. Additionally, when hovering over rows in the first or second table, the other tables start rendering unex ...

Tips for designing a form action

I am a beginner and struggling with understanding the CSS for the code below. Can someone help me out? <div id="page-container"> <?php include_once("home_start.php"); ?> <h1>Login</h1> <for ...

Enforcing object keys in Typescript based on object values

I'm looking to design a structure where the keys of an object are based on values from other parts of the object. For example: type AreaChartData = { xAxis: string; yAxis: string; data: { [Key in AreaChartData['xAxis'] | AreaChart ...

The error TS2339 is indicating that there is no property called myProperty on the type SetStateAction<User>

I'm encountering a TypeScript error while working with React that's leaving me puzzled: <html>TS2339: Property 'subEnd' does not exist on type 'SetStateAction&lt;User&gt;'.<br/>Property 'subEnd' d ...

Tips for creating a flexbox layout that is responsive to different screen

Currently, I am using flex to ensure that the two inner div elements have the same height. However, the design is not responsive as it appears perfectly in a full-width window but gets squeezed on mobile devices. Is there a solution to this issue? Are th ...

retrieve all the table data cells except for the initial one

I have a specific table structure that I need to work with: <table> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td&g ...

The autoHideDuration feature does not function properly when there is a change in the

I am considering enabling autohide duration after a certain process in the FC component by utilizing hooks to handle state. <Snackbar anchorOrigin={{ vertical: 'bottom', horizontal: 'center', }} ...

Make sure the top edge of your Bootstrap 4 dropdown menu is perfectly aligned with the bottom edge of your

Trying to make a Bootstrap 4 navbar dropdown display right below the navigation bar, but it consistently shows slightly above the bottom edge of the navbar. Is there a way to make this happen without fixing the height of the navbar and using margin-top fo ...

Strapi registration operates successfully, however it yields an empty data object upon completion

I'm currently working on implementing an Authentication flow using strapi. After setting up the /api/auth/local/register endpoint, everything seems to be functioning correctly -- when I register a user and then refresh the strapi Users page, the new u ...

What is the best way to eliminate the blue-box-fill when buttons are clicked?

Check out this screen recorded gif on my device showcasing the blue-box-fill I'm referring to: https://i.stack.imgur.com/ajr2y.gif I attempted the following solution: * { user-select: none; -webkit-user-select: none; /* Safari */ -khtml-user-s ...

Exploring how to replicate background-size: cover with a center position using HTML5's <video> tag

Looking to replicate the effect of background-size: cover on a <video> element. I was able to achieve this with the code below: <video id="videobackground" autoplay="true" loop="true"> <source src="BackgroundFinal2.mp4" type="video/mp4" ...

ReactJS and Webpack: Troubleshooting image display issues

I am having trouble loading a background image in my component. Despite using require('imagepath') to load the image, it gets changed to url('imagepath') during build. However, when I try to load it within my styles that are being added ...

I'm having trouble getting this button and icon to align properly. How can I fix this misalignment

Take a look at the HTML code snippet I'm currently working on... <div id="projects"> <H1 class="projects">PROJECTS</H1> <div class="box"></div> <div class="box"></div> <div class="box"></ ...

Having trouble with customizing a selected ListItemButton in Material-UI - need some help with

After reviewing the documentation, I discovered a method to override the styling of the selected class by introducing a new class under .MuiSelected. The implementation looks something like this: const customStyles = makeStyles(() => ({ customizedSele ...

Is the navbar-nav being unexpectedly placed below the navbar-brand?

As my screen width decreases to 767px, the navigation collapses as expected. However, at 768px, the navbar-nav drops below the navbar-brand until reaching 795px where they realign again. These values may vary based on the size of your navigation. Check o ...