Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<div class=grid_parent>
  
  <div class=grid-2_3_4>

    <!-- SVGs are embedded into these divs by JS -->
        
    <div class=gridItem-01 data-fullScreen></div>
    <div class=gridItem-02 data-fullScreen></div>
    <div class=gridItem-03 data-fullScreen></div>
    <div class=gridItem-04 data-fullScreen></div>
    <div class=gridItem-05 data-fullScreen></div>
    <div class=gridItem-06 data-fullScreen></div>
    <div class=gridItem-07 data-fullScreen></div>
    <div class=gridItem-08 data-fullScreen></div>
    <div class=gridItem-09 data-fullScreen></div>
    <div class=gridItem-10 data-fullScreen></div>
    <div class=gridItem-11 data-fullScreen></div>
    <div class=gridItem-12 data-fullScreen></div>

  </div> <!-- .grid-2_3_4 -->
</div> <!-- .wrapper -->


<svg id=svg_defs style=display:none>

  <symbol id="icon-andyWarhol" viewBox="0 0 600 600">
    <!-- Refactored from: https://thenounproject.com/Simon%20Child on: https://thenounproject.com/term/andy-warhol/62704/-->
    <path id="andy_face" fill="var(--face)" d="M436 290l1 35-32 150-19 42-60 55-82-2-52-42-32-68-31-169 256-109"/>
    <path id="andy_hair" fill="var(--hair)" d="M587 173S540 27 374 66c-1 1-52-26-52-26l-68-16c-62 0-116 14-163 38l140-19C110 89 46 161 38 256l59-84-12 45-12 101 26-40 10 10-1 85 37 33-11-95 65-56-10 86c51-71 114-127 198-161 6 58 20 78 49 110v33l-9 85c18-18 36-36 56-51 14-26 24-54 26-86v-1l16 14c-1-70-45-128-45-128l15-10-61-34 74 1 79 60z"/>
    <path id="andy_outline" fill="var(--line)" d="M600 191l-9 4-12-16c-34-42-82-74-137-66 31 9 61 25 88 42l-4 9c-12-5-26-8-39-9 40 42 47 108 49 165l-9 2c-3-12-6-24-11-36-6 32-18 65-33 92l-9-3v-12l-8 8c-9 27-27 37-39 40l-14 66c-10 25-23 47-44 63l-12 11c-22 28-32 28-71 29-38-1-49-1-71-29l-12-11c-21-16-34-38-44-63l-14-66c-11-2-26-11-36-32l-4 18-9-1c0-26 4-59 11-89l-5 8-9-4 7-26c-16 27-27 56-31 82l-10-1c1-27 8-82 20-121-6 9-10 18-14 27l-9-3c6-27 22-59 37-87-30 33-46 72-53 109h-9C15 161 125 76 200 50c-68 1-132 29-178 81L8 148l-8-4 7-15C42 68 118 37 180 25c67-13 136-2 193 37 96-39 201 19 227 129zm-16-22a159 159 0 00-210-97h-4c-84-59-197-51-284-4 38-19 87-33 149-27v10c-59 6-190 82-196 206 26-80 96-158 260-159v10c-86 1-145 22-185 54l-3 7-27 51c33-41 86-72 161-75l1 9c-68 3-115 29-147 64l-4 10c-10 23-18 59-22 90 10-25 25-50 44-72l1-1c15-16 32-30 53-41l4 9c-19 10-36 23-50 39-6 10-11 22-16 36l22-26 7 7-16 19c-5 18-10 41-13 61 16-38 43-72 89-96l6 6-6 24-10 1 1-5c-8 1-15 4-21 6 6-6 14-11 23-14l1-4c-17 8-57 49-55 50-10 15-18 30-23 46 2 4 7 5 10 6 5 2 4 11-7 5 7 16 18 23 26 27l-3-15c-7-13-9-32-5-63h2c3 1 6 2 6 6a436 436 0 002 27c1 23 9 34 21 43 11 9 22 18 29 28 6 9 8 16 7 32 0 4-5 4-5 0 0-15-2-21-7-28-6-10-16-19-27-27l-12-12 17 82c7 20 17 36 31 50-2-7-3-22-2-23-3-3-5-8-5-13 0-4 5-4 5 0 0 6 6 12 11 13 4 1 3 7-1 6h-1a137 137 0 004 27c5 3 9 7 12 11 6 7 12 15 20 19s21 6 44 6c25 0 42 1 59-18l5-7 11-10v-23s6-11 9-32c1-12-2-29 1-41-5-12-13-22-20-30l9 1 14 22 4-5c9-9 18-20 28-28 12-10 20-20 21-44l1-15v-11c0-4 4-5 7-6h2c5 33 3 51-5 65l-3 12c9-3 19-10 26-26h-2c-6 0-6-10 1-10s14-5 17-15c-16-51-91-90-88-157-39 12-88 45-127 82 9 6 12 16 13 25h-1c-4-6-12-11-22-15l-4 4-11-3c44-46 108-93 156-105l6 6c-9 70 79 108 90 171 12-27 22-57 26-86v-1c-6-12-14-24-23-35l6-7c14 16 25 34 32 53-4-46-17-99-54-129l3-9 22 3c-24-13-51-25-77-28v-10c65-20 124 11 166 61zM421 392l-12 12c-10 8-18 18-27 27-9 8-6 23-6 34 0 17-3 34-10 49l1 16c17-15 29-34 37-56l17-82zm-91 90c2-3 6 1 4 4l-2 1c-4 3-8 5-13 5 0 3-2 6-6 6a134 134 0 00-53 0c-3 0-6-3-5-6-6 0-13-2-17-6-2-3 2-7 4-4h1c4 3 9 4 14 3 9-2 20-2 29-2 10 0 20 0 29 2 5 1 11 0 15-3zm6-14l-16-5h-29a20 20 0 01-10 0h-29l-13 4-8 3c-6 4-11-5-5-8 7-5 15-5 23-9 6-2 23-9 29-2a11 11 0 0015 0c4-3 11-6 30 2 8 4 12 4 16 5 6 2 3 11-3 10zm-34-147l-2-4c2 2 4 0 5 2l2 13 1 23c1 5 3 10 6 14s10 7 13 11 5 15 5 17c-1 6-5 12-13 12-3 0-6-1-8-4-4 1-5 0-6-2l-3 2c-7 12-25 12-32 0l-3-2c-1 2-3 2-5 2-3 3-6 4-9 4-8 0-12-6-13-12 0-1 0-11 2-13l8-10c9-6 10-15 15-26 2-6 1-25 1-28 1-1 4-1 5-3l2-1c-3 2-3 5-3 5v19c0 11-2 21-7 31 1 1 0 3-2 4-14 3-22 28-8 28l5-2 2-5c2-1 4-4 8-5 1 0 4 1 5 3 2 4 7 7 14 7 11 0 12-11 17-10 4 1 6 4 8 5l1 4 1 1 5 2c14 0 6-25-8-28-2-1-3-3-2-4-5-10-7-20-7-31v-19zm1-22c1-18 10-36 57-33 18 2 34 8 44 19-12-5-28-9-48-8-22 1-44 11-52 22h-1z"/>
    <path id="andy_glasses" fill="var(--spec)" d="M188 285c12-2 57-6 76 18 2 2 4 2 7 1 8-5 20-5 30-1 1 1 4 2 5 1 12-17 44-22 63-21s42 11 54 16c4 2 11 1 13 1l1 3 1 11-3 3-10 5v8c0 21-8 42-18 54-15 18-44 25-59 19-6-2-11-4-15-8-4-3-3-11-6-15s-10-7-13-11-5-9-6-14l-1-23-2-13c-1-2-3 0-5-2-1-3-9-5-13-5-5 1-13 2-16 5-1 2-4 2-5 3 0 3 1 22-1 28-5 11-6 20-15 26l-8 10c-2 3-1 12-3 12-40 21-67-6-70-8a65 65 0 01-20-42l-1-22c0-2-9-3-9-6 1-3 12-17 16-20 5-4 29-14 33-13zm136 18s20 12 43 17c30 7 48 6 48 6s-5-28-39-34-52 11-52 11zm-131-11c15 16 50 23 66 25-3-7-15-18-24-21-10-5-33-1-42-4z"/>
    <path id="andy_fringe-fill" fill="var(--hair)" d="M199 262l-14 84 65-73-51-11z"/>
    <path id="andy_fringe-outline" fill="var(--line)" d="M192 267c-12 50-11 80-11 80s8 6 9 4c25-33 57-70 67-78 2-2-7-7-9-5-32 26-59 70-59 70s9-58 15-77c1-5-10 1-12 6z"/>
  </symbol>
