gpt4 book ai didi

css - 有没有办法使用变换比例使内容自动适合父 div?

转载 作者:行者123 更新时间:2023-12-05 08:06:11 24 4
gpt4 key购买 nike

考虑一下:

enter image description here

有了用于缩放内容的精确数字(transform: scale(0.62);),我们可以实现这一点:

enter image description here

是否可以在不使用精确数字的情况下实现这种缩放?内容是可变的,因此它必须适用于任何内容。

CodePen

.container {
width: 200px;
height: 200px;
background: yellow;
}

/*
.content {
transform: scale(0.62);
transform-origin: 0 0;
}
*/
<div class="container">
<div class="content">
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasda
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
sdfdsfsdfsdfdsfsdsdfdsfs
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdas
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdas
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdas
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdas
sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdas
</div>
</div>

最佳答案

这也需要 Javascript 的帮助。在Javascript中获取container div和content div的宽高。然后下面的技巧可能会有所帮助:

scale = min( 
availableWidth / contentWidth,
availableHeight / contentHeight
);

关于css - 有没有办法使用变换比例使内容自动适合父 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61895358/

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