简体   繁体   English

将Google Maps容器的大小设置为等于md-card-content的宽度

[英]Set Google Maps container size equal to md-card-content width

How can set a Google Maps div container size equal to md-card-content width? 如何将Google Maps div容器大小设置为等于md-card-content宽度?

I have the following code but it doesn't work. 我有以下代码,但无法正常工作。

<style> #map { width: 100%; height: 100%; } </style>

<md-card flex>
    <md-card-content>
        <div layout="column">
            <md-input-container flex="100">
            <!-- ... -->
            <div id="map"></div>
        </div>
    </md-card-content>
</md-card>

I try these solutions ( link , link ) but it doesn't work for me. 我尝试了这些解决方案( linklink ),但对我而言不起作用。 I also tried What I'd want get is like this: 我也尝试过我想要得到的是这样的:

在此处输入图片说明

I don't use angular but I'd say it's because of height is not set on a parent container. 我不使用角度,但是我想说是因为未在父容器上设置高度。 From the image you've posted it seems that you want squared map. 从您发布的图像来看,您似乎想要平方的地图。 You can use the padding trick to maintain aspect ratio: 您可以使用填充技巧来保持宽高比:

 .map-container { position: relative; } .map-container:before { display: block; content: ''; padding-top: 100%; } #map { position: absolute; top: 0; bottom: 0; right: 0; left: 0; background-color: tomato; /* only for testing */ } 
 <link href="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.css" rel="stylesheet"/> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js"></script> <md-card flex> <md-card-content> <div layout="column"> <md-input-container flex="100">input</md-input-container> <!-- ... --> <div class="map-container"> <div id="map"> </div> </div> </div> </md-card-content> </md-card> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM