css3min函数与max函数

81 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html{
            font-size: 12px;
        }
        body {
            background-color: #f3f3f3;
            display: flex;
            justify-content: center;
            align-items: center;
            /*
               vw: viewport width   视口宽度
               vh: viewport height  视口高度
               1vw = 1/100 * 视口宽度
               1vh = 1/100 * 视口高度
            */
            width:100vw;
            height:100vh;
        }
        div {
            background:white;
            /* min() 取最小值 下面的意思是最大是300px*/
            width:min(50vw,300px);
            /*max() 取最大值4vw < 1rem 就取1rem*/
            font-size: max(4vw,1rem);
            padding: 30px;
            /*它的宽度或者高度,会自动调整为,刚刚好容纳下子元素中那个长度最长(按照文字不换行时计算)的元素即可。
            参考的基准为子元素有多宽多高。*/
            height:max-content;
            line-height: 2em;
            box-shadow: 0 0 5em rgba(0,0,0,0,0.2);
        }
    </style>
</head>
<body>
    <div>
      测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本。
      测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本。
    </div>
</body>
</html>