zoukankan      html  css  js  c++  java
  • [CSS] Create a Responsive Unit and Container

    https://www.w3schools.com/cssref/css_units.asp

    In this lesson, we lay the foundations for creating a CSS illustration of the Egghead logo using the "tracing" technique.

    We walk through positioning an image and container whilst making them both responsively sized. We use the images' intrinsic dimensions to size our illustration using a custom unit. This custom unit is calculated from our images' intrinsic dimensions and the desired size of our illustration.

    This results in us having a responsive container for us to create our CSS illustration in that will scale with our browser window.

    *,
    *:before,
    *:after {
      box-sizing: border-box;
    }
    :root {
      --bg: #ffd500;
      --size: 50;
      --unit: calc((var(--size) / 769) * 1vmin);
    }
    
    body {
      background-color: var(--bg);
      min-height: 100vh;
    }
    /* Image height will responsive to container height, width will change accordingly to its height%*/
    img {
      opacity: 0.5;
    }
    
    .egg {
      background-color: hsla(0, 100%, 50%, 0.2);
    }
    
    img,
    .egg {
      height: calc(769 * var(--unit));
       calc(742 * var(--unit));
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
      
    <html>
      <head>
        <link rel="stylesheet" href="./index.css" />
      </head>
      <body>
        <img src='egghead.png'/>
        <div class='egg'></div>
      </body>
    </html>
  • 相关阅读:
    SQL2008安装重启失败
    UML学习笔记
    强大的wget
    记录几款不错的chrome主题
    关于nginx配置的不完全总结
    关于Mac下的SSH客户端iterm2等配置
    安装配置sock5代理
    配置DNS
    复习一些编译原理
    了解CentOS及周边
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13470364.html
Copyright © 2011-2022 走看看