CSS scale height to match width - possibly with a formfactor

前端 未结 10 1779
天涯浪人
天涯浪人 2020-12-04 11:28

I have implemented a GoogleMapsV3 map in a twitterBootstrap basic responsive design site.

But my question is quite simple: i have:

10条回答
  •  猫巷女王i
    2020-12-04 11:55

    Let me describe the JS solution as a separate answer:

    function handleResize()
    {
      var mapElement = document.getElementById("map");
      mapElement.style.height = (mapElement.offsetWidth * 1.72) + "px";
    }
    
    
    ...

    (or register the event listener dynamically).

    mapElement.style.width * 1.72 will not work, since it requires that the width be set explicitly on the element, either using the width DOM attribute or in the inline style's width CSS property.

提交回复
热议问题