CSS-only square div fitting inside rectangle div

前端 未结 4 633
忘掉有多难
忘掉有多难 2021-01-06 02:54

I have determined how to set a div height based on its width (using percentage width and padding-bottom). But I also need to be able to set a div width based on its height.

4条回答
  •  温柔的废话
    2021-01-06 03:06

    If you can use min and the parent is your rect then you could do this:

    .rectangle {
      width: 100vw;
      height: 100vh;
    }
    
    .square {
      width: min(80vw, 80vh);
      height: min(80vw, 80vh);
    }
    

提交回复
热议问题