Maintain Aspect Ratio Mixin

Maintain Aspect Ratio Mixin

Maintain the aspect ratio of a div with CSS

RESPONSIVE ASPECT RATIOS WITH PURE CSS

How to Maintain Image Aspect Ratios in Responsive Web Design

http://www.w3.org/TR/2011/REC-CSS2-20110607/box.html#padding-properties

example code 1
/*
 * Pure CSS aspect ratio with no spacer images or js! :)
 */

body {
    width: 36%;
    margin: 8px auto;
}

div.stretchy-wrapper {
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 */
    position: relative;

    background: blue;
}

div.stretchy-wrapper > div {
    position: absolute;
    top: 0; bottom: 0; left: 0; right: 0;

    color: white;
    font-size: 24px;
    text-align: center;
}

/* Other aspect ratios to try:
 * 56.25% = 16:9
 * 75% = 4:3
 * 66.66% = 3:2
 * 62.5% = 8:5
 */
<div class="stretchy-wrapper"><div>Resize your browser</div></div>
example 2
<section class="ejemplo">
    <h1>Aspect ratios pure Css: widths rule</h1>
  <h2>Resize the window</h2>
    <div class="width ratio2-1">
        <div class="contenido">Aspect ratio 2:1</div>
    </div>
    <div class="width ratio16-9">
        <div class="contenido">Aspect ratio 16:9</div>
    </div>
    <div class="width ratio4-3">
        <div class="contenido">Aspect ratio 4:3</div>
    </div>
    <div class="width ratio1-1">
        <div class="contenido">Aspect ratio 1:1</div>
    </div>
</section>
<p><a href='http://ksesocss.blogspot.com/2013/08/aspect-ratios-css.html'>The post (es-es)</a></p>
<p>See the second part: <a href='http://codepen.io/Kseso/pen/rouEi'>when heights rule</a></p>
@import url(http://fonts.googleapis.com/css?family=Dosis:300);
* {
  margin: 0;
  padding: 0;
  border: 0 none;
  position: relative;
}
html, body {
  background: #164C88;
  font-family: Dosis;
  font-size: 1.1rem;
  line-height: 1.6;
  color: #F6FAFD;
}
body {padding: 1rem;}
.ejemplo {
  text-align: center;
}
.width {
    width: 45%;
    background: #F9D237;
    position: relative;
    display: inline-block;
    margin: 1%;
    vertical-align: top;
    box-shadow: 0 0 4px rgba(0,0,0,.3);
}
.width:before {
    content: '';
    display: block;
}
.ratio1-1:before {padding-top: 100%;}
.ratio2-1:before {padding-top: 50%;}
.ratio4-3:before {padding-top: 75%;}
.ratio16-9:before {padding-top: 56.25%;}
.contenido {    
   position: absolute;
   top: 0; left: 0; bottom: 0; right: 0;
   font-size: 1.5rem;
   color: #444;
}
a {color: #F9D237}

转载于:https://www.cnblogs.com/joe-yang/p/5677316.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值