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>
  • 相关阅读:
    LINQ Practice
    windows下python环境安装
    kafka安装教程
    使用python连接mysql/oracle
    使用百度地图实现地图网格
    单链表反转java代码
    mysql的索引问题分析
    java中String字符串的==解析
    辗转相除法的原理
    myeclipse2014新建maven项目
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13470364.html
Copyright © 2011-2022 走看看