css是相对谁的

相对于父级元素宽高
width, height, margin,padding, text-indent ... 等
相对于父级定位元素宽高
top, left, right, bottom
相对于自身宽高
border-radius, translate, transform-origin, zoom,background-size
相对于自身字体大小
line-height
相对于继承字体大小
font-size

demo

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .container{
      border: 1px solid #000;
      width: 600px;
      height: 600px;
    }
    .inner{
      border: 1px solid red;
      /*width: 200px;*/
      /*height: 200px;*/
      /*相对父元素*/
      width: 50%;
      height: 50%;
      /*margin-top: 50%;*/
      /*padding-top: 50%;*/
      /*text-indent: 50%;*/
      /*  相对自身*/
      /*border-radius: 10%;*/
      /*border-radius: 30px;*/

      /*translate, transform-origin, zoom,background-size*/
    }
  </style>
</head>
<body>

<div class="container">
  <div class="inner">1111</div>
</div>

</body>
</html>


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容