Is there a way to do this with user CSS on Firefox?

The content has to have full opacity. So setting opacity through the compositor or the opacity CSS property does not count.

  • MrOtherGuy@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    2 days ago

    Yeah, I just figured the safest option would be to only set the actual document root element transparent - in practice I think it’s possibly more likely that the <body> element has background set by the page - although the page might as well set both. So yes, it depends on the website.

    • Quail4789@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      edit-2
      2 days ago

      I think the problem comes from !important not working as expected for me. Your html:root doesn’t work on my setup because most websites set background on body and that somehow overrides html:root despite the !important. Similarly, if I set it in the body, background or background-color set in lower levels still override my usercontent (again, despite me using !important). That’s causing the webpage to have some transparent bits but a lot of elements will have regular opaque backgrounds. Any ideas?

      PS I don’t have anything else in userContent.css or any extension that’s setting CSS rules.

      • MrOtherGuy@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        2 days ago

        I think the answer depends on which elements exactly you want to make transparent. The page is a layered structure. The html root element is behind them all. Then body element is on top of that, the rest of the elements on top of body, etc.

        So if you intend to have transparency all the way down, then you need to make sure that all the elements in that stack are transparent. If any single item in a stack has an opaque background then the transparency effect stops at that.

        As an example, if you set background:transparent to just body but not the document root element, then body will indeed be transparent, but it does not matter because the root will still be opaque. Likewise, if root is made transparent, but there is any opaque layer on top of that, then only the parts of the root element that are not covered by that opaque layer will show up as transparent. If you have a glass table and put a sheet of paper on top of it, then you don’t see through the part covered by the paper even though the table itself is transparent.

        • Quail4789@lemmy.mlOP
          link
          fedilink
          English
          arrow-up
          0
          ·
          edit-2
          2 days ago

          I want the entire background of any webpage to be transparent. Like this user had here..

          For me, inheritance doesn’t work as you described. Inner level rules don’t always inherit from outer levels (I think if an inner background-color is set equal to a variable, it doesn’t inherit it’s parent’s background). Setting root background doesn’t affect body, setting body background doesn’t effect elements further down the tree (e.g. a lemmy post will still have a background color while it’s surroundings are transparent).

          I can achieve what I want by setting the rule globally with:

          * {
          	background: transparent !important;
          	background-color: transparent !important;
          }
          

          The problem with this approach is I don’t actually want 100% transparency. I want at least above 75% to keep the content readable. However, with something like this:

          * {
          	background: #00000080 !important;
          	background-color: #00000080 !important;
          }
          

          overlapping elements’ transparency stack and create regions with different opacities all over the page.

          edit: writing this game me an idea and combining the two works:

          * {
          	background: transparent !important;
          	background-color: transparent !important;
          }
          
          body {
          	background: #00000080 !important;
          	background-color: #00000080 !important;
          }
          
          • MrOtherGuy@lemmy.world
            link
            fedilink
            arrow-up
            0
            ·
            2 days ago

            Right, background-color is not an inherited property (compared to for example color (color of text) which is). But even if it were, inheritance is not “enforced” so if website css sets a backround-color specifically for that element then the inherited value would be lost anyway.

            But the way you now describe it doesn’t seem possible. There is not syntax to apply style rule to “just the innermost element”. I think the closest would be to have everything else have fully transparent background, but the html root element have only partial transparency:

            *{
              background: transparent !important;
            }
            html:root{
              background: #00000080 !important;
            }
            

            However, you will still face a problem; many websites draw graphics or images as a background-image so if you use the background shorthand property then those graphics will be effectively removed. On the other hand, if you instead set just background-color then parts might get opaque again because a website could be drawing even opaque backgrounds as background-image instead of background-color.

            • Quail4789@lemmy.mlOP
              link
              fedilink
              English
              arrow-up
              0
              ·
              2 days ago

              You’re right about the background. That was me going catch-all while testing. I’ll set background-color only for a while and observe how that works.

              I assumed background-color would be inherited when marked !important since I haven’t seen that noted anywhere on MDN or similar.