zoukankan      html  css  js  c++  java
  • 2020-02-25 今天学了啥?

    CSS如何实现固定宽高比

    一、元素尺寸已知,直接写宽高

    二、尺寸未知,可替换元素(img、video等),指定宽度或者高度,另一个自动计算。

    <div class="wrapper">
      <img src="./picture" alt="">
    </div>


    .wrap{
      width50vw;
    }
    img{
      width100%;
      height: auto;
    }

    三、普通元素实现固定宽高比

    使用padding-top/padding-bottom实现

    <div class="wrapper">
      <div class="box"></div>
    </div>

    .wrap{
       50vw;
    }
    .box{
       100%;
      height: 0;
      padding: 0;
      padding-bottom: 75%;
    }

    上述使用padding-bottom来撑开盒子,实现4/3的比例。但是如果box盒子要放入内容的话,可以使用绝对定位来充满盒子。

    .box{
      position: relative;
      width100%;
      height0;
      padding0;
      padding-bottom75%;
      margin50px;
      background-color: lightsalmon;
    }
    .content {
      position: absolute;
      top0;
      right0;
      bottom0;
      left0;
    }
  • 相关阅读:
    bat 笔记 一
    air 桌面应用发布后可以删除的文件
    as3 去掉字符串空白问题
    as3 air 获取文件夹下的所有文件
    egret 配置设置
    egret 精简游戏项目
    starling 第一天
    《笨办法学Python》 第2课手记
    《笨办法学Python》 第1课手记
    《笨办法学Python》 第0课手记
  • 原文地址:https://www.cnblogs.com/ylweb/p/12364435.html
Copyright © 2011-2022 走看看