简体   繁体   English

在Polymer中,样式何时应该在模板标签内部或外部?

[英]In Polymer, when should styles be inside or outside the template tag?

In most cases, the style tag is inside the template tag for encapsulation. 在大多数情况下, style标记位于template标记内以进行封装。 This is one of the best parts of Web Components, so that's unsurprising. 这是Web组件的最佳部分之一,因此不足为奇。

However, in some cases, such as the official Polymer Elements ( https://github.com/PolymerElements/iron-a11y-announcer/blob/master/iron-a11y-announcer.html ), the style tag is outside the template tag. 但是,在某些情况下,例如官方的Polymer Elements( https://github.com/PolymerElements/iron-a11y-announcer/blob/master/iron-a11y-announcer.html ), style标签位于 template标签之外 Why is this? 为什么是这样? When should it be inside and when should it be outside? 什么时候应该在里面?什么时候应该在外面?

This was the recommended way about a year ago for a short while, but they changed the recommandation back to styles inside the <template> tag. 这是大约一年前推荐的方式,但是他们将建议更改回<template>标签内的样式。 Not all code has been updated yet and styles outside template works as well, therefore no pressure to change the code. 并非所有代码都已更新,模板外部的样式也可以使用,因此无需更改代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当选择标签中有内部模板(重复)时,Polymer 1.0会读取选择值 - Polymer 1.0 reading select value when there is an inside template(dom-repeat) in select tag 聚合物无法在重复模板中设置自定义标签的样式 - polymer could not style custom tag in repeat template 聚合物元素似乎不接受模板中的样式 - polymer elements don't seem to accept styles within a template 确定全局变量应在函数内部还是在函数外部 - Deciding when global variable should be inside the function or outside the function 仅在具有布局属性的元素内部将样式应用于自定义聚合物元素 - Styles applied to custom polymer element only inside an element with layout attribute 在Polymer元素模板中访问div - Accessing a div inside of a Polymer element template 聚合物将功能结果绑定到模板内 - polymer binding a function result inside template 标签内的jsRender模板 - jsRender template inside tag 全局变量在内部定义<script> tag. But it is overwritten when accessed outside <script> tag - Global variable is defined inside <script> tag. But it is overwritten when accessed outside <script> tag 为什么聚合物属性绑定在模板中需要标签? - Why does the polymer property binding need a tag in my template?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM