CSS scale height to match width - possibly with a formfactor

前端 未结 10 1762
天涯浪人
天涯浪人 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条回答
  •  死守一世寂寞
    2020-12-04 11:32

    For this, you will need to utilise JavaScript, or rely on the somewhat supported calc() CSS expression.

    window.addEventListener("resize", function(e) {
        var mapElement = document.getElementById("map");
        mapElement.style.height = mapElement.offsetWidth * 1.72;
    });
    

    Or using CSS calc (see support here: http://caniuse.com/calc)

    #map {
        width: 100%;
        height: calc(100vw * 1.72)
    }
    

提交回复
热议问题