CSS3 blur filter on HTML body tag

橙三吉。 提交于 2019-12-12 01:38:26

问题


Is it possible to have a background image on the Bodytag, and then add blur filter on it, whitout getting the blur effect on the div's thats inside the body ?

Or do U need to add it on the first div inside the body as I can see many ex. on ?


回答1:


Using CSS filters, all child elements of the element being blurred will also be blurred. However, rather than clutter your markup with an extra div just for the sake of a bg image with blur, you can use a pseudo element.

Don't forget to give it a z-index below the other content. In this case I just used -1, but you could use any number and give the other elements another number higher.

CSS

body:before {
  content: '';
  z-index: -1;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  -webkit-filter: blur(10px);
  background: url(http://hackingui.com/wp-content/uploads/2014/05/meng2-1980x1000.jpg) no-repeat;
  background-size: cover;
}

Check it out on codepen



来源:https://stackoverflow.com/questions/23871333/css3-blur-filter-on-html-body-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!