问题
I'm trying to use MDC Components for material design components on my application. I have a custom element in Polymer (LitElement):
_render(props) {
return html`
${SharedStyles}
<style>
.js-panel {
display: none;
}
.js-panel.is-active {
display: block;
}
</style>
<div class="mdc-toolbar">
<div class="mdc-toolbar__row">
<div class="mdc-toolbar__section mdc-toolbar__section--align-start">
<nav id="tab1" class="mdc-tab-bar mdc-tab-bar--indicator-accent js-tabs" role="tablist">
<a role="tab" aria-controls="panel-1" class="mdc-tab mdc-tab--active">Item One</a>
<a role="tab" aria-controls="panel-2" class="mdc-tab">Item Two</a>
<span class="mdc-tab-bar__indicator"></span>
</nav>
</div>
</div>
</div>
<section>
<div class="js-panels" for='tab1'>
<p class="js-panel is-active" role="tabpanel" aria-hidden="false">Item One</p>
<p class="js-panel" role="tabpanel" aria-hidden="true">Item Two</p>
</div>
</section>
`
}
I have imported from @material/tabs all the classes needs to create the component, and it actually works perfectly fine but the styles doesn't apply:
In the dist
folder we have the css file mdc.tabs.css
that has all the css for the component. I did the test copying all the file content into the style tag and it applies all the styles correctly, but I think it should be a better way to do that... My question is how can I import the css file into my webcomponent?
回答1:
You can always use the traditional approach when you render()
your html:
<link href="./mdc.tabs.css" rel="stylesheet">
来源:https://stackoverflow.com/questions/50518495/how-to-import-a-css-file-from-an-npm-module-webcomponent