Angular 6 - How to apply external css stylesheet (leaflet) at component level?

前端 未结 2 1387
[愿得一人]
[愿得一人] 2021-02-19 18:24

Trying to use Leaflet in an Angular 6 component. Depending on how the css file is linked, the map shows ok or is messed up, there are missing tiles not in the right order, which

相关标签:
2条回答
  • 2021-02-19 18:48

    Doing this

    @import url("path")
    

    ex:

    @import url("https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css")
    

    or doig also

    @import "bootstrap/dist/css/bootstrap.min.css"
    
    0 讨论(0)
  • 2021-02-19 19:06

    Ok, here's what worked (thanks @Palsri, I read once more the blog post and the Angular styling guidelines and tried the following, which worked):

    In a separate css file, import the leaflet css:

    // map.component.css
    @import url("../assets/lib/leaflet/leaflet.css");
    
    .mapstyle {
        width: 100%;
        height:100%;
    };
    

    Then in the component, reference this css instead of the leaflet css as follows:

    @Component({
        templateUrl: "./map.component.html",
        selector: "app-map",
        styleUrls: ["./map.component.css"],
        encapsulation: ViewEncapsulation.None
    })
    

    Here's the code in the html template:

    <div id="map" class="mapstyle"></div>
    

    One more thing: for the height % to work, you need to define the parents size, which I currently did in the index.html as follows:

    <style>
    html, body {
        min-height: 100% !important;
        height:     100%;
        padding: 0px 0px 0px 0px;
        margin:  0px 0px 0px 0px;
    }
    </style>
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题