css - 居中筛选具有最大高度和最大宽度的图像
问题描述
我尝试为论坛之类的东西制作一个功能。人们可以使用自定义 BBcode 生成图像的缩略图,然后单击我会看到一个图像模式,其中包含具有最大高度和最大宽度的动态尺寸图像。
图像模式存在我的问题。我无法使结果正确居中到屏幕。像这样格式化时,图像水平居中但垂直贴在顶部。我能做些什么?
HTML:
<div class="wrapperDiv">
<img class="fullimage" src="$someUrl">
</div>
CSS:
.wrapperDiv {
position: fixed;
display: block;
height: 100%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 10000;
}
.fullimage {
height: 100%;
max-height: 500px;
max-width: 500px;
}
解决方案
您应该尝试使用 flex 代替,如下所示:
.wrapperDiv {
position: fixed;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.fullimage {
height: 100%;
max-height: 500px;
max-width: 500px;
}
推荐阅读
- python - 使用 beautifulsoup、请求和正则表达式的 Web 抓取程序中的语法错误
- statistics - 如何从此函数获得一致的返回类型?
- javascript - 从 HTML Canvas 捕获图像的最快方法
- java - 按标准排序的 5 个项目的分组
- java - 使用 Firestore 的 Android 加入查询
- python - 使用字典进行类型转换
- jmeter - JMeter:如何在单个线程组下为多个并发用户运行多个采样器?
- php - 在php中使用时区转换原子时间戳
- python - (Rest 框架,Django)__init__() 接受 1 个位置参数,但给出了 2 个
- sql - 在插入或删除之前检查是否存在多对多关系