Achieving a frosted glass effect for your background without relying on a background image

I am currently working on creating a modal window in React with a blurred backdrop. My goal is to blur the backdrop content while keeping the background image clear, as there is no image behind the modal window, just content. I have explored various solutions such as frosting glass, frosting glass, and glass effect. However, all of them involve using a background image to achieve the blur effect, which is not what I want.

Here is the React component:

import React from "react";
import './index.scss';

const Modal = ({ handleClose, show, children }) => {
    return (
            <div class="modal display-block">
               <div class="modal-container">
                  <section class="modal-main">
                      <div class="row no-gutters header">
                          <div class="col">
                             <i class="fa fa-lg fa-close"></i>
                          </div>
                      </div>
                      <div class="row no-gutters content"></div>
                  </section>
               </div>
           </div>
    );
};

export default Modal;

CSS:

@import 'yelStrap/_variables.scss';

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width:100%;
    height: 100%;
}

.modal-container {
  background: inherit;
  position: absolute;
  top: 50px;
  right: 250px;
  left: 0;
  bottom: 0;
  overflow: hidden;
}

.modal-container::before{
  content: '';
  width: 100% ;
  height: 100%;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0; 
  background-color: rgba(255, 255, 255, 0.5);
  filter: blur(6px);
  -webkit-filter: blur(6px);
  -moz-filter: blur(6px);
  -o-filter: blur(6px);
  -ms-filter: blur(6px);
 }

.modal-main {
  position: relative;
  background: white;
  width: 90%;
  min-height: 352px;
  top: 10%;
  left: 0px;
  right: calc(10% / 2);
  padding: 10px;
  background-color: $white;
  border-radius: 5px;
  box-shadow: 0 0 12px 2px rgba(20, 150, 255, 0.15);
  z-index: $zindex-modal;
}

.fa-close {
  color: $water-disabled;
  cursor: pointer;
}

.display-block {
  display: block;
}

.display-none {
  display: none;
}

Adding a background image to the .modal-container::before works, but with a background color it does not!

Any assistance would be greatly appreciated, thank you.

Answer №1

Here is the solution for you. Take a look at the outcome. I recommend positioning the modal next to the content you want to blur, instead of placing it inside the content itself.

