reactjs - 在卡片中制作图像填充空间
问题描述
我正在使用 react 和 reactstrap 制作网站,我有一张包含图像的卡片,卡片是正方形,图像是矩形,我希望图像以与要填充的图像相同的方式填充卡片屏幕的背景(裁剪边缘以适应,从而避免图像被拉伸)。
我尝试在高度为 100% 时将宽度设置为自动,但图像最终只会比正常尺寸小,但会从卡中溢出,而不是居中。
<Row ClassName="posts">
<Col>
<Card style={{ height:"460px", width:"460px"}}>
<a href="#"><img className="img-fluid" src={media_picture} width="auto" height="100%"/></a>
</Card>
</Col>
<Col>
<Card style={{ height:"460px", width:"460px"}}>
<a href="#"><img className="img-fluid" src={media_picture} width="auto" height="100%"/></a>
</Card>
</Col>
</Row>
我希望生成的图像包含在卡片中,居中并像背景图像一样填充。
解决方案
您可能会受益于将NPMJS 中的 Bootstrap添加到您的项目中。然后,您可以使用文档中的基本样式。
您所要做的就是添加className="img-fluid"
到您img
的
<Row ClassName="posts">
<Col>
<Card style={{ height:"460px", width:"460px"}}>
<a href="#"><img className="img-fluid" src={media_picture} width="auto" height="100%"/></a>
</Card>
</Col>
<Col>
<Card style={{ height:"460px", width:"460px"}}>
<a href="#"><img className="img-fluid" src={media_picture} width="auto" height="100%"/></a>
</Card>
</Col>
</Row>
推荐阅读
- alexa - 如何在 Alexa 中建立 HTML5 技能
- javascript - 将对象数组传递给另一个组件是未定义的 - React & Redux
- java - android设备重启时ImageView不保留图像
- ckeditor - DJANGO-CMS PlaholderFields CKEDITOR TEXT_HTML_SANITIZE
- python - Chrome 驱动程序 - Selenium
- reactjs - POST 方法在 POSTMAN 中工作,但显示来自前端的错误
- cookies - OIDC js 库响应 cookie 未存储且未附加用于后续请求
- ios - 如何对齐自定义 UITableViewCells 中的标签?
- python - Python:正则表达式从遵循特定模式的文件名中提取字符串
- reactjs - TypeScript 可区分联合不会为不存在的字段提供错误