Only apply the CSS filter alpha to the parent element and not its children

I am working on implementing an alert message box using HTML and CSS.

Below is the code I have so far:


    <div class="dim" id="msg">
        <div class="dialog_wrapper">
            <div class="dialog" id="msg_value"></div>
        </div>
    </div>

CSS:


    .dim {
        height: 100%;
        width: 100%;
        position: fixed;
        left: 0;
        display: none;
        top: 0;
        z-index: 1 !important;
        background-color: black;
        filter: alpha(opacity=75); /* internet explorer */
        -khtml-opacity: 0.75;      /* khtml, old safari */
        -moz-opacity: 0.75;       /* mozilla, netscape */
        opacity: 0.75;           /* fx, safari, opera */
    }

    .dialog_wrapper { 
        opacity: 1; 
        -moz-opacity: 1; 
        -khtml-opacity: 1; 
        filter: alpha(opacity=100); 
        width: 100%; 
        top: 40%; 
        left: 0px; 
        position: absolute; 
        z-index: 5; 
        display: block;  
    }
    
    .dialog { 
        opacity: 1; 
        -moz-opacity: 1; 
        -khtml-opacity: 1; 
        filter: alpha(opacity=100); 
        width: 400px; 
        height: 10%; 
        margin: 0 auto; 
        padding: 40px; 
        background-color: #fff; 
        border: 1px solid #ccc; 
        color: #333; 
    }

The issue lies in the usage of the `filter:alpha` property for both the background and message box. I want to apply this filter only to the background and not the message box. How can I achieve this?

Thank you.

Answer №1

To create a dim effect, apply the rgba background-color to your element with the class .dim

background: rgba(0, 0, 0, 0.75);

Check out this demo on jsBin

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Include a CSS file from an external JavaScript file

Is there a way to include an external CSS file in an external JS file? I am trying to reference and load Default.css inside Common.js like the image below shows. Any suggestions are greatly appreciated! BB ...

The max-height property is not applied to a border-box div with padding

One technique we use is the percentage trick on paddings to maintain aspect ratio in a div as the user scales their window. Here's an example: .div { background: red; width: 80%; margin: 0 auto 10px; -webkit-box-sizing: border-box; ...

Is there a way to change a class on an anchor element without disrupting its functionality?

The code snippet provided includes an anchor tag with classes for "window" and "less" applied. Is there a way to eliminate the anchor tag while still keeping the classes intact in the code, ensuring that the functionality remains unchanged? ...

"Discover the magic of jQuery: Unveiling the hidden div with one simple CSS visibility change

I want to implement a functionality on my screen where the Previous button is hidden initially and only becomes visible when the user clicks the Next button. I have set the CSS property for the Previous button to hide it by default, but despite using an if ...

What is the best way to customize the CSS of the Skype contact me button?

I am struggling with customizing the Skype contact me button. The standard Skype button has a margin of 24px and vertical-align set to -30px. I have tried removing these styles but have had no success. Here is the code snippet I am working with: Skype ...

Switch from scrolling the entire page to scrolling within a single div

Whenever I click on an element on my webpage, a modal window with a fixed position appears. The issue I am facing is that when I scroll using the mouse or touch gestures on my phone or tablet, the entire page scrolls instead of just the content within the ...

What is the technique for causing this element to move in reverse?

How can I utilize JS to halt the interval and direct the alien to move backwards once it reaches 700px? I am aware that CSS can achieve this, but I prefer a strictly JS approach. I am struggling with stopping the interval as it hits the left position of 70 ...

Incorporate a class into the fixed navigation menu using fullpage.js

I am attempting to modify the behavior of a sticky menu as the user scrolls down using fullpage.js. My goal is to have the #top-wrapper behave normally when the first section/page loads, and then add a class of is-fixed as you scroll down. When scrolling ...

Modify the navbar background color in bootstrap-vuejs

As per the information provided in the documentation, the instructions for setting styles for the navigation bar are as follows: <b-navbar toggleable="lg" type="dark" variant="info"> <!-- Or --> <b-navbar toggleable="lg" type="dark" variant ...

Comparing Yii's CHtml::link() function with the use of regular <a href=''></a> HTML tags

When using elements like yii CHtml::link, what are the recommended practices? I'm working on a button that needs to include an icon, text, respond to hover events, and be wide. Are there any benefits to using CHtml instead of a regular tag that can e ...

Using percentages for sizing and margins in CSS

Looking to create a visually appealing page that always fills the entire screen? Check out this code snippet that does just that: #posts{ width:100%; height:auto; background:#666; } .entry{ float:left; margin-left: 4%; margin-top:10 ...

The element is not occupying the full width within the div container

I'm working with a div that contains some elements. My goal is to have these elements span the entire width of the container div. .container { height: 100px; width: 100px; display: flex; flex-direction: column; overflow: scroll; borde ...

What is the best way to change the size of an SVG image

I have exhausted all the methods I could find on stackoverflow and Google, but my SVG is refusing to resize. Would someone kindly shed some light on why this might be happening? <div> <svg viewBox="32 32 32 32" height="100" width="100"> ...

Create Stylish Popups and Spacious Containers with CSS

A unique pure css popup was crafted by merging and . Hovering over "John Smith" triggers the appearance of the popup. The code for this can be seen at http://codepen.io/kikibres/pen/MwEgQX. However, there are some challenges being faced. The aim is to ke ...

Using the linear-gradient method in CSS for border images

I managed to successfully create a design using the CSS properties border-image and linear-gradient. However, I am struggling to understand the syntax involved. While I grasp the concept that the series of colors defines the gradient transition, as well as ...

Tips for personalizing text and icon colors in the TableSortText element of Material-ui

My Goal: I aim to empower users with the ability to apply customized styles to my EnhancedTable component by utilizing a styles object containing properties like headCellColor, headCellBackgroundColor, bodyCellColor, bodyCellBackgroundColor, and more. The ...

What is the best way to prevent a jQuery hover event from adding a text-shadow to the CSS?

Currently, I am facing an issue with a jQuery event that triggers a text-shadow effect: $(".leftColumn").hover(function (){ $(".leftColumn h2").css("text-shadow", "0px 2px 3px rgba(0, 0, 0, 0.5)"); },function(){}); The problem arises when the text-shad ...

Tips for adjusting div content to fit a fixed height on all devices

Looking to adjust the size of the #left-content div based on the height of the window, while ensuring that all content is visible within the fixed #left-bg. However, when viewing on mobile or tablet devices, the content appears hidden. .left-bg{ backgro ...

What is the best way to include an image in a bootstrap carousel?

Can anyone help me troubleshoot my issue with fitting an image into the bootstrap carousel? I've tried adjusting the CSS, but it's not working. Any advice or suggestions would be greatly appreciated! Here is a screenshot for reference: Below is ...

Combining various types of media stylesheets with a print stylesheet

I'm struggling with a school assignment that is asking me to compare two different ways of linking a print stylesheet with another stylesheet in HTML. The assignment requires me to explain when each technique would be appropriate: <link rel="style ...