📅  最后修改于: 2023-12-03 14:56:14.086000             🧑  作者: Mango
猫鼬填充(Martenstyn)是一种 CSS 技巧,可以用来填充选定的字段,使其比例保持不变。
.martenstyn
。.martenstyn {
position: relative;
overflow: hidden;
}
.martenstyn::before {
content: "";
display: block;
padding-top: 100%; /* 这里的值表示高度与宽度比为 1:1,可以根据需要调整 */
}
.martenstyn > * {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
<div class="martenstyn">
<img src="https://via.placeholder.com/300" alt="">
</div>
.martenstyn {
position: relative;
overflow: hidden;
}
.martenstyn::before {
content: "";
display: block;
padding-top: 100%;
}
.martenstyn > * {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
display: block;
。