How to change Polymer(1.0) paper-toolbar background colour?

不问归期 提交于 2019-12-10 13:08:36

问题


Yesterday I decided to try Polymer 1.0 and I'm already facing difficulties when trying to styling the paper-toolbar.

The documentation says that the background colour can be changed by using: --paper-toolbar-background

But how can I use it on CSS?

I tried the following:

    paper-toolbar {
        --paper-toolbar-background: #e5e5e5;
    }

Also this:

    paper-toolbar {
        --paper-toolbar {
            background: #e5e5e5;
        }
    }

But neither worked. What is the correct way to do it?

Thanks.


回答1:


If you are styling it on your main page, then you have to apply styles using <style is='custom-style'>. This is to make Custom CSS Properties work.

Applying is relatively easy. paper-toolbar provides 2 custom properties and one mixin. --paper-toolbar-background is a property that changes the background color of the toolbar while --paper-toolbar-color changes its foreground color. --paper-toolbar is a mixin applied to the toolbar.

To use these properties is just the same as applying styles in your elements. As an example

<style is="custom-style">
  paper-toolbar {
    --paper-toolbar-background: #00f; /* changes the background to blue*/
    --paper-toolbar-color: #0f0; /* changes the foreground color to green */
    --paper-toolbar: {
      font-size: 40px; /* Change default font size */
    }; /* Notice the semicolon here */
  }
</style>



回答2:


I couldn't find a solution to this problem either until recently. I have two toolbars and I didn't want to change the CSS for all toolbars just the header toolbar.

To change the CSS for every toolbar, in your external css file add the following:

paper-toolbar.paper-toolbar-0 {
  background: orange;
  color: red;
}

However, that doesn't address the problem. To change a single paper toolbar based on a class like the following:

<paper-toolbar class="header">
  ...
</paper-toolbar>

The above uses the class called "header" so in my CSS I added:

paper-toolbar.header {
    background: orange;
    color: red;
}

... and it worked! Yay! That means with this you should be able to override any CSS of any of the other elements doing the same thing. This is completely untested but I think it should work like:

<elementName>.<classname> {
  ...
}

Hope this all helps!



来源:https://stackoverflow.com/questions/30556196/how-to-change-polymer1-0-paper-toolbar-background-colour

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!