html - 如何在 React 中水平对齐卡片元素(rmwc)?

标签 html css reactjs

在我的父组件中:

        {
          this.state.projectList.map(dat => <Item data = {dat}/>)
        }

在子组件Item

render() {
    return (
        <div style={{'width':'100%', 'textAlign':'center'}}>
            <Card style={{ width: '25rem', padding: '1rem', display: 'inline-block' }}>
                <CardPrimaryAction>
                    <div style={{ padding: '0 1rem 1rem 1rem' }}>
                    <Typography use="headline6" tag="h2">
                        {this.props.data.name}
                    </Typography>
                    <Typography use="body1" tag="div" theme="text-secondary-on-background">
                        {this.props.data.description}
                    </Typography>
                    </div>
                </CardPrimaryAction>
            </Card>
        </div>
    );
}

我正在使用 rmwc Card 组件来放置一些东西。

enter image description here

现在它只是像堆栈一样垂直放置所有渲染的元素。我真正想要的是图像右侧的蓝色钢笔小草图。

我试着给包装 div 'width':'100%', 'textAlign':'center'Card它本身是一个 inline-block 但它仍然是一样的。

最佳答案

在父组件中 GridList 附上您的 map 函数指定所需列的 material-ui 组件。然后将您的数据附在 GridListTile 中.如下所示,

 <div>
      <GridList cols={2} spacing={16}>
        this.state.projectList.map(dat => 
          <GridListTile item key={dat} xs={6}> 
            <Item data = {dat}/>
          <GridListTile/>
       ))}
     </GridList>
 </div>

在子组件中,移除父组件 <div>你很高兴去。 请导入必要的依赖项。

关于html - 如何在 React 中水平对齐卡片元素(rmwc)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52011290/

相关文章:

c++ - 在 Qt HTML5 应用程序中使用替代脚本语言

HTML 未正确居中

javascript - 如何处理angularjs中的css和自定义指令

html - 表头右侧的定位元素

css - 如何使用伪类在悬停时创建 mui 过渡?

javascript - 正确的 React 方式来处理父组件中仅作用于选定子组件的函数?

javascript - React.createElement : type should not be null, 未定义、 bool 值或数字。它应该是一个字符串(对于 DOM 元素)...;使用固定数据表 CDN

html - 处理浏览器缩放(缩放导致换行)

html - 100% 高度的 float 元素

Javascript 或 CSS 修复 100% <div> 在 IE11 缩放时不填满页面