Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit f90b956

Browse files
committed
Merge pull request #643 from Polymer/polyfill-next-selector
Update polyfill-next-selector docs for #637
2 parents 3e181dd + 56f8a0b commit f90b956

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

docs/polymer/styling.md

+23-30
Original file line numberDiff line numberDiff line change
@@ -92,44 +92,37 @@ CSS selectors to give you more control on how style rules are shimmed.
9292
### polyfill-next-selector {#at-polyfill}
9393

9494
The `polyfill-next-selector` selector is used to replace a native CSS selector with one that
95-
will work under the polyfill. For example, targeting distributed nodes using `::content` only works under native Shadow DOM. Instead, you can tell {{site.project_title}} to replace said
96-
rules with ones compatible with the polyfill.
95+
will work under the polyfill.
9796

9897
To replace native CSS style rules, place `polyfill-next-selector {}` above the
9998
selector you need to polyfill. Inside of `polyfill-next-selector`, add a
100-
`content` property. Its value should be a CSS selector that is roughly equivalent
101-
the native rule. {{site.project_title}} will use this value to shim the native selector. For example:
99+
`content` property. Its value should be a CSS selector that is roughly equivalent to
100+
the native rule. {{site.project_title}} will use this value to shim the native selector.
102101

103-
polyfill-next-selector { content: ':host .bar'; }
104-
::content .bar {
105-
color: red;
106-
}
107-
108-
polyfill-next-selector { content: ':host > .bar'; }
109-
* ::content .bar {
110-
color: blue;
111-
}
102+
For example, in earlier versions of {{site.project_title}} targeting distributed nodes using `::content` only worked under the native Shadow DOM. This is no longer the case and in polyfilled browsers the `::content` elements will be removed. Under the polyfill, the following selector:
112103

113-
polyfill-next-selector { content: '.container > *'; }
114-
::content * {
115-
border: 1px solid black;
104+
.foo ::content .bar {
105+
color: red;
116106
}
117107

118-
Under native Shadow DOM nothing changes. Under the polyfill, the native selector
119-
is replaced with the one defined in its `polyfill-next-selector` predecessor. The previous
120-
examples would be shimmed into:
108+
Becomes:
121109

122-
x-foo .bar {
110+
.foo .bar {
123111
color: red;
124112
}
125-
126-
x-foo > .bar {
127-
color: blue;
128-
}
129113

130-
x-foo .container > * {
131-
border: 1px solid black;
132-
}
114+
This means you only need `polyfill-next selector` when doing something that would not work if `::content` were removed.
115+
116+
For example: `::content > *` will not work in a polyfilled browser because `> *` is not a valid selector. This selector could be rewritten as follows:
117+
118+
::content > * { }
119+
120+
or as:
121+
122+
polyfill-next-selector { content: '> *' }
123+
::content > * { }
124+
125+
Under native Shadow DOM nothing changes. Under the polyfill, the native selector is replaced with the one defined in its `polyfill-next-selector` predecessor.
133126

134127
### polyfill-rule {#at-polyfill-rule}
135128

@@ -154,7 +147,7 @@ The previous examples become:
154147
x-foo .bar {
155148
background: red;
156149
}
157-
150+
158151
x-foo.foo .bar {
159152
background: blue;
160153
}
@@ -181,7 +174,7 @@ You should only need `polyfill-unscoped-rule` in rare cases. {{site.project_titl
181174
182175
According to CSS spec, certain @-rules like `@keyframe` and `@font-face`
183176
cannot be defined in a `<style scoped>`. Therefore, they will not work in Shadow DOM.
184-
Instead, you'll need to declare their definitions outside the element.
177+
Instead, you'll need to declare their definitions outside the element.
185178
186179
Stylesheets and `<style>` elements in an HTML import are included in the main document automatically:
187180
@@ -287,7 +280,7 @@ of the scoping behavior.
287280
Because polyfilling the styling behaviors of Shadow DOM is difficult, {{site.project_title}}
288281
has opted to favor practicality and performance over correctness. For example,
289282
the polyfill's do not protect Shadow DOM elements against document level CSS.
290-
283+
291284
When {{site.project_title}} processes element definitions, it looks for `<style>` elements
292285
and stylesheets. It removes these from the custom element's Shadow DOM `<template>`, rejiggers them according to the rules below, and appends a `<style>` element to the main document with the reformulated rules.
293286

0 commit comments

Comments
 (0)