Div Square, width size based on 100% height

后端 未结 7 2146
灰色年华
灰色年华 2020-12-03 15:15

I\'m trying to make a responsive square with the width size based on the (100%) height of the element. I believe it\'s impossible using only CSS.

The square width sh

相关标签:
7条回答
  • 2020-12-03 16:05

    You could do this with a tiny inline image. No JS, no extra files.

    .container {
      height: 150px;
      width: 100%;
      text-align: center;
      background: #acd;
    }
        	
    .square {
      display: inline-block;
      height: 100%;
      background: #691;
    }
    <div class="container">
      <div class="square">
        <img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" height="100%">
      </div>
    </div>

    0 讨论(0)
提交回复
热议问题