以下示例是关于Scss中包含保持长宽比混合器用法的示例代码,想了解保持长宽比混合器的具体用法?保持长宽比混合器怎么用?保持长宽比混合器使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。
@mixin ratioParent($width, $height) {
width: 100%;
padding-top: ($height / $width) * 100%;;
position: relative;
overflow: hidden;
}
@mixin ratioChild() {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
// Example usage:
// Image in design is 300x280px
// Send those values to the mixin
.image-wrapper {
@include ratioParent(300px, 280px);
img {
@include ratioChild;
}
}
本文地址:https://www.itbaoku.cn/snippets/785403.html