</svg>




<div class=description>

  <h1>Andy Warhol looks a scream&hellip;</h1>

  <p><i>[ This page demonstrates an alternate use of <a target=_blank title="[new window]" href="https://codepen.io/2kool2/pen/ZEzgQRx">launch any object into full-screen method</a>. ]</i></p>

  <p>Here we are emulating Andy Warhol's Marilyn Monroe screenprints from the 1970s.<br>These prints are based on the picture taken by Gene Korman for Niagara film reel.<br>About 50 works were based on that image:</p>

  <img style="max-width:650px" src="https://cdn.shopify.com/s/files/1/0037/9214/2436/articles/setmarilyn.jpg?v=1561746021" alt="Andy Warhol's Marilyn (Monroe) Diptych (1962)">

  <p>If you wish to know more, start with this Art Trauma article:<br> <a target=_blank title="[new window]" href="https://www.artetrama.com/blogs/news/about-andy-warhols-sunday-b-morning-marilyn-monroe-series">About Andy Warhol's Marilyn Monroe</a>.</p>

  <p>We're replacing Marilyn's portrait with that of Warhol himself, based on a self-portrait photograph from 1986:</p>

  <img style="max-width:698px" src="https://d2jv9003bew7ag.cloudfront.net/uploads/Andy-Warhol-Self-Portrait-With-Fright-Wig-1986.jpg" alt="Andy Warhol self-portrait with fright wig (1986)">

  <p>The photo was reimagined into an SVG by Simon Child: <a target=_blank title="[new window]" href="https://thenounproject.com/term/andy-warhol/62704/">Andy Warhol SVG</a>.</p>

  <p>The SVG was refactored, by myself, into a semi-random colour version using CSS variables, then layed-out into a 12-cell grid based on browser width.</p>

</div>



<!--  Footer include -->
[[[https://codepen.io/2kool2/pen/mKeeGM]]]
              
            
!

CSS

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

body {
  margin: 0;
  text-align: center;
  font-family: sans-serif;
  line-height: 1.5;
  color: #4B3D5A;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='1200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.05' stitchTiles='stitch' numOctaves='4' result='noise'/%3E%3CfeDiffuseLighting in='noise' lighting-color='%23ffe' surfaceScale='2' result='diffLight'%3E%3CfeDistantLight azimuth='35' elevation='60'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='1200' height='1200' filter='url(%23n)' opacity='.2'/%3E%3C/svg%3E");
}

/* Comment this class out to read text */
.-visually-hidden {
  position: absolute !important;
  clip: rect(1px,1px,1px,1px);
  padding: 0 !important;
  border: 0 !important;
  height: 1px !important;
  width: 1px !important;
  overflow: hidden;
}
.description {
  margin: 2rem 1rem;
}
h1 {
  font-weight: 400;
}
p {
  max-width: 40rem;
  margin: 1rem auto;
}
img {
  display: block;
  margin: 2rem auto;
  width: 100%;
}

/* Makes Chrome behave like Firefox */
[data-fullScreen]:-webkit-full-screen {
  width: 100%;
  height: 100%;
}

/* Button is added by JS, when supported */

[class^="btn-fullScreen"]::-moz-focus-inner {
  border: 0;
}
[class^="btn-fullScreen"] {
  display: block;
  width: 100%;
  padding: 10%;
  background-color: inherit;
  border: none;
  cursor: pointer;
  transition: all .3s;
}
[class^="svg-andyWarhol"] {
  display: block;
  margin: 0 auto;
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  filter: drop-shadow(.25vw .25vw .25vw rgba(0,0,0,.75));
  transition: all .3s;
}
[class^="btn-fullScreen"]:focus {
  outline: none;
}
[class^="btn-fullScreen"]:hover > [class^="svg-andyWarhol"],
[class^="btn-fullScreen"]:focus > [class^="svg-andyWarhol"] {
  filter: drop-shadow(.5vw .5vw .5vw rgba(0,0,0,1));
  transform: scale(1.1);
  outline: none;
}
:fullscreen [class^="svg-andyWarhol"],
:fullscreen :hover > [class^="svg-andyWarhol"],
:fullscreen :focus > [class^="svg-andyWarhol"] {
  filter: drop-shadow(.5vw .5vw .5vw rgba(0,0,0,1));
  transform: scale(0.8);
  outline: none;
}


/* Grid layout */

/* Grid spacing */
[class^="grid_parent"] {}

/* The grid */
[class^="grid-"] {
  --columns: 1;
  display: grid;
  grid-template-columns: var(--columns);
}
@media (min-width: 20em) { /* 320px */
  [class^="grid-2"] {
    --columns: 1fr 1fr;
  }
}
@media (min-width: 40em) { /* 640px */
  [class^="grid-3"],
  [class^="grid-2_3"] {
    --columns: 1fr 1fr 1fr;
  }
}
@media (min-width: 60em) { /* 960px */
  [class^="grid-2_4"],
  [class^="grid-2_3_4"] {
    --columns: 1fr 1fr 1fr 1fr;
  }
}

/* Grid item */
[class^="gridItem-"] {
  min-width: calc(20rem - var(--spacing) * 2);
  min-height: 33.3333vh;
  max-height: 50vh;
  max-width: 100vw;

  /* Centre the content (button) */
  display: flex;
  align-items: center;
  justify-content: center;
  
  fiter: greyscale(100%)
}



/* Colouring in */

/* Backgrounds are set to prevent neighbour clashes */
.gridItem-01 {background-color: #d27;}
.gridItem-02 {background-color: #18a;}
.gridItem-03 {background-color: #beb;}
.gridItem-04 {background-color: #cac;}
.gridItem-05 {background-color: #7c6;}
.gridItem-06 {background-color: #f79;}
.gridItem-07 {background-color: #d98;}
.gridItem-08 {background-color: #2cd;}
.gridItem-09 {background-color: #ecd;}
.gridItem-10 {background-color: #0ac;}
.gridItem-11 {background-color: #e38;}
.gridItem-12 {background-color: #aa5;}

/* SVG colours are generated by JS using CSS variables */
              
            
!

JS

              
                var supportsES6 = function() {
  // https://gist.github.com/bendc/d7f3dbc83d0f65ca0433caf90378cd95
  try {
    new Function("(a = 0) => a");
    return true;
  }
  catch (err) {
    return false;
  }
}();



// Deep merge (for the config file)
// Adapted from: Prashant Yadav - https://learnersbucket.com/examples/javascript/how-to-merge-objects-in-javascript/
const deepMerge = (...arguments) => {

  const len = arguments.length;
  if (len < 1) return {};
  if (len < 2) return arguments[0];

  const target = {};

  // Merge the object into the target object
  const merger = obj => {
    for (const prop in obj) {
      if (!obj.hasOwnProperty(prop)) continue;

      if (Object.prototype.toString.call(obj[prop]) === '[object Object]') {
        // If doing a deep merge, and the property is an object
        target[prop] = deepMerge(target[prop], obj[prop]);
      } else {
        // Otherwise, a regular merge
        target[prop] = obj[prop];
      }
    }
  };

  //Loop through each object and conduct a merge
  for (const argument of arguments) {
    merger(argument);
  }

  return target;
};


// Use the Andy Warhol SVG as the  buttons open / exit SVG
// by overriding the default configuration


// Add a full-screen toggle button where supported.
// Version 1.5 06/10/2019
// Version 1.6 14/10/2019 - Added a deep merge for config file
// Prefixes would be required for production.

function launchFullWindow(config) {

  "use strict";
  if (!supportsES6) return false;
  if (!document.fullscreenEnabled) return false;

  let cfg = {
    launchObjSelect : '[data-fullScreen]',
    launchBtnClass : 'fullScreen_btn',
    svgClass : 'fullScreen_svg',
    open : {
      icon : 'icon-fullScreen-open',
      extension : '-open',
      label : 'Launch into full screen',
      title : 'Full screen [f, f11]'
    },
    exit : {
      icon : 'icon-fullScreen-exit',
      extension : '-exit',
      label : 'Exit full screen',
      title : 'Exit full screen [f, f11, esc]'
    }
  };

  // Blend the parameter config into the default cfg
  // Object.assign(cfg, config); // Would require config to be an exact object match
  // Deep merge allows a partial object matching (prevents overwrite of cfg.open and cfg.exit).
  cfg = deepMerge(cfg, config);
  
  const svgData = {
    open : {},
    exit : {}   
  }

  // Get symbol from the SVG definitions in the HTML
  const setSvgData = (_ => {

    const getData = param => {
      const symbol = document.getElementById(cfg[param].icon);
      if (!symbol) return false;
      svgData[param].class = cfg.svgClass;
      svgData[param].icon = cfg[param].icon;
      svgData[param].symbol = symbol.innerHTML;
      svgData[param].viewBox = symbol.getAttribute('viewBox');
    };

    getData('open');
    getData('exit');
  })();


  const _instantiateLaunchObj = launchObj => {

    const _getCfg = (param, toOpen) => cfg[toOpen ? 'open' : 'exit'][param];


    const _getSvgString = toOpen => {
      const param = _getCfg('extension', toOpen).substr(1);

      // Note: complete SVG is embedded, not a <use>, so each may have different properties. Color for example.
      return `<svg class="${svgData[param].class}" aria-hidden="true" viewbox="${svgData[param].viewBox}">${svgData[param].symbol}</svg>`;
    }

    const _setBtnAttr = toOpen => {
      btn.className = cfg.launchBtnClass + _getCfg('extension', toOpen);
      btn.title = _getCfg('title', toOpen);
      btn.setAttribute('aria-label', _getCfg('label', toOpen));
      btn.innerHTML = _getSvgString(toOpen);
    }

    // Check to see if the button already exists in the elements html
    let btn = launchObj.querySelector('.' + cfg.launchBtnClass);
    if (!btn) {

      // If not, create one
      btn = document.createElement('button');
      launchObj.prepend(btn);
    }
    _setBtnAttr(true);

    const _toggleFullScreen = _ => {
      if (!document.fullscreenElement) {
        launchObj.requestFullscreen();
      } else {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        }
      }
      btn.focus();
    }

    const _onFullscreenChange = _ => _setBtnAttr(!document.fullscreenElement);

    {
      btn.addEventListener('click', _toggleFullScreen);

      // Toggle attr this way because esc key is not detected but change is!
      document.addEventListener('fullscreenchange', _onFullscreenChange);

      // Toggle if the f, or f11, key is pressed
      document.addEventListener('keydown', event => {
        if (event.keyCode === 70 || event.keyCode === 112) {
          _toggleFullScreen();
        }
      });
    }

  }

  // Multiple objects to launch
  const objs = document.querySelectorAll(cfg.launchObjSelect);
  for (const obj of objs) {
    _instantiateLaunchObj(obj);
  }

}

// Any object with data-fullScreen attribute by default
// Overrides the defaults to use the Andy Warhol SVG
launchFullWindow({
  launchBtnClass : 'btn-fullScreen',
  svgClass : 'svg-andyWarhol',
  open : {
    icon : 'icon-andyWarhol'
  },
  exit : {
    icon : 'icon-andyWarhol'
  }
});






// Andy Warhol in glorious technicolor
  
var addColorToSvgs = (function(config) {

  "use strict";
  if (!supportsES6) return false;

  let cfg = {
    svgSelect : '.svg-andyWarhol'
  };

  const getRandomInt = (min, max) => {
    // Maximum is exclusive, minimum is inclusive
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min)) + min;
  };

  // Generate HSL colour
  const H = _ => getRandomInt(0, 361);
  const S = _ => getRandomInt(0, 101);

  /* Lightness */
  const L1 = _ => getRandomInt(0, 27); // Darkest
  const L2 = _ => getRandomInt(28, 67); // Medium
  const L3 = _ => getRandomInt(34, 101); // Lightest

  // Andy SVGs
  const andys = document.querySelectorAll(cfg.svgSelect);
  for (const andy of andys) {

    // Get a random color
    const hair = H();

    // Calc its double complimentary colors:
    const face = (hair + 60) % 360;
    const spec = (hair + 180) % 360;
    const line = (hair + 240) % 360;

    // Add the CSS vars to the SVGs parent
    andy.parentElement.setAttribute('style', 
      `--hair: hsl(${hair}, ${S()}%, ${L3()}%); 
       --face: hsl(${face}, ${S()}%, ${L2()}%); 
       --spec: hsl(${spec}, ${S()}%, ${L1()}%); 
       --line: hsl(${line}, ${S()}%, ${L1()}%); `);
  }

})();



              
            
!
999px

Console