body, html {
  height: 100%;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

.bg-image {
  filter: blur(8px);
  -webkit-filter: blur(8px);
  width: 100%;
  height: 100%; 

}

.bg-text {
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0, 0.4); /* Black w/opacity/see-through */
  color: white;
  font-weight: bold;
  border: 3px solid #f1f1f1;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 80%;
  padding: 20px;
  text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>

<div class="bg-image">
asdaidnasijbadkjhvbafvjhabdf vkjhabdfvk ahjbdfkv hjbfdkv s
</div>

<div class="bg-text">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam sit dolores nam tempore dolore dicta quae fugiat assumenda, obcaecati, quibusdam. Officiis autem perspiciatis pariatur, beatae possimus, nulla nobis adipisci ipsum.</p>
</div>

</body>
</html>

Answer №2

Insert

filter: blur(1px);

Adjusting the blur pixels will enhance the background's blurriness.

Test it out on this link

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

Enhance your React/Bootstrap project with a hover effect class similar to Tailwind CSS's :hover feature

Is there a way to achieve the hover effect in React using Bootstrap similar to Tailwind's approach? I've searched online but haven't found any solutions. Appreciate any help! ...

How can I add information into a nested div element?

I encountered an issue when attempting to insert data into my block. The div structure is as follows: <div class="1"> <div class="2"> <div class="3"> <div class="4"></div> </div> ...

Is there a way to group together select values in a dropdown menu under a shared category?

If I have a dropdown menu that looks like for example: <select> <option value="1">1</option> <option value="3">3</option> <option value="2">2</option> <option value="4">4</option> </select&g ...

Displaying left and right div elements alongside each other in HTML/CSS works in Chrome, but not in Safari or Firefox

I've encountered an issue with aligning divs side by side in Firefox and Safari, although it seems to be working perfectly in Chrome. It's a bit tricky to provide all the CSS code as I have different stylesheets for mobile, normal, and print vers ...

Access data from State in React

Just starting out with React. I have a backend API that I want to send requests to using Axios. I currently have two input fields for numbers: const [input, setInput] = useState(0); const [input2, setInput2] = useState(0); <div> ...

Utilize React Redux Router to efficiently pass down props into components

In my App.js file, I have defined mapStateToProps and mapDispatchToProps function to connect the state and actions to props. For example: const mapStateToProps = (state) => { return { isPeddingHome: state.getShowsHome.isPeddingHome, data: state. ...

Currently, I am experiencing difficulties with two specific aspects of the website I am working on - the hamburger menu and the slideshow feature

I'm having trouble with the menu on my website. It's not functioning as expected - the dropdown feature isn't working, and two items are not staying in the correct position under the parent ul despite attempts to position them using CSS. Add ...

Header bar not extending across the entire width of the screen when viewed on mobile devices

View the problem screenshot hereWelcome to my first stackoverflow post, please be gentle if I make any mistakes. I'm currently working on a project for a course using Bootstrap 4. The issue I'm facing pertains to the navbar losing its full width ...

Exploring the process of retrieving outcomes from Node.js within a Knockout ObservableArray

Below is the Node.js code snippet I have: var http = require('http'); var port = process.env.port || 1337; var MovieDB = require('moviedb')('API KEY'); MovieDB.searchMovie({ query: 'Alien' }, function (err, res) { ...

Troubleshooting the "Module parse failed: Unexpected token" error: a complete guide

Upon running npm run build, an error was encountered: ERROR in ./src/client.js 7:2 Module parse failed: Unexpected token (7:2) File was processed with these loaders: * ./node_modules/jshint-loader/index.js You may need an additional loader to handle the ...

How do I incorporate a standalone checkbox in a React Material-UI table without affecting row selection upon clicking?

I would like to have a distinction between clicking on a checkbox and clicking on a row. Specifically, I want the following behavior: when I click on the checkbox, only the checkbox should be checked; and when I click on the row, only the row should be se ...

Using the onMessage event in React Native WebView does not seem to have any functionality

I'm having trouble with the onMessage listener in React Native's WebView. The website is sending a postMessage (window.postMessage("Post message from web");) but for some reason, the onMessage listener is not working properly. I can't figure ...

How to eliminate vertical spacing between rows in Bootstrap?

I am looking to eliminate the unsightly vertical spacing between the bootstrap rows displayed below: https://i.sstatic.net/dgR2z.png The code appears as follows: <div class="outerbox container-fluid vw-100"> <div class="row vw-100 justify-co ...

Unable to display routerLink within innerHTML in Angular

Within my component code, there is a field named "taggy" that contains a complete anchor tag. Initially, when I rendered it in my HTML, I only saw the contents of "taggy" displayed as text "<a href="blopp/1337">hazaa<a>". Clearly, this did not ...

The compilation process for npm start has encountered an error

Having trouble with npm start and running react-scripts start. Can anyone offer assistance? I'm attempting to integrate Swiper in my app, but encountering this error in the console. UPDATE: I've included the code snippet where Swiper is utilize ...

Tips on transforming button-controlled tab pages in Bootstrap 2 to Bootstrap 3

I am currently in the process of upgrading my website from Bootstrap 2 to Bootstrap 3, and I have encountered an issue with a specific control that consists of multiple sets of tab pages controlled by toggle buttons. Here is an example of the functional c ...

Encountering an error with the React Material-UI Datagrid after completing the app development process

I'm facing an issue now. Initially, the console was fine before building my App. However, after building it, the console is logging an error. view image here In my opinion, the cause of this error lies in the row data within the Data-grid. The consol ...

The onload event for windows does not fire

I am currently working on a project that requires the use of tabbing control with flyingbox. To achieve this, I consulted the following link: After referring to the above link, I made some modifications to my project. I am retrieving details from another ...

HTML div ID displaying incorrectly

My main div on the page has the attribute align="center", but it does not seem to align in the center. If you'd like to see the page for reference, click here. This is the CSS: #page{ background-color: #4C1B1B; width:85%; height:500px; ...

Can you remind me of the specific CSS class used for Internet Explorer in Twitter Bootstrap?

Currently utilizing Twitter Bootstrap and curious if there is a specific CSS class to designate IE browsers within the BODY or HTML tags. Interested in writing CSS specifically for all IE browsers. Aware that Bootstrap offers some CSS classes for IE brows ...