ZBLOG

使用nextjs card 实现 cardcontent 包括 左侧一整张图片 右侧 一个表单 里面包含 单选框 输入框 复选框等

下面是使用Next.js和Material-UI实现带有图片和表单的Card组件的示例代码:

首先,安装必要的依赖:

  1. npm install next react react-dom @mui/material @emotion/react @emotion/styled

然后,创建一个新的Next.js页面文件(例如pages/index.js),并添加以下代码:

  1. import React from 'react';
  2. import Card from '@mui/material/Card';
  3. import CardContent from '@mui/material/CardContent';
  4. import { FormControl, FormControlLabel, RadioGroup, Radio, Checkbox, TextField } from '@mui/material';
  5. const IndexPage = () => {
  6. return (
  7. <Card sx={{ maxWidth: 500 }}>
  8. <CardContent>
  9. <div style={{ display: 'flex' }}>
  10. <img src="/path/to/image.jpg" alt="Image" style={{ width: '100%', height: 'auto' }} />
  11. </div>
  12. <FormControl component="fieldset">
  13. <RadioGroup aria-label="gender" name="gender1">
  14. <FormControlLabel value="female" control={<Radio />} label="Female" />
  15. <FormControlLabel value="male" control={<Radio />} label="Male" />
  16. </RadioGroup>
  17. </FormControl>
  18. <TextField label="Name" variant="outlined" fullWidth margin="normal" />
  19. <FormControlLabel control={<Checkbox />} label="Agree to Terms and Conditions" />
  20. </CardContent>
  21. </Card>
  22. );
  23. };
  24. export default IndexPage;

在上述代码中,你可以替换/path/to/image.jpg为你自己的图片路径。根据需要修改表单中的选项、标签等。

最后,在终端启动项目:

  1. npm run dev

打开浏览器访问 http://localhost:3000,你将看到带有图片和表单的Card组件。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=10531

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?