javascript - CSS not applied to Polymer 2 web component in Chrome -
i have polymer v2 web component defined below. in main page include css file defines style named n-action-button
. when open main page in firefox or ie style applied web component, when same in chrome content of web component not styled.
everything working fine when application using polymer v1 library. has changed when upgraded polymer v2. i've read in docs on net externally-defined styles should applied web components. have no idea why isn't working under google chrome browser.
<link rel="import" href="../polymer/polymer-element.html"> <dom-module id="login-form"> <template> <h1> use username & password sign in. </h1> <form id="form" method="post" action="j_security_check"> <input id="username" name="j_username" type="text" placeholder="username"/> <input type="submit" id="submit" value="log in" class="n-action-button"> </form> </template> <script> class loginform extends polymer.element { static is() { return 'login-form'; } } window.customelements.define(loginform.is, loginform); </script> </dom-module>
edit: style looks this:
.n-action-button, .n-action-button:hover, .n-action-button:focus, .n-action-button:active, .n-action-button:visited, .n-action-button[disabled], .z-button.n-action-button, .z-button.n-action-button:hover, .z-button.n-action-button:focus, .z-button.n-action-button:active, .z-button.n-action-button:visited, .z-button.n-action-button[disabled] { display: inline-block; color: #fff; text-shadow: none; text-decoration: none; padding: 15px 30px; line-height: 22px; -webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px; border: 0; -webkit-transition: color .25s, background .25s; -moz-transition: color .25s, background .25s; -o-transition: color .25s, background .25s; transition: color .25s, background .25s; } .n-action-button, .n-action-button:visited, .z-button.n-action-button, .z-button.n-action-button:visited { background: #49b87b; } .n-action-button:hover, .n-action-button:focus, .n-action-button:active, .z-button.n-action-button:hover, .z-button.n-action-button:focus, .z-button.n-action-button:active { color: #fff; background: #4bbe7f; } .n-action-button[disabled], .z-button.n-action-button[disabled], .z-button.n-action-button[disabled]:hover, .z-button.n-action-button[disabled]:focus, .z-button.n-action-button[disabled]:active { color: #fff; background: #b1b1b1; }
global styles should not influence element inside shadow dom. i'm afraid approach worked before because of limitations of polyfills. polymer 2 true shadow dom , encapsulation.
so encapsulation work have expose css mixins , globally set those.
example:
<link rel="import" href="../polymer/polymer-element.html"> <dom-module id="login-form"> <template> <style> #submit { background: #49b87b; display: inline-block; color: #fff; text-shadow: none; text-decoration: none; padding: 15px 30px; line-height: 22px; -webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px; border: 0; -webkit-transition: color .25s, background .25s; -moz-transition: color .25s, background .25s; -o-transition: color .25s, background .25s; transition: color .25s, background .25s; @apply --submit; } #submit:hover, #submit:focus, #submit:active { color: #fff; background: #4bbe7f; @apply --submit-hover; } #submit[disabled], #submit[disabled]:hover, #submit[disabled]:focus, #submit[disabled]:active { color: #fff; background: #b1b1b1; @apply --submit-disabled; } </style> <h1> use username & password sign in. </h1> <form id="form" method="post" action="j_security_check"> <input id="username" name="j_username" type="text" placeholder="username"/> <input type="submit" id="submit" value="log in" class="n-action-button"> </form> </template> <script> class loginform extends polymer.element { static is() { return 'login-form'; } } window.customelements.define(loginform.is, loginform); </script> </dom-module>
so in html override values if need them. styles.html
<custom-style> <style is="custom-style"> html { --submit: { color: orange; }; --submit-hover: { color: orange; background: grey; }; --submit-disabled: { color: green; background: grey; }; } </style> </custom-style>
Comments
Post a Comment