[英]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.