reactjs - 材质 UI 对话框,适合对话框高度内的图像
问题描述
我有一个 Material UI 对话框,它将显示一堆图像,图像具有风景或肖像纵横比。他们也可能有不同的分辨率。我想找到一个优雅的解决方案来保持对话框的高度为屏幕的 80%。
但是将整个图像放入对话框中,无需滚动,这是一个SandboxExample。
或者找到下面的片段:
<div>
<Button variant="outlined" color="primary" onClick={handleClickOpen}>
Open dialog
</Button>
<Dialog
open={open}
onClose={handleClose}
hasCloseButton
style={{ maxWidth: "100%", maxHeight: "100%" }}
>
<img
style={{ maxWidth: "100%", height: 'auto' }}
src="https://images.unsplash.com/photo-1565992441121-4367c2967103"
alt="image"
/>
</Dialog>
</div>
解决方案
你不能将图像高度设置为包含它的元素的 100% 吗?
在你的沙箱上我做了这个:style={{ width: 'auto', height: '100%' }}
它似乎工作。
这是完整的代码:
<div>
<Button variant="outlined" color="primary" onClick={handleClickOpen}>
Open dialog
</Button>
<Dialog
open={open}
onClose={handleClose}
hasCloseButton
style={{ maxWidth: "100%", maxHeight: "100%" }}
>
<img
style={{ width: 'auto', height: '100%' }}
src="https://images.unsplash.com/photo-1565992441121-4367c2967103"
alt="image"
/>
</Dialog>
</div>
推荐阅读
- rally - Rally 自定义字段更改反映其他字段
- android - Android R8 ArrayIndexOutOfBoundsException
- ios - 如何使用 RxSwift 模拟 tableView 行选择
- ios - FACEBOOK 登录:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序
- php - 使用 csv 在列中设置数据
- npm - 如何在 NPM 脚本中使用 Windows 控制台“设置”变量?
- asp.net - 我们使用 SQL Server 2008 在 vs 2010 中开发了 asp.net mvc 3 Web 应用程序
- c# - 在 PKCS7 (CMS) 中使用相同的响应 xml 签名签署多个位置
- c# - 如何配置 NSubstitute 不调用内部虚拟方法
- html - 里面的进度元素html文本