modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.22k stars 291 forks source link

CSS example targeting html which does not exist in shadow root #459

Closed e111077 closed 4 years ago

e111077 commented 4 years ago

Heya, the example here doesn't seem to be green because it is selecting html but the example is in a shadow root. Not sure if that's intentional as the following text says it should have 'cornflowerblue' as a bg

https://github.com/modernweb-dev/web/blob/ebe2cef0657e27b69d120fe67d0dd272b3b99ef2/docs/guides/going-buildless/css.md#L59

https://modern-web.dev/guides/going-buildless/css/

daKmoR commented 4 years ago

@bennypowers we probably should check this example... maybe we can make it "simpler" and/or easier to follow 🤔

bennypowers commented 4 years ago

@e111077 correctly identified the problem: I selected for html instead of :host, being that this is all rendered in the shadow root of an <mdjs-preview>.

this css should fix it. I'll send in a PR sometime this week.

:host {
  --my-background-color: green;
  --my-font-size: 12px;
}

article p {
  --my-font-size: 24px;
  --my-background-color: cornflowerblue;
  --p-padding-horizontal: 12px;
}

p {
  display: inline-block;
  border-radius: 4px;
  padding: 4px var(--p-padding-horizontal,6px);
  background-color: var(--my-background-color);
  font-size: var(--my-font-size);
}
Screen Shot 2020-08-31 at 23 40 26