Created
August 19, 2014 20:58
-
-
Save mishelen/41350ab7e43561dae50b to your computer and use it in GitHub Desktop.
constant aspect ratio for child in container
Создание блока с постоянным соотношением сторон, на псевдоэлементе, по существу блок нулевой высоты, высота получается за счет паддинга псевдоребенка, сам ребенок абсолютно позиционируется в этом получившемся контейнере.
По умолчанию миксина предполагает ребенком img, также считается что контейнер буд…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @mixin stretching-pos($type-pos: absolute) { | |
| left: 0;top: 0;right: 0;bottom: 0; | |
| position: $type-pos; | |
| } | |
| @mixin stretching-hw($type-pos: absolute) { | |
| height: 100%; width: 100%; | |
| position: $type-pos; | |
| } | |
| @mixin i-b($v-a:middle) { | |
| display: inline-block; | |
| vertical-align: $v-a; | |
| zoom: 1; | |
| *display: inline; | |
| } | |
| @mixin imgwrapper-aspect-ratio($width-of-parent:true,$aspect-ratio:9/16,$child: "img") { | |
| @include i-b(); | |
| @if ($width-of-parent) { | |
| width: 100%; // whatever width you want | |
| } | |
| position: relative; | |
| &:after { | |
| padding-top: percentage($aspect-ratio); | |
| display: block; | |
| content: ''; | |
| } | |
| #{$child} { | |
| @include stretching-pos($type-pos: absolute); // fill parent | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment