【问题标题】:How to use an External Stylesheet in Polymer 2.0如何在 Polymer 2.0 中使用外部样式表
【发布时间】:2018-05-23 03:10:41
【问题描述】:

我是新手,所以请放轻松...

我正在尝试使用外部样式表设置 Polymer 2.0 自定义元素的样式,但是我无法将外部样式表应用于该元素。

这是我要设置样式的元素(web-app.html):

<link rel="import" href="../elements/Styles/style-web-app.html">

<dom-module id="web-app">
<template>
<div id="header-container" class="header-container">
<div id="logo">
<img id="Mono" class="logo" src="../img/mono_primary_white_RGB.png" 
height="75px" width="75px" />
</div>
<div id="header">
<h1 id="title">ICR</h1>
</div>
</div>
<div id="tabs">
<paper-tabs selected="{{selected}}">
<paper-tab name="Name">Name</paper-tab>
<paper-tab name="Type">Type</paper-tab>
<paper-tab name="Usages">Usages</paper-tab>
</paper-tabs>
</div>
</template>

这是外部样式表代码(style-web-app.html):

<dom-module id="style-web-app">
<template>
<style>
:host{
#title {
font-size: 30px;
/* text-align: center; */
width: 500px;
color: #FFFFFF;
}
#header-container, #tabs {
background-color: #01579B;
display: flex;
color: #FFFFFF;
}
#header {
display: inline-block;
}
}
</style>
</template>
</dom-module>

谁能告诉我哪里出错了?

TIA

【问题讨论】:

    标签: css polymer-2.x


    【解决方案1】:

    这是一个直接取自 Polymer 2.0 文档的伪示例。
    创建要共享的样式表后,您可以将其导入要添加该样式的元素中,并使用&lt;style&gt; 中的include 应用它们-

    <!-- Create Your external Style document -->
    <dom-module id="my-style-module">
      <template>
        <style>
          p {
           color: red;
          }
          <!-- rest of styles to share go here! -->
        </style>
      </template>
    </dom-module>
    
    
    <!-- import custom-style -->
    <link rel="import" href="/bower_components/polymer/lib/elements/custom-style.html">
    <link rel="import" href="my-style-module.html">
    <dom-module>
     <template>
       <style include="my-style-module">
         <!-- custom element style go here! -->
       </style>
    
      <p>Paragraph A: I am in the main DOM. I am red.</p>
     </template>
    
     <script>
      //Your custom element script
     </script>
    </dom-module>
    

    因此,在您的示例中,您必须更新 web-app.html 以包含来自 style-web-app 的样式 -

    <style include="style-web-app">
             <!-- custom element style go here! -->
    </style>
    

    您可以进一步阅读自定义样式和外部样式表here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-25
      • 1970-01-01
      • 2017-12-03
      • 2013-11-24
      • 2017-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多