面试题 纯CSS实现一个自适应的正方形

要求:

  1. 正方形;
  2. 宽度或高度有一个是100%;
  3. 自适应;

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Recttitle>
head>

<body>
    <style>
        .rect {
            /* width: 100%; */
            max-width: 100vh;
            /* height: 100%; */
            max-height: 100vw;
            background: yellowgreen;
            margin: auto;
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
        }
    style>

    <div class="rect">div>
body>

html>

你可能感兴趣的:(前端CSS)