Question

I'm making a user stylesheet for the add-on 'stylish.'

It applies a semi-transparent dark box over the entire page for night-browsing.

I'm using:

html:before {
    content:url()!important;
    position:fixed!important;
    width:100%!important;
    height:100%!important; 
    top:0!important; 
    left:0!important; 
    background:rgba(2,3,3,.35)!important; 
    z-index:99999999999999999!important;
    pointer-events:none!important;
}

to create the fixed, overlying div.

This works just fine, however, if there are any iframes in the site, it will apply this code into the iframes' HTML as well as you can see here:

because these social networking widgets rely on an IFRAME, its repeating the code into those pages, creating a double-overlaying of the semi transparent dark box i've made.

the desired look would be:

I've tried hack-ish things, like applying a much-higher z-index to iframes and specifying the background-color and background of * of anything in the iframes to 'white' and 'opaque' so that it 'floats' on top of the parent html page, but this doesn't work perfectly. i've also tried something like:

html:not(iframe):before{}

but this also doesn't work. I'm wondering if there is a way to do what I'm trying to do in a way that doesn't rely on 'html:before' to create the same effect, or if there's a way to do that but not have it repeat inside the html of iframes on a page.

I've exhausted my efforts trying to get this to work, so any help would be really appreciated. Thank you.

Was it helpful?

Solution

Unfortunately, there is no way using CSS to target only the contents of an iframe from within the source of the iframe, i.e. the page that contains the iframe element.

I'm assuming, since you're using Stylish, that your CSS is in a Firefox user stylesheet. If so, you may have to look at the source URLs of those iframes, create a @-moz-document rule targeting those URLs at their domains, and remove the html:before pseudo-element accordingly.

Something like this, which should go beneath what you already have:

@-moz-document domain(/* Facebook Like */), 
    domain(/* Tweet Button */), 
    domain(/* Google +1 */)
{
    html:before
    {
        content: none !important;
    }
}

The content: none declaration disables the pseudo-element, preventing it from being rendered.

Having to exclude specific domains in this manner means this method is extremely limited and not very versatile at all, but it's the best I can think of.

OTHER TIPS

You may want to try a different route:

html {
    box-shadow: inset 0 0 0 2000px rgba(2, 3, 3, .35) !important;
}

Demo

This way the webpage is still useable when the user's browser doesn't support pointer-events.

You may also want to checkout this question: CSS - max z-index value

To apply these styles to only the parent document's <html> element, and not to iframes, simply apply the box-shadow to document.documentElement with JS:

document.documentElement.style.boxShadow = "inset 0 0 0 2000px rgba(2, 3, 3, .35) !important";

Edit:

I don't know about the addon thing but you could give your HTML tag an ID and target it that way, although if you want this to apply to all pages then that's an issue

or maybe use html:first-child ? I honestly don't know what will happen, you can give it a try though

CSS doesn't allow you to style HTML inside an iframe. Since you're using an add-on, this is a non-standard implementation of CSS. Styles are not inherited by iframes, because an iframe is basically a new browser window. The add-on is adding the style to every HTML page in the browser window. There's no way for the browser to know that a page is inside an iframe (at least not in a way that's accessible via CSS).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top