cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <main>

<h1>Stamp vignette hover effect <span>(no JavaScript)</span></h1>

<p>
  Concentrates user focus on the central area.<br>
  Each image has individual values set in the HTML, which works wonderfully in production.
</p>

<section class=imgChange>
  <button value="var(--image0)">Images off</button>
  <button value="var(--image1)">Image 1</button>
  <button value="var(--image2)">Image 2</button>
  <button value="var(--image3)">Image 3</button>
  <button value="url(https://www.tesco.com/food-love-stories/2018/stories/1802-jimmys-steak-for-two/i/bg-stories.jpg)">Image 4</button>
</section>

<section class=stamps>

  <article>
    <a class=stamp_link href>

      <div class=img_container data-vignetteOpacity=1>
        <div class=stamp_img-bg1 data-imgBrightness=125%></div>
      </div>

      <div class=stamp_copy data-matchHeights=copy>
        <p>
          This stamp uses the most extreme values.
          <br>Darkest vignette (1) with the brightest (125%) hover state.
          <br>In practice, use more subtle values.
        </p>
      </div>
      
    </a>
  </article>


  <article>
    <a class=stamp_link href>

      <div class=img_container data-vignetteOpacity=0.75>
        <div class=stamp_img-bg7 data-imgBrightness=120%></div>
      </div>

      <div class=stamp_copy data-matchHeights=copy>
        <p>Vignette opacity (0.75) with the brightness (120%)</p>
      </div>

    </a>
  </article>


  <article>
    <a class=stamp_link href>

      <div class=img_container data-vignetteOpacity=0.5>
        <div class=stamp_img-bg6 data-imgBrightness=115%></div>
      </div>

      <div class=stamp_copy data-matchHeights=copy>
        <p>Vignette opacity (0.5) with the brightness (115%)</p>
      </div>

    </a>
  </article>


  <article>
    <a class=stamp_link href>

      <div class=img_container data-vignetteOpacity=0.25>
        <div class=stamp_img-bg5 data-imgBrightness=110%></div>
      </div>

      <div class=stamp_copy data-matchHeights=copy>
        <p>Vignette opacity (.25) with the brightness (110%)</p>
      </div>

    </a>
  </article>


  <article>
    <a class=stamp_link href>

      <div class=img_container data-vignetteOpacity=0.125>
        <div class=stamp_img-bg5 data-imgBrightness=105%></div>
      </div>

      <div class=stamp_copy data-matchHeights=copy>
        <p>Minimal values, try it with Image 3.<br>Vignette opacity (.125) with the brightness (105%).</p>
      </div>

    </a>
  </article>


  <article>
    <a class=stamp_link href>

      <div class=img_container data-vignetteOpacity=0>
        <div class=stamp_img-bg5 data-imgBrightness=100%></div>
      </div>

      <div class=stamp_copy data-matchHeights=copy>
        <p>Without effects</p>
      </div>

    </a>
  </article>

    </a>
  </article>

</section>

<p><a href="https://codepen.io/2kool2/pen/XZZJPP" target=_blank title="[new window]">Stamp vignette generator</a></p>

</main>



[[[https://codepen.io/2kool2/pen/mKeeGM]]]
            
          
!
            
              body {
  font-family: sans-serif;
  line-height: 1.5;
  text-align: center;
  margin: 1rem 0 2rem;
  padding-bottom: 2rem;
  color: hsl(269,19%,30%);
  background-color: hsla(32,100%,85%,.35);
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg width='100%25' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.4'/%3E%3C/filter%3E%3C/defs%3E%3C!-- %3Cpath filter='url(%23a)' opacity='.3' d='M0 0h1200v256H0z'/%3E--%3E%3Crect filter='url(%23a)' opacity='.3' width='100%25' height='100%25'/%3E%3C/svg%3E");
}
h1,h2 {
  font-weight: 100;
  margin: 2rem 1rem 1rem;
}
h1 span {font-size:smaller}
p {margin: 1rem}


/* Grid definitions - 1,2,3,6 */
.stamps {
  --spacing: .75rem;
  --columns: 1;
  padding: 0 var(--spacing);
  display: grid;
  grid-gap: var(--spacing);
  grid-template-columns: var(--columns);
}
@media (min-width: 40em) { /* 640px */
  .stamps {
    --spacing: 1rem;
    --columns: 1fr 1fr;
  }
}
@media (min-width: 60em) { /* 960px */
  .stamps {
    --columns: 1fr 1fr 1fr;
  }
}
@media (min-width: 80em) { /* 1280px */
  .stamps {
/*     --columns: 1fr 1fr 1fr 1fr; */
  }
}
@media (min-width: 120em) { /* 1920px */
  .stamps {
    --columns: 1fr 1fr 1fr 1fr 1fr 1fr;
  }
}



main {
  --image0: none;
  --image1: url(https://websemantics.uk/portfolio/2018/food-love-stories/i/iain/bg-stories.jpg);
  --image2: url(https://websemantics.uk/portfolio/2018/food-love-stories/i/al/bg-stories.jpg);
  --image3: url(https://www.tesco.com/mothers-day/2018/i/gifts/s2.jpg);

  --image: var(--image1);
}
section {
  margin: 1rem 0;
}
button {
  font: inherit;
  margin: 0 0.375rem;
}
button:focus {
  background-color: hsl(269,19%,30%);
  color: #fff;
}


/* Custom version test */
.custImg {
  display: inline-block;
  background-color: #fff;
}
form {
  max-width: 30em;
  margin: 0 auto;
}
label {
  display: flex;
  justify-content: space-between;
  margin: .5rem 0;
  text-align: right;
}
label span {
  width: 12em;
}
input {
  width: calc(100% - 14em);
}


.stamp_img-bgTest {
  display: block;
}

[class^="stamp_link"] {
  color: hsl(269,19%,30%);
  background-color: #fff;
  display: block;
  min-width: 296px;
  max-width: 616px;
  margin: 0 auto;
  text-decoration: none;
  transition: color .3s ease-out;
}

[class^="img_container"] {
  position: relative;
}

[class^="stamp_img-bg"] {
  background-repeat: no-repeat;
  height: 300px;
  background-size: cover;
  background-position: center;
  background-image: var(--image);
}
img[class^="stamp_img-bg"] {
  background-image: none;
}

[class^="stamp_copy"] p {
  padding: .75rem;
  margin: 0;
}

/* Stamp image vignette */
[data-vignetteOpacity] {
  --vignetteInnerRadius: 58%;
  --vignetteOuterRadius: 150%;
}
[data-vignetteOpacity="1"] {--vignetteOpacity: 1;}
[data-vignetteOpacity="0.75"] {--vignetteOpacity: 0.75;}
[data-vignetteOpacity="0.5"] {--vignetteOpacity: 0.5;}
[data-vignetteOpacity="0.25"] {--vignetteOpacity: 0.25;}
[data-vignetteOpacity="0.125"] {--vignetteOpacity: 0.125;}
[data-vignetteOpacity="0"] {--vignetteOpacity: 0;}

[data-vignetteOpacity]::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  opacity: var(--vignetteOpacity, .5);
  background-image: radial-gradient(ellipse at center, hsla(0,0%,0%,0) var(--vignetteInnerRadius, 58%), hsla(0,0%,0%,1) var(--vignetteOuterRadius, 150%));
  box-shadow: inset 0 0 1rem 0 hsla(0,0%,0%, calc(var(--vignetteOpacity, .5) / 2));
  transition: opacity .3s ease-out;
}
a:hover [data-vignetteOpacity]::after,
a:focus [data-vignetteOpacity]::after {
  will-change: opacity;
  opacity: 0;
}




/* Stamp image brightness */

[data-imgBrightness="100%"] {--imgBrightness: 100%;}
[data-imgBrightness="105%"] {--imgBrightness: 105%;}
[data-imgBrightness="110%"] {--imgBrightness: 110%;}
[data-imgBrightness="115%"] {--imgBrightness: 115%;}
[data-imgBrightness="120%"] {--imgBrightness: 120%;}
[data-imgBrightness="125%"] {--imgBrightness: 125%;}

[data-imgBrightness] {
  transition: filter .3s ease-out;
}
a:hover [data-imgBrightness],
a:focus [data-imgBrightness] {
  will-change: filter;
  filter: brightness(var(--imgBrightness, 100%));
}
            
          
!
            
              
// Switches the images. Using CSS custom properties
(function () {
  
  "use strict";

  const stamps = document.querySelector(".stamps");

  function setImageVar(e) {
    stamps.style.setProperty("--image", e.target.value);
  }

  const btns = document.querySelectorAll("button");
  for (const btn of btns) {
    btn.addEventListener("click", setImageVar, false);
  }

}());
            
          
!
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