【发布时间】:2019-06-05 07:11:12
【问题描述】:
我希望子元素可以缩放和居中。如果将孩子的缩放比例更改为 200%,您可以看到元素的顶部是紫色的,但您无法放大。我怎样才能解决这个问题?我认为这是因为 margin-top 低于零。
100% 缩放:
#child {
background-image: linear-gradient(red, violet, yellow, green, pink);
width:50px;
height:400px;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
zoom: 100%;
}
#parent {
background-color:blue;
width:500px;
height:500px;
position: relative;
transform: scale();
overflow: auto;
}
<div id="parent">
<div id="child"></div>
</div>
放大 200%:
#child {
background-image: linear-gradient(red, violet, yellow, green, pink);
width:50px;
height:400px;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
zoom: 200%;
}
#parent {
background-color:blue;
width:500px;
height:500px;
position: relative;
transform: scale();
overflow: auto;
}
<div id="parent">
<div id="child"></div>
</div>
【问题讨论】:
标签: html css overflow zooming margin