Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you blur the content beneath/behind a div? [duplicate]

Tags:

css

blur

I'm creating a new web design in Photoshop at the moment, but I'd like to know if it's possible to blur the content beneath a div?

I'd like to create a half transparent nav bar on my page that's fixed at the top of your screen. Everything that flows beneath/behind, I want to have blurred. For those of you that have an iDevice with iOS 7, check out Safari's header; where the page beneath the header is blurred. That's the effect what I'm looking for.

I wouldn't mind the effect not working on older browsers (IE8 etc.), which in that case will have a 0.5 opacity white background as fallback.

If this is possible, I'm really looking for the necessary code!

like image 321
Sander Schaeffer Avatar asked Mar 13 '14 19:03

Sander Schaeffer


People also ask

How do you blur content behind an element?

backdrop-filter: blur(10px); It will blur area behind the element.

Can you blur a div?

Blurring the background elements of a div can be achieved using backdrop-filter . All the elements placed under the div are going be blurred by using this.

How do you make a div blurry?

The trick is to use background-position:fixed; on html / body and the element to blur on top of it, so , both background-image lays on the same area of the window. The duplicate uses an extra element, this can be a pseudo element if you do not wish to modify HTML structure. Flex can also be used to center body.

How do I blur the background in a CSS container?

If you want to use CSS (CSS3) do this: filter: blur(5px) brightness(0.5); just set the values to whatever you want.. put all your text in the div whose class is "text" and leave the div with class "background" empty..


1 Answers

If you want to enable unblur, you cannot just add the blur CSS to the body, you need to blur each visible child one level directly under the body and then remove the CSS to unblur. The reason is because of the "Cascade" in CSS, you cannot undo the cascading of the CSS blur effect for a child of the body. Also, to blur the body's background image you need to use the pseudo element :before

//HTML  <div id="fullscreen-popup" style="position:absolute;top:50%;left:50%;">     <div class="morph-button morph-button-overlay morph-button-fixed">         <button id="user-interface" type="button">MORE INFO</button>         <!--a id="user-interface" href="javascript:void(0)">popup</a-->         <div class="morph-content">             <div>                 <div class="content-style-overlay">                     <span class="icon icon-close">Close the overlay</span>                     <h2>About Parsley</h2>                     <p>Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.</p>                     <p>Turnip greens yarrow ricebean rutabaga endive cauliflower sea lettuce kohlrabi amaranth water spinach avocado daikon napa cabbage asparagus winter purslane kale. Celery potato scallion desert raisin horseradish spinach carrot soko. Lotus root water spinach fennel kombu maize bamboo shoot green bean swiss chard seakale pumpkin onion chickpea gram corn pea. Brussels sprout coriander water chestnut gourd swiss chard wakame kohlrabi beetroot carrot watercress. Corn amaranth salsify bunya nuts nori azuki bean chickweed potato bell pepper artichoke.</p>                     <p>Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.</p>                     <p>Turnip greens yarrow ricebean rutabaga endive cauliflower sea lettuce kohlrabi amaranth water spinach avocado daikon napa cabbage asparagus winter purslane kale. Celery potato scallion desert raisin horseradish spinach carrot soko. Lotus root water spinach fennel kombu maize bamboo shoot green bean swiss chard seakale pumpkin onion chickpea gram corn pea. Brussels sprout coriander water chestnut gourd swiss chard wakame kohlrabi beetroot carrot watercress. Corn amaranth salsify bunya nuts nori azuki bean chickweed potato bell pepper artichoke.</p>                     <p>Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.</p>                     <p>Turnip greens yarrow ricebean rutabaga endive cauliflower sea lettuce kohlrabi amaranth water spinach avocado daikon napa cabbage asparagus winter purslane kale. Celery potato scallion desert raisin horseradish spinach carrot soko. Lotus root water spinach fennel kombu maize bamboo shoot green bean swiss chard seakale pumpkin onion chickpea gram corn pea. Brussels sprout coriander water chestnut gourd swiss chard wakame kohlrabi beetroot carrot watercress. Corn amaranth salsify bunya nuts nori azuki bean chickweed potato bell pepper artichoke.</p>                 </div>             </div>         </div>     </div> </div>  //CSS  /* Blur - doesn't work on IE */  .blur-on, .blur-element {     -webkit-filter: blur(10px);     -moz-filter: blur(10px);     -o-filter: blur(10px);     -ms-filter: blur(10px);     filter: blur(10px);      -webkit-transition: all 5s linear;     transition        : all 5s linear;     -moz-transition   : all 5s linear;     -webkit-transition: all 5s linear;     -o-transition     : all 5s linear; } .blur-off {     -webkit-filter: blur(0px) !important;     -moz-filter   : blur(0px) !important;     -o-filter     : blur(0px) !important;     -ms-filter    : blur(0px) !important;     filter        : blur(0px) !important; } .blur-bgimage:before {     content: "";     position: absolute;     height: 20%; width: 20%;     background-size: cover;     background: inherit;     z-index: -1;      transform: scale(5);     transform-origin: top left;     filter: blur(2px);            -moz-transform: scale(5);     -moz-transform-origin: top left;     -moz-filter: blur(2px);            -webkit-transform: scale(5);     -webkit-transform-origin: top left;     -webkit-filter: blur(2px);     -o-transform: scale(5);     -o-transform-origin: top left;     -o-filter: blur(2px);             transition        : all 5s linear;     -moz-transition   : all 5s linear;     -webkit-transition: all 5s linear;     -o-transition     : all 5s linear; }   //Javascript  function blurBehindPopup() {     if(blurredElements.length == 0) {         for(var i=0; i < document.body.children.length; i++) {             var element = document.body.children[i];             if(element.id && element.id != 'fullscreen-popup' && element.isVisible == true) {                 classie.addClass( element, 'blur-element' );                 blurredElements.push(element);             }         }     } else {         for(var i=0; i < blurredElements.length; i++) {             classie.addClass( blurredElements[i], 'blur-element' );         }     } } function unblurBehindPopup() {     for(var i=0; i < blurredElements.length; i++) {         classie.removeClass( blurredElements[i], 'blur-element' );     } } 

Full Working Example Link

like image 168
Mike Lee Avatar answered Sep 23 '22 16:09

Mike Lee