08.固定宽高比 & 图片加载失败时的回退方案 & 隐藏滚动条

### 固定宽高比

确保具有可变 width 的元素将保持与其 `height 成比例的值。

  • ::before 伪元素上应用 padding-top,使元素的 height 等于其 width 的百分比。
  • heightwidth 的比例可以根据需要进行调整。例如,padding-top100% 将创建一个响应式正方形(1:1 比例)。
<body>
  <div class="constant-width-to-height-ratio"></div>

  <style>
    .constant-width-to-height-ratio {
      background: #9C27B0;
      width: 50%;
    }

    .constant-width-to-height-ratio::before {
      content: '';
      padding-top: 100%;
      float: left;
    }

    .constant-width-to-height-ratio::after {
      content: '';
      display: block;
      clear: both;
    }
  </style>
</body>

在这里插入图片描述

相关推荐

  1. css隐藏溢出隐藏滚动

    2024-07-21 01:58:03       27 阅读
  2. 安卓Glide失败点击按钮重新图片

    2024-07-21 01:58:03       27 阅读
  3. 如何隐藏一个元素滚动

    2024-07-21 01:58:03       22 阅读
  4. CSS设置元素

    2024-07-21 01:58:03       34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-21 01:58:03       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-21 01:58:03       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-21 01:58:03       45 阅读
  4. Python语言-面向对象

    2024-07-21 01:58:03       55 阅读

热门阅读

  1. PHP项目开发流程概述

    2024-07-21 01:58:03       16 阅读
  2. Go知识点记录

    2024-07-21 01:58:03       19 阅读
  3. DAY05 CSS

    DAY05 CSS

    2024-07-21 01:58:03      17 阅读
  4. MacOS命令行运行fortran程序|编程私教解答

    2024-07-21 01:58:03       18 阅读
  5. 类与对象-多态-案例3-电脑组装具体实现

    2024-07-21 01:58:03       18 阅读
  6. OpenPyXL 写入 Excel 文件

    2024-07-21 01:58:03       15 阅读
  7. 量化机器人如何实现无缝交易?

    2024-07-21 01:58:03       17 阅读