css - flexbox 下的缩放转换在 Chrome 和 Firefox 中呈现不同
问题描述
我想将一个 div 居中,然后将其缩放(通过 transorm:scale)更大。
我使用 flexbox 使 div 居中。我想使用整个视图空间,所以我给 HTML 和 BODY 元素设置了 100% 的高度。
在 Firefox 中,它呈现得很好。然而,在 Chrome 中,内部 div 的缩放似乎会导致 BODY 元素溢出,并出现垂直滚动条。
如果您在 Chrome 和 Firefox 中运行以下代码段,您会注意到不同之处:垂直滚动条仅在 Chrome 中出现。我想让它在 Chrome 中看起来就像在 Firefox 中一样(没有滚动条)。
谁能帮我解决这个问题?
html {
height: 100%;
background-color: black;
}
body {
height: 100%;
display: flex;
overflow: auto;
margin: 0;
background-color: antiquewhite;
}
div {
height: 50px;
width: 50px;
margin: auto;
transform: scale(1.7);
background-color: blue;
}
<html>
<body>
<div>
</div>
</body>
</html>
解决方案
而不是 margin 考虑align-items
/justify-content
使元素居中。Chrome 似乎也扩大了导致这个问题的边距:
html {
height: 100%;
background-color: black;
}
body {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
margin: 0;
background-color: antiquewhite;
}
div.box {
height: 50px;
width: 50px;
transform: scale(1.7);
background-color: blue;
}
<div class="box">
</div>
推荐阅读
- r - if语句错字-我找不到
- python - 有人可以告诉我如何将 .text 文件放入包含数字和字符串的字典中
- javascript - 从 Azure IotHub / EventHub 获取 deviceId
- java - springboot自动忽略未知的json属性
- r - 建立一个包含 3 个变量的图表
- reactjs - 如何在 redux-toolkit 中正确使用带有元类型的 PayloadAction?
- html - 在 github 和 gist 上查看解释的 HTML,而不是 HTML 源代码
- python - Choropleth 地图未填写/悬停不工作
- python - 如何显示来自 s3 的图像?
- powershell - 搜索具有相同名称和 3 个字母扩展名的文件