How to make image responsive in Material-UI
In your image tag, you are setting the height and width to 50vh. Viewport units (vh or vw) will cause stuff to overflow out of containers if it sees fit. In your case, everything is working as intended, the image is taking up 50% of the viewport height (637/2 = 319px). It's going to overflow out of the grid container if it needs to in order to meet those dimensions.
You should likely have the image itself have width: 100% height: 100%, or width: 100% height: auto and control the size of the image via the container (like you're already doing).
Hope this helped, let me know if you have questions.
React JS + Material UI : displaying N elements inside a container of variable width
You can deal with these kinds of problems using flex-box. Here I did a simple example just using a couple of properties that should fit our description: https://codesandbox.io/s/throbbing-cdn-cbb6mx?file=/src/App.js
In this link, you can find a very nice guide about flex-box: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
How to contain images in react material ui CardMedia component
To fit image in CardMedia
, add props component="img"
like:
<CardMedia
className={classes.media}
image={brand.image.length > 0 ? brand.image : knightdemon}
title={brand.name}
component="img"
/>
This should solve your problem.
Related Topics
Bootstrap Carousel Caption Top Alignment
Padding Between Checkbox and Label
How to Use CSS Rotate() in Th Table Tags
Chrome Not Loading CSS Source Maps
Unwanted CSS Injected into Posts
How to Render a Border to a Div Without Occupying Any Extra Space
How to Draw Lines Through Bootstrap Vertical Dividers
React Js: Apply Material-Ui CSSbaseline
How Can The Pseudo Element Detect The Height of The Non-Pseudo Element
CSS Ul Li Image to Align with Text
In CSS Use "Display:None" on The Element, But Keep Its ":After"
Angular Error: Postcss Received Undefined Instead of CSS String