Div Square, width size based on 100% height

后端 未结 7 2167
灰色年华
灰色年华 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 15:53

    You can accomplish this using javascript. I'm assuming that you have a larger div container, in which you want a square, whose height is the same height as the container. The html is as follows:

    In javascript, you would simply do:

    
    
                                     
                  
提交回复
热议问题