Tips for creating a MaterialUI list that wraps to the next line?

import React from 'react';
import {
  List, ListItem,
} from '@material-ui/core';
import {
  makeStyles, createStyles,
} from '@material-ui/core/styles';
import clsx from 'clsx';
import VideoCard from './VideoCard';

const useStyles = makeStyles(() => createStyles({
  root: {
    display: 'inline-flex',
  },
  item: {
    padding: '80px 40px',
  },

}));

export default function VideoList(props: any) {
  const { videos } = props;
  const classes = useStyles();
  return (
    <div>
      <List className={clsx(classes.root)}>
        {videos.map((video: any) => (
          <ListItem className={classes.item} button key={video}>
            <VideoCard videoTitle={video.title} thumbnailImage={video.imageSrc} key={video} />
          </ListItem>
        ))}
      </List>
    </div>
  );
}
import React from 'react';
import Typography from '@material-ui/core/Typography';
import clsx from 'clsx';
import Thumbnail from './Thumbnail';

export default function VideoCard(props: any) {
  const { thumbnailImage, videoTitle } = props;
  return (
    <div>
      <Thumbnail imageSrc={thumbnailImage} />
      <Typography>{videoTitle}</Typography>
    </div>
  );
}

I am attempting to showcase a series of video titles and thumbnails in a layout similar to the video cards on the homepage of YouTube. How can I make sure that the cards wrap onto a new line every 4th card? Currently, they are lining up and extending off the screen.

Update: Included my VideoCard code as well for reference

Answer №1

Change the style to float: 'left' and then adjust the width to 100% - 25% to ensure a new line is created after every 4 cards

const useStyles = makeStyles(() =>
  createStyles({
    root: {
      width: "100%",
      display: "inline-block"
    },
    item: {
      padding: "80px 40px",
      float: 'left',
      width: '25%'
    }
  })
);

https://i.stack.imgur.com/8Vwf2.png

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

Is utilizing React function components the most effective solution for this problem?

export default function loginUserUsing(loginType: string) { const [state, setState] = useState(loginType); function login() { // body of the login function } function oauth() { // body of the oauth function login(); ...

Issue with z-index in Internet Explorer version 7

Currently, I have implemented a drop-down list using jQuery that activates when the user hovers over the main menu. This functionality is working appropriately in all browsers except for IE7 and earlier versions. In an attempt to ensure the drop-down menu ...

The integration of Angular CLI with SCSS is no longer a separate process -

It seems like I might be overlooking something very straightforward here. After a fresh installation of angular-cli, I created a new website with SCSS. I input the SCSS in the global style.scss as well as some in a component SCSS file. However, when I se ...

Safari causing placeholders to be sliced

I'm having trouble creating attractive placeholders in Safari. This is how it currently appears. Codepen: https://codepen.io/anon/pen/RLWrrK .form-control { height: 45px; padding: 15px; font-size: 16px; color: #8c8c8c; background-color: ...

1. "Customizing Navbar height and implementing hover color for links"2. "Tips for

Having issues adjusting the height of my Navbar - when I try to do so, the collapse button doesn't function properly. I've attempted setting the height using style="height: 60px;" and .navbar {height: 60px;} but the collapse menu stops ...

In relation to User Interface: Analyzing target tracking and studying the flow of time

Is there a way to track mouse cursor movements, button clicks, and click times to an external database using only CSS, HTML5, and Javascript? I am curious about the possibility of conducting usability studies in this manner. ...

Turn off the footer button on materialize.css modal

I'm struggling to disable one of the modal footer buttons in materialize.css. I tried using disabled="disabled", but it doesn't seem to be working. You can see my example on jsfiddle. <a class="waves-effect waves-light btn modal-trigger" href ...

a single column with a div of varying height using flexbox

I need to create a div with a height of 120px using only the CSS property display: flex. I am not allowed to use float and can only use div elements. Here is the code I have so far, but I'm unsure how to achieve the desired outcome: .flex-containe ...

I am having trouble getting the exit animation to work in Framer Animation, despite using AnimatePresence, motion.div, and a unique key

Hello and thank you for taking the time to read this! :D I'm currently facing an issue with getting Framer Motion to work properly. My code seems to be functioning well for all features except for the exit animation. I have assigned a unique key as w ...

Creating a zebra-striped list using CSS can be done by styling even and odd list items differently

I am facing an issue with Angularjs and the table tag when using group loops. The problem arises in achieving correct zebra striping for the list. How can I solve this to ensure the zebra pattern is applied correctly? <table> <tbody> <tr ...

Bootstrap - Border padding excessively wide

For a project exercise using bootstrap, I'm working on recreating a page that can be found here: https://codepen.io/freeCodeCamp/full/NNvBQW I've hit a roadblock in trying to put a border around the image. Here's the code I have so far: htt ...

Enhancing Single Cards with React and Material UI Card Expander

Currently, I am utilizing React along with Material UI to craft 3 expandable cards containing images. The setup is running smoothly as expected; the cards render and expand almost perfectly. However, there is one major issue: all the cards expand simultane ...

Caution: It is important that every child within an array or iterator is assigned a distinct "key" property

As a new developer in ReactJS, I have created a table using ReactJS on the FrontEnd, NodeJS on the BackEnd, and MySQL for the database. My goal is to retrieve data with a Select request on the table. For my frontend: class ListeClients extends Component ...

Tips for simulating redux-promise-listener Middleware and final-form

I recently configured react-redux-promise-listener using the (repository) to work with react-final-form following the author's instructions. However, I am facing difficulties when trying to mock it for testing purposes. The error message I'm enc ...

What are some ways to eliminate spacing between child and parent div elements?

I am facing an issue with a parent div that contains multiple children. I want to add spacing between the children by applying margins, but this also creates unwanted space between the parent and the children. Is there a clean solution to remove this space ...

Show or conceal advertisement based on user role

I have developed a custom Web Control that acts as a container for a mobile banner, but I want to hide it from users who are admins. So far, I've attempted the following: <mob:MobileBanner runat="server" ID="MobileBanner" Visible='<%# Not ...

Having trouble with the scrollbar appearance after updating Chrome?

I've encountered an issue with my code after the latest Chrome update. Is there a way to implement cross-browser styling for scrollbars? // Looking for Scrollbar Styling Solution const scrollbarStyle = { scrollbarColor: `${themeLayers.scrollBar[0 ...

Can you please guide me on submitting an example of signing in using Material UI?

I have successfully implemented a SignIn component by following the example provided in Material UI's documentation, which can be found here. import React from 'react'; import PropTypes from 'prop-types'; import Avatar from ' ...

Leveraging react.js through npm along with ASP.NET Web API during development

Currently, I am building a React.js front-end application that communicates with an ASP.NET Web API backend. To prevent cross-site-scripting issues, it is required to host both the front and back end on the same domain. While this setup works well under n ...

Using TypeScript with React: Specifying a type when calling a React component

How should a type be passed into a component call? Within this scenario, the render prop APICall is utilizing a type parameter named MobileSplashReturn. Although this example is functional, it seems to be causing issues with prettier, indicating that it m ...