reactjs - 使用 Material UI 在 React 中溢出的网格项目中的图像

标签 reactjs grid material-ui

我的图像溢出了我的网格边界。我认为这是因为它的大小是精确的,但我不确定为什么,因为我指定图像最多只能包含 sm={6} 而它不会。代码和图片如下。

class Intro extends React.Component {
render() {
    return (
        <Grid container className="intro">

            <Grid item xs={12} sm={6}>
                <img src={IntroFood} alt="Restaurant Intro Food" className="introImg" />
            </Grid>

            <Grid item container direction="column" xs={12} sm={6} alignContent="center" justify="center">
                <Typography variant="body1">{this.props.desc} </Typography>
                <Button>Go to Menu</Button>
            </Grid>
        </Grid>

    );
}

我在 App.JS 中这样调用这段代码: P.S 这也只是一个片段,但网站上的每个组件本质上都是一个网格项目

`

  {/* Header */}
  <Grid item>
    <NavBar restaurantName="test" address="test addrr" phoneNum="test phone" />
  </Grid>

  {/* Intro */}
  <Grid item className="pad">
    <Intro desc="Hi there and welcomhis message will be repeated 100x. Hi there and welcomhis message will be repeated 100x. Hi there and welcomhis message will be repeated 100x. Hi there and welcomhis message will be repeated 100x. Hi there and welcomhis message will be repeated 100x. Hi there and welcomhis message will be repeated 100x. Hi there and welcomhis message will be repeated 100x. Hi there and welcome to this restaurant. This message will be repThis message will be repeated 100x"/>
  </Grid>

这是显示的结果 enter image description here `

最佳答案

您可能希望将图像的最大宽度设置为 100%,这样它就不会超过父级尺寸。

.introImg {
  max-width: 100%;
}

The max-width CSS property sets the maximum width of an element. It prevents the used value of the width property from becoming larger than the value specified by max-width.

来源:MDN

关于reactjs - 使用 Material UI 在 React 中溢出的网格项目中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63084438/

相关文章:

reactjs - Material-UI 和 React : Using the Fade component onScroll

reactjs - 多选轮廓 varant 属性不起作用

javascript - 如何计算列表中当前的滚动位置?

css - Susy Grid 没有得到 Grid Padding

reactjs - 如何在MUI中将anchorEl与styled()一起使用?

silverlight - WIndows Phone 中的 Grid 和 ItemsControl.ItemContainerStyle

c# - 在固定网格上拖动对象的算法

javascript - React 无法读取未定义的属性(读取 'state' )

reactjs - 在 webpack 应用程序中引用 amd 模块(arcgis)

javascript - 检查输入是否具有相同的值 React