Comments (9)
Hi,
this look more a lit-html issue but i'm not sure you can use expression inside <style>, template are a dom hack to substitute values in places.
To achieve this you need to use inline style
style$=${`top: ${top}; left: ${left};`}
you can also use css custom properties
:host {
display: block;
position:absolute;
--my-top: 100px;
--my-left: 300px;
top: var(--my-top);
left: var(--my-left);
}
and
this.style.setProperty('--my-top','400px');
from lit-element.
Modifying the content of a stylesheet is bad practice, because that invalidates all the styles of that stylesheet, potentially causing unnecessary layout/paint. The most efficient way would be to use css custom properties as suggested in #74 (comment)
from lit-element.
I see the same bug on Chrome 63 on windows
from lit-element.
Thanks @eskan, I did use inline styles to work around this but I think this limitation should be documented as the big selling point is that it's just string literals and therefor something like this would be expected to work, in my opinion.
from lit-element.
@jofan here isn't only string literal it's lit-html which use string literal to build template result with "parts" and this is dom relative.
@justinfagnani may you confirm that lit-html can't be use inside <style> ?
from lit-element.
Support for style is advertised as one of the lit-html features: https://github.com/polymer/lit-html#css-compatible-syntax
from lit-element.
@blikblum i understand this as "lit html syntax is compatible with css syntax" so you can write style inside template string. (vs include expression in CSS style)
from lit-element.
Using expressions inside of the <style>
element is not supported in browsers where shadycss
is required. The shim takes <style>
element and put it in the head of the document (it adds also scope to template element and CSS selectors). It has to be done before render
method is called, so your values are placed in incorrect place.
from lit-element.
@smalluban Thanks for that explanation. Then it's promising for the future when the shim is no longer necessary.
from lit-element.
Related Issues (20)
- Typescript error on latest build HOT 1
- mixins don't work when using ESNext in tsconfig to compile HOT 1
- Error throw when accessing queryAssignedNodes getter (No version >2.4.0) HOT 1
- Support for contexts? HOT 2
- Persistance? HOT 5
- idempotent/soft customElement decorator HOT 1
- state() is shown as deprecated in LitElement 2.5 HOT 1
- Should not be necessary to copy TemplateResult
- jsdelivr/+esm: [object Object] HOT 1
- Nested components, slot and text styling HOT 1
- Git tags are not in sync with npm tags HOT 2
- No release major/minor branches available for reference. HOT 2
- Move tests and benchmarks to GitHub Actions
- Accessibility => lit-element + Google Chrome Screen Reader Extension => UI Design is Changed HOT 3
- Property does not re-render when fired from custom event HOT 4
- Add a way to know when rendering of an element, and ALL its sub-elements, is finished HOT 3
- Litelement Boolean property returns undefined in when not set HOT 6
- Forward Compatibility With Lit 2 misleading HOT 2
- Starter projects missing in getting started documentation HOT 1
- How do you get the actual click event target? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lit-element.