• 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 {
    	 36%;
    	margin: 8px auto;
    }
    
    div.stretchy-wrapper {
    	 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 {
         45%;
        background: #F9D237;
        position: relative;
        display: inline-block;
        margin: 1%;
        vertical-align: top;
        box-shadow: 0 0 4px rgba(0,0,0,.3);
    }
    .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}
    
  • 相关阅读:
    Java io流 之file类(文件和文件夹)
    异常处理
    封装
    面向对象与类
    包与模块的使用
    模块
    递归函数
    迭代器
    装饰器
    函数基础2
  • 原文地址:https://www.cnblogs.com/joe-yang/p/5677316.html
Copyright © 2020-2023  润新知