Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Card (or Paper) NOT take up full width Material UI

I'm trying to create a card element that does NOT span the entire width of the container it is in.

The Example seems to be able to do it fine

enter image description here

But when I attempt to use the example code, my card stretches the whole width of the page.

https://codesandbox.io/s/074zmkx0

enter image description here

like image 758
AKrush95 Avatar asked Nov 01 '18 15:11

AKrush95


People also ask

What is the difference between paper and card in material UI?

Paper component is mostly background of an application resembles the flat, opaque texture of a sheet of paper, and an application's behavior mimics paper's ability to be re-sized, shuffled, and bound together in multiple sheets. The Card is are surfaces that display content and actions on a single topic.

How do you style paper in material UI?

To set a background color on Material UI's Paper, you simply need to apply the background-color CSS property to the root element of the Paper. Setting the styles on the root element of any Material UI component can be done in multiple ways, but the most common is to use the useStyles hook.

Why is material UI so hard?

> Material UI uses a very similar theming system. The interface of the theme itself is different, but that seems to be about it there. Material UI implements Material UI by default and this is the main reason why it's hard to customize.


2 Answers

Hi when I ran your example it also spans the entire page, but this is an easy fix. Within your Style.css you can add a css selector to change your Card component's display to be inline-block.

Style.css

    /* Card component */
    #root > div > div {
          display: inline-block;
    }
like image 115
Nathan Avatar answered Oct 28 '22 00:10

Nathan


if you want to apply the inline-block solution, a clean way is to wrap the card inside a box

<Box display="inline-block">
    <Card...
</Box>
like image 45
rejetto Avatar answered Oct 28 '22 01:10

rejetto