Fuzzy backdrop with razor-sharp edges

In the process of designing a website, I am in need of a header with a blurred background that retains sharp edges. To achieve this effect, I implemented the use of ::before in my CSS code.

Current Outcome:

(For full clarity, it may be necessary to view in full-screen mode.)

https://i.sstatic.net/Zr778.jpg

The current code snippet can be accessed here: (View on CodePen)

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

header {
  width: 100%;
  min-height: 60%;
  padding: 50px 100px;
  text-align: center;
  color: white;
}

header nav ul {
  list-style: none;
}

header nav li {
  display: inline-block;
  padding: 5px;
}


/* Header background */

.header::before {
  position: absolute;
  top: 0;
  left: 0;
  z-index: -100;
  content: '';
  display: block;
  min-height: 60%;
  width: 100%;
  background: url(https://placeimg.com/1000/662/any) no-repeat fixed top;
  -webkit-filter: blur(5px) contrast(125%) brightness(75%);
          filter: blur(5px) contrast(125%) brightness(75%);
}
<header class="header">
  <nav>
    <ul>
      <li>Lorem</li>
      <li>Lorem</li>
      <li>Ipsum</li>
      <li>Ipsum</li>
      <li>Dolor</li>
    </ul>
  </nav>
  <h1>Title</h1>
  <p>Lorem ipsum dolor osit amet, consectetur adipiscing elit.</p>
</header>

Desired Look:

https://i.sstatic.net/jbzRP.jpg

I attempted to enclose the design in a container div with overflow: hidden to extend the background slightly beyond, thus hiding the blurred edges. However, this approach proved unsuccessful and I prefer not to introduce unnecessary additional containers since the primary intent was to utilize ::before. I have explored various solutions tailored for achieving sharp edges with image blurs, but they do not directly apply to background images. Could you provide guidance on how I could potentially address this issue?

Answer №1

Is there a right way to solve this problem? The blur filter has an impact on the entire element, including edges. One workaround is to hide the edges by enlarging the element compared to its container, with the parent having overflow:hidden; - Check out the demo:

* { padding: 0; margin: 0; box-sizing: border-box; }

html, body { height: 100%; }

.blurred {
  height:100%;
  width:50%;
  position: relative;
  float:left;
  margin:0 auto;
  overflow:hidden;
  border:3px solid #FFF;
  padding:1em;
  color:#FFF;
}

.blurred:before {
  background: url(https://placeimg.com/1000/662/any) no-repeat fixed top;
  background-size:cover;
  -webkit-filter: blur(5px) contrast(125%) brightness(75%);
  filter: blur(5px) contrast(125%) brightness(75%);
  content:"";
  height: 110%; width: 110%;
  display: block;
  position: absolute;
  z-index:-1;
  top:0; left:0;
}

.blurred.scaled:before {transform:scale(1.1);}
<div class="blurred scaled">
Scaled background
</div>

<div class="blurred">
Normal background
</div>

Check out the jsFiddle link for more

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

A few of the input fields I filled out are not getting sent to the PHP script

Currently, I am working on a school project that involves creating a website similar to IMDB. My task is to include comments in our database, but I am facing an issue where two fields (fid and spoiler) are not getting posted to the PHP script handling the ...

Using jQuery to iterate over a multi-dimensional array and showing the child elements for each parent array

I am facing an issue with a multidimensional array that contains objects and other arrays. While it is simple to loop through the parent array and display its contents in HTML, I encounter a problem when there are multiple layers of arrays nested within ea ...

Using Three.js to display a CSS3D-rendered DIV in full-screen mode

After extensively experimenting with the three.js library, I was able to establish two distinct scenes – one canvas-rendered and the other css3d-rendered – both displayed using the same perspective camera. Note: Despite my efforts, I am constrained to ...

Is it advisable to optimize your SEO by placing the JavaScript code at the bottom of your webpage?

Is this just an urban legend or is it actually true? I've heard that when web crawlers analyze a webpage, they have a time limit to capture all available code (like html) before moving on to the next page. If the JavaScript code is in the head sectio ...

Generating a dynamic triangle within a div while ensuring it fits perfectly with the maximum width

I need help with creating a responsive triangle on a web page that takes three inputs. The challenge is to adjust the size of the triangle so it fits inside a div element while maintaining the aspect ratio of the inputs. For instance, if the inputs are 500 ...

Creating a toggle label using just CSS: a step-by-step guide

Recently, I was trying to create a toggle label using HTML, CSS, and JavaScript. Here is the code snippet that I experimented with: function genre_itemclick(item){ if(item.classList.contains('light_blue_border_button')) { ...

Transform Array into an unordered list with list items

Currently, I am dealing with a file that contains strings of file paths in the following format: ./CatDV/S1/SFX/steam/6004_90_04 LargeHeadlightSm.wav ./CatDV/S1/SFX/steam/AirHissPressureRe HIT032001.wav ./CatDV/S1/SFX/steam/Impact_Metal_Bullet_Hit(1).wav ...

Adjusting the Scaling Value to Match the Browser's Scaling Value

I'm struggling with a problem in HTML where the initial-scale function is not working as expected. When I zoom in on certain pages, it saves the zoom level. However, when I navigate to another page and then return to the original one, the zoom level r ...

The Angular currency filter is displaying a strange blank space despite the correct syntax being used. Is there anyone who can assist me with this issue?

Hey everyone, I'm having some trouble with the currency filter in Angular. It's not working and just displaying a blank space. I'm new to learning Angular so any help would be greatly appreciated! Here is the code I'm using: <!DOCT ...

Insert Angular HTML tag into TypeScript

I am currently working on creating my own text editor, but I'm facing an issue. When I apply the bold style, all of the text becomes bold. How can I make it so that only the text I select becomes bold without affecting the rest of the text? Additional ...

Tips for making a scrollable container that allows its contents to overflow without clipping?

Currently working on implementing a horizontal card row for my website with a unique hover effect - the cards lightly rotate and raise on hover. Here is a preview: https://i.sstatic.net/eDQ59.gif To make this row responsive, I added overflow-x: auto; to e ...

vue-awesome-swiper / The button's name is synchronized, causing all other swiper elements to move in unison

<template> <swiper v-for="item in items" :key="item.id" :options="swiperOption" ref="mySwiper" @someSwiperEvent="callback"> <swiper-slide>I'm Slide 1</swiper-slide> <swiper-slide>I'm Slide 2</swiper-slid ...

Text Separation Within a Singular JSON Object

Currently, I am offering my assistance as a volunteer to develop a fast AngularJS App for a non-profit organization. Although I have successfully set up Angular, the main issue I am encountering has to do with parsing JSON data. The JSON object that I am ...

Dealing with errors in AJAX divs

Utilizing an AJAX-based script known as AJAXTwits, I've been able to seamlessly load multiple Twitter timelines for a sports team into a designated div. The standout features of this script include its ability to combine various timelines into a singl ...

"Offspring div popping up beyond the bounds of its parent div

I've been working on a project where I need to insert a div containing an image into another div. The parent div already has two other child divs set up and functioning perfectly. Here is the HTML code for the parent and child divs: <div id="conte ...

Tips for keeping your button fixed in place

I am encountering an issue where my button moves below the select dropdown list when I try to make a selection. Is there a way to keep the button in place even when the dropdown list from the select box is visible? For reference, here is the current outp ...

Retrieve data from a text file using ajax and then return the string to an HTML document

Just starting out with ajax, I have a text file containing number values For example, in ids.txt, 12345 maps to 54321 12345,54321 23456,65432 34567,76543 45678,87654 56789,98765 Here is the Html code snippet I am using <html><body> < ...

Tips for locking the position of a table header and allowing only the table body to scroll

I have designed a table with tbody consisting of 2 tr elements. One tr is used for hiding/showing data. I am trying to keep the Table header fixed while only scrolling the table body. However, as I am using angular js ng-repeat on the tbody, I am encounte ...

Creating a responsive grid division

.subcategory-main-wrapper { display: grid; grid-template-columns: repeat(4, max-content); position: absolute; width: 100%; column-gap: 4%; justify-content: center; height: 360px; @media @tabletScreens { height: 280px; } @media @ ...

Disappearing Act: The vanishing act of Bootstrap 4 navbar

Everything works perfectly on a large screen, but disappears when resizing. I haven't specified a height property for the navbar. Here's the Fiddle. I know this question has been asked many times before, but I have yet to find a solution that act ...