css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <body>
  <div class="wrapper">
    <header>
      <div class="container">
        <h1 class="logo">
          <a href="/">CSS Background Image Blur without blurry edges</a>
        </h1>
        <p>Trying to get rid of the blurry edges when using filter:blur() on a background image.</p>
      </div><!--.container-->
    </header>

    <main>
      <article class="container">
        <p>
          Using <code>filter: blur(2px)</code> on a background image that is set to be the cover image of the whole page, can result in ugly edges. 
        </p>
        <p>I tried to get rid of them with various techniques.</p>

        <h2>Negative absolute positioning</h2>
        <p>The parent wrapper has <code>overflow: hidden</code> so anything inside it even when over <code>100%</code> should not make the viewport wider.</p>
        <p>Using negative <code>top|bottom|left|right: -1%</code> values and increased the <code>width|height: 102%</code> moved the background image to the right position. But the blurry edges still were there. Damn.</p>
        
        <h2>Negative margin</h2>
        <p>Setting a negative <code>margin: -2%</code> had no effect either.</p>
        
        <h2>Clipping the image</h2>
        <p>Some people did suggest using <code>clip:rect()</code>. What does work when using an <code>img</code> with known dimensions. But unfortunately <code>clip:rect()</code> does not support percentage values, which we would need to crop a full size background image with unknown width/height.</p>
        
        <h2>Solution</h2>
        <p>Enough talking about what didn't work - here is what did:</p>
        <p>Simply scaling the background image to <code>110%</code> by using <code>transform: scale(1.1)</code> makes the background image heigher and wider. Blurry edges gone. Perfect.</p>
        
        <p><strong>But don't forget the vendor prefixes for <code>transform: scale</code></strong></p>
        
      </article>
    </main>
    
  </div><!--.wrapper-->
</body>
            
          
!
            
              @import url(//fonts.googleapis.com/css?family=Open+Sans:400,700,800,300);

$color-primary: #34495E;
$color-black: #333;
$color-grey: #ECF0F1;


*,*:before,*:after{
  box-sizing: border-box;
}

// .group is the new clearfix
.group:after {
  content: "";
  display: table;
  clear: both;
}

html{
  position: absolute;
  z-index: 1;
  height: 100%;
  width: 100%;
  overflow: hidden;
  
  &:before{
    content: '';
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: #fff url('http://newevolutiondesigns.com/images/freebies/city-wallpaper-11.jpg') center center fixed no-repeat;
    background-size: cover;
    filter: blur(2px);
    // this does the trick
    transform: scale(1.1);
  }
}

body{
  position: relative;
  overflow: auto; // needed because html has overflow: hidden
  margin: 0 auto;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #E2E2E2;
  color: #333;
  font-size: 100%;
  font-family: 'Open Sans','Helvetica Neue',Helvetica, sans-serif;
  line-height: 1.45;
}

a{
  text-decoration: none;
  color: $color-primary;
  transition: all 150ms ease-in-out;

  &:hover{
    color: darken($color-primary,8%);
  }
}

header{
  margin: 0;
  padding: 1rem 0;
  background: rgba($color-primary,.8);
  
  .logo{
    display: block;
    margin: 0 1rem;
    padding: 0;
    text-align: center;
    
    a{
      display: block;
      font-size: 1.3rem;
      color: #fff;
    }
  }
  p{
    display: block;
    margin: 0;
    padding: 0;
    text-align: center;
    font-size: 0.9rem;
    color: #ccc;
  }
}

.container{
  display: block;
  position: relative;
  margin: 0 auto;
  width: 90%;
  max-width: 900px;
}

main{
  margin: 3rem 0;
  padding: 0;
}
article{
  border-radius: 2px;
  background: rgba($color-grey,.9);
  padding: .5rem 1.5rem;
  
  
  h2{
    font-size: 1.1rem;
    letter-spacing: -1px;
    margin: 1rem 0;
    padding: 0;
  }
  
  p{
    padding: 0;
    margin: 1rem 0;
  }
  
  code{
    display: inline-block;
    font-size: .8em;
    font-weight: normal;
    background: rgba($color-primary,.2);

    border-radius: 3px;
    padding: 2px 3px 1px;
  }
}

h1,h2,h3,h4,h5,h6{
  margin: 0;
  padding: 0;
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console