1

Как можно размыть background ?

<body>
  <div></div>
</body>

Хочу, чтобы фон страницы был размыт. Картинка задана как background-img. Как я понял, фильтры(filter css) можно накладывать только на картинки.


ps. Не нашел нужного вопроса т.к. везде спрашивали про img тег.

2 ответа 2

2

Если применить blur к body, то размыто будет все содержимое страницы.

Чтобы этого избежать, можно вынести background в новый div с position:absolute, а весь остальной контент обернуть в другой div с position:relative и z-index выше, чем у блока с фоном:

.content {
  position: relative;
  z-index: 2;
  color: #fff;
}

.bg {
  position: absolute;
  z-index: 1;
  left: -10px;
  top: -10px;
  right: -10px;
  bottom: -10px;
  filter: blur(5px);
  background: url(http://files.all-free-download.com//downloadfiles/wallpapers/1920_1080/tropical_beach_paradise_5k_17484.jpg) no-repeat center;
  background-size: cover;
}
<body>
  <div class="bg"></div>
  <div class="content">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </div>
</body>

1
  • Спасибо, так себе и представлял решение, но казалось странным.=)
    – EpicLegend
    7 сен 2017 в 12:07
0
.selector {
    filter: blur(3px);
}

http://joxi.ru/5mdMJp3hkQpgv2

Эффект размытия фона / Эффект матового стекла — CSS

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.