Giter Site home page Giter Site logo

Comments (8)

wmertens avatar wmertens commented on June 2, 2024

Ok so the problem seems to be nested CSS not being supported by the scoped styles.

The original CSS (in a .module.css) is

ul {
  color: green;
  
  > :global(a) {
    color: red;
  }
}

During dev, the resulting CSS is

ul.⭐️d907jw-0 {
  color: green;
  
  > a {
    color: red;
  }
}

Note that this is nested CSS, and that Chrome supports this, but the scoped styles don't support it.

And in prod, it becomes

            ul.⭐️d907jw-0 {
                color: green
            }

            ul.⭐️d907jw-0>a.⭐️d907jw-0 {
                color: red
            }

Here, the nested rules are flattened, and the scoped styles correctly add the scoped classes.

So, it's a bug, but only because it should also not be red in dev mode.

To get the Link to be red, you have to do const {scopeId} = useScopedStyles$(...) and then <Link class={scopeId} />. This is the correct way to pass scopes down to Qwik Components.

from qwik.

netzpixel avatar netzpixel commented on June 2, 2024

This is in conflict with the docs: https://qwik.dev/docs/components/styles/#global-selector
The <Link class={something} /> is only for non scoped css according to the docs.
Using the ?inline parameter on the style file import changes how the file is read (I'm assuming here) and therefor I can't use it in the same way.

So what is the correct way to handle scoped css? And even better would be to know how to use scoped scss (but we can ignore that for the moment if it makes things way to complicated).

from qwik.

wmertens avatar wmertens commented on June 2, 2024

TBH I think the best way to style is using Tailwind (or UnoCSS).

And to style Qwik components it's best to use the scopeId.

But the behavior of global is a bug

from qwik.

netzpixel avatar netzpixel commented on June 2, 2024

Ok, I finally found a solution. The hint with the nested stuff was essential:

Instead of:

ul {
  color: green;
  
  > :global(a) {
    color: red;
  }
}

I have to write this:

ul {
  color: green;
}

ul  > :global(a) {
  color: red;
}

I think the qwikest way to improve the issue would be to update the docs to remove the nesting there.

But still, the bug should be fixed.

from qwik.

netzpixel avatar netzpixel commented on June 2, 2024

Ok, I think I have to revert my last comment... It worked in one scenario and doesn't in another.
It works if the global is added to an element which already is tracked. Example:

this works:

nav:global(.open) {
  display: block;
}

this doesn't:

nav :global(a) {
  display: block;
}

Reason seams to be that the first example only adds the .open via JS to an element which has a scoped class already and the second doesn't.
The first one results in something like this: nav.open.⭐️rwl3jt-0 { while the second one creates something like this: nav.⭐️rwl3jt-0 a.⭐️rwl3jt-0 { which doesn't work since the .⭐️rwl3jt-0 doesn't exist on the a tag which still comes from the Link component.

from qwik.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.