Div Square, width size based on 100% height

后端 未结 7 2174
灰色年华
灰色年华 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:01

    Since a square has same width and the height, and you know the width of the square, you can apply the same value to height.

    If you can use JS, then please try this: (jQuery)

    var wiDth = $('div').css('width'); // get width
    $('div').css('height', wiDth); // apply that value to the height
    

    Try it here: http://jsfiddle.net/afzaal_ahmad_zeeshan/vpGUK/

提交回复
热议问题