gpt4 book ai didi

html - 不重叠的 CSS 缩放

转载 作者:行者123 更新时间:2023-12-04 01:14:01 27 4
gpt4 key购买 nike

我需要使用 transform scale(1.3) 来缩放中间的 div。它当然有效,但问题是在缩放后它会与相邻的 div 重叠。是否可以仅使用 CSS 来消除重叠?这是它现在的样子:

enter image description here

但是我想要这样

enter image description here

.main {
width: 100%;
height: 500px;
background-color: gray;
padding: 100px;
}

.box {
width: 100px;
height: 100px;
background-color: red;
margin: 2px;
display: inline-block;
border: 2px;
border-style: solid;
border-color: black;
}

.scaled-box {
width: 100px;
height: 100px;
-webkit-transform: scale(1.3);
-moz-transform: scale(1.3);
transform: scale(1.3);
display: inline-block;
background-color: green;
opacity: 0.7;
}
<div class="main">
<div class="box"></div>
<div class="scaled-box"></div>
<div class="box"></div>
</div>

最佳答案

.main {
width: 100%;
height: 500px;
background-color: gray;
padding: 100px;
--scale-rate:1.5; /* You can change scale from this line */
}

.box {
width: 100px;
height: 100px;
background-color: red;
display: inline-block;
border: 2px;
border-style: solid;
border-color: black;
}

.box:first-child{
margin-right: calc(((100px * var(--scale-rate)) - 100px) / 2); /* 100px is scaled-box width*/
}

.box:last-child{
margin-left: calc(((100px * var(--scale-rate)) - 100px) / 2); /* 100px is scaled-box width*/
}

.scaled-box {
width: 100px;
height: 100px;
-webkit-transform: scale(var(--scale-rate));
-moz-transform: scale(var(--scale-rate));
transform: scale(var(--scale-rate));
display: inline-block;
background-color: green;
opacity: 0.7;
}
<div class="main">
<div class="box"></div>
<div class="scaled-box"></div>
<div class="box"></div>
</div>

已编辑:

margin 率固定

关于html - 不重叠的 CSS 缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63921971/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com