Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to blur only background and not content in Ionic/CSS

I am trying to have a blurred background for my content.

So far I tried this:

.background-image {
  background-image: url('../img/background/image.jpg');
  width: 100vw;
  height: 100vh;

  -webkit-filter: blur(10px);
  -moz-filter: blur(10px);
  -o-filter: blur(10px);
  -ms-filter: blur(10px);
  filter: blur(10px);
}

and then

<ion-view class="background-image">
   // header, content, footer etc
<ion-view>

But then I get the problem that the whole screen is blurred and not only the background as follows:

enter image description here

like image 837
JohnAndrews Avatar asked Jun 25 '15 13:06

JohnAndrews


People also ask

How do you blur only the background and not the text in CSS?

The backdrop-filter property in CSS is used to apply filter effects ( grayscale , contrast , blur , etc) to the background/backdrop of an element. The backdrop-filter has the same effect as the filter property, except the filter effects are applied only to the background and instead of to the element's content.

How do you blur the background in ionic?

To achieve this in Ionic 1, you need to set the main div's class (that is displayed in the background of your popup) to use the blur css class .

How do I blur the background only image in CSS?

Syntax. filter: blur(px); To apply a blur effect to the background image, with the blur function use the z-index property to set the stack order of the element, set the width and height 100% to have a full background image.


3 Answers

put content out side the blurred div.

.background-image {
  background-image: url('../img/background/image.jpg');
  width: 100vw;
  height: 100vh;

  -webkit-filter: blur(10px);
  -moz-filter: blur(10px);
  -o-filter: blur(10px);
  -ms-filter: blur(10px);
  filter: blur(10px);
}

<div class="background-image"></div>

<div>Content</div>
like image 161
Karan Bhutwala Avatar answered Sep 22 '22 14:09

Karan Bhutwala


there is an other way come to my head which is add second background-image, which in css3 you can have multi background for one element, and the second one can be a blur image, even with low quality , like this

in sass

#element
 background:
  image: url(/*first url*/), url(/*second url*/)
  size: auto auto /*first one*/, 100% 100% /* second one*/

i guess second will cover first or revers , you can try it out

like image 41
Taurus Avatar answered Sep 21 '22 14:09

Taurus


Put the image outside the other div... Like this:

<div class="background-image"></div>

<div class="content">
<p>Here goes your content</p>
</div>
like image 21
Matthijs Otterloo Avatar answered Sep 22 '22 14:09

Matthijs Otterloo