A paragraph with normal opacity inside a gray div

I make a web page when a user does not have access to it. To do this, I place a div with a white background color and reduced opacity on top of the web page. I want to write some words in this div with words having normal opacity.

Currently sustained background is displayed correctly. However, I do not see the words being regular opacity. The resulting styles in Firebug show the opacity of the words as normal, but this is clearly not the case.

What am I doing wrong?

HTML:

<div class="noPermission">
    <p>I'm sorry. You do not have permission to access this page.</p>
</div>

CSS:

div.noPermission {
    background-color: white;
        filter:alpha(opacity=50); /* IE */
        opacity: 0.5; /* Safari, Opera */
        -moz-opacity:0.50; /* FireFox */
        z-index: 20;
        height: 100%;
        width: 100%;
    background-repeat:no-repeat;
        background-position:center;
        position:absolute;
        top: 0px;
        left: 0px;
}

div.noPermission p{
    color: black;
    margin: 300px auto auto 50px;
    text-align: left;
    font-weight: bold;
    font-size: 18px;
    display: block;
    width: 250px;
}
+3
source share
5 answers

I would handle this with two folded divs. The lower part consists only of color and opacity, while the upper part has text with a transparent background.

+1

jQuery, BlockUI

+1

Try something else like this:

<div class="noPermission">
    <div class="noPermission">
        &nbsp;
    </div>
    <p>I'm sorry. You do not have permission to access this page.</p>
</div>

... and

div.noPermission div.noPermission {
    background-color: white;
    filter:alpha(opacity=50); /* IE */
    opacity: 0.5; /* Safari, Opera */
    -moz-opacity:0.50; /* FireFox */
    z-index: 20;
    height: 100%;
    width: 100%;
    background-repeat:no-repeat;
    background-position:center;
    position:absolute;
    top: 0px;
    left: 0px;
}

div.noPermission p {
    color: black;
    margin: 300px auto auto 50px;
    text-align: left;
    font-weight: bold;
    font-size: 18px;
    display: block;
    width: 250px;
    position:absolute;
    z-index:30;
    top: 0px;
    left: 0px;
}
+1
source

Use the rgba value in the background to affect its opacity without changing the main foreground fonts, for example:

div.noPermission { background-color: rgba(255, 255, 255, 0.5); }

As with many recent CSS enhancements, this will not work in older browsers, but as long as this is not critical, this should not be a concern.

+1
source

Just create 1px x 1px 50% white png with transparency and use this as a div background image. Simples!

0
source

Source: https://habr.com/ru/post/1749089/


All Articles