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.

            
              <div class="js-cookiebar cookiebar position--fixed width--100 block" style="display:none">
  <div class="card margin">
    <div class="mw--48 flex flex--column justify--center center">
      <div class="card-content">
        <h2 class="card-title">[YOUR_SITE] uses cookies</h2>
        <p>[YOUR_SITE] uses cookies (and other techniques) to collect information about the use of the platform in order to analyse and improve, for the use of social media and to ensure that advertisements are relevant to you. Read more about our cookie policy, <a href="/terms" target="_blank" class="link">terms and conditions</a> and <a href="/privacy" target="_blank" class="link">privacy statement</a>. By continuing on this site and accepting our cookies you agree to the collection of information on this basis by us and by third parties on the platform. Please customize your cookie settings below.</p>
        <div class="card-action flex--row justify--space-between p-top--1 p-bottom--1">
          <div class="flex width--100 align__items--center justify--center">
            <label class="flex align__items--center justify--center m-right--1" for="basic_chkbx">Basic</label><input id="basic_chkbx" type="checkbox" name="items" value="true" disabled checked />
          </div>
          <div class="flex width--100 align__items--center justify--center">
            <label class="flex align__items--center justify--center m-right--1" for="preferences_chkbx">Preferences</label><input id="preferences_chkbx" type="checkbox" name="items" value="true" />
          </div>
          <div class="flex width--100 align__items--center justify--center">
            <label class="flex align__items--center justify--center m-right--1" for="statistics_chkbx">Statistics</label><input id="statistics_chkbx" type="checkbox" name="items" value="true" />
          </div>
          <div class="flex width--100 align__items--center justify--center">
            <label class="flex align__items--center justify--center m-right--1" for="marketing_chkbx">Marketing</label><input id="marketing_chkbx" type="checkbox" name="items" value="true" />
          </div>
          <button type="button" class="button button--blue flex width--100 justify--center" id="cookiebutton" onclick="onCookieButtonClick()">Accept</button>
        </div>
      </div>
    </div>
  </div>
</div>
<button class="button button--orange js-change-cookie">Change Cookie</button>
            
          
!
            
              @use postcss-nested;
@use postcss-cssnext;

:root {
  --fontsize: 1rem;
  --blue: rgba(8,125,196,1);
  --orange: rgba(239, 113, 2, 1);
  --grey--dark:rgba(24,24,24, 1);
  --white: rgba(255,255,255,1);
  --100: 100;
}

@custom-media --max-md (width <= 48em);

.cookiebar {
    position: fixed;
    bottom: 0;
    left: 0;
    display: none;
    width: var(--100)%;
    box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), -3px -4px 5px 0 rgba(0,0,0,0.12), 0 3px 1px -2px rgba(0,0,0,0.2);

    .card {
        position: relative;
        margin: 0;
        width: var(--100)%;
        border-radius: 2px;
        background-color: var(--white);

        &-inner {
            display: flex;
            margin: 0 auto;
            flex-direction: column;
            justify-content: center;
            max-width: 48em;
        }

        &-content {
            padding: 24px;
            border-radius: 0 0 2px 2px;
        }

        &-title {
            margin-bottom: 8px;
            display: block;
            line-height: 32px;
            font-size: 1.5rem;
            font-weight: 300;
            color: var(--blue);
        }

        &-action {
            position: relative;
            padding: 16px 0 0;
            display: flex;
            align-items: center;
            justify-content: space-between;
            background-color: inherit;
            border-top: 1px solid rgba(160,160,160,.2);

            #basic_chkbx,
            label[for="basic_chkbx"] {
            opacity: .5;
            }

            @media (--max-md) {
                flex-direction: column !important;
                width: 100%;

                .flex {
                    margin-top: 10px;
                }

                > button {
                    max-width: 200px;
                    margin-top: 10px;
                }
            }
        }
    }
}

.m-right--1 {
    margin-right: 1em;
}

.width--100 {
    width: 100%;
}

.flex {
    display: flex;
}

.align__items--center {
    align-items: center !important;
}

.justify--center {
    justify-content: center !important;
}

.button--orange {
    background: var(--blue);
    color: var(--white);
}

.mw--48 {
  max-width: 48em;
}

.flex--row {
    flex-direction: row;
}

.flex--column {
    flex-direction: column;
}

.center {
  margin: 0 auto;
}

.button {
  position:relative;
  padding: 7.5px 15px;
  overflow: hidden;
  margin-bottom: 0;
  border: none;
  border-radius: 2px;
  box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
  background: var(--blue);
    font-family: 'Roboto', sans-serif;
    font-weight: 500;
    font-size: 14.4px;
    font-size: 0.9rem;
  color: var(--white);
  line-height: 1.5;
  text-transform: uppercase;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: all .2s ;
  
  &--orange {
    background: var(--orange);
  }
}

h1,
h2,
h3,
p,
label,
a {
  font-family: 'Roboto', 'sans-serif';
}

.block {
  display: block;
}
            
          
!
            
              function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

// Setup GTM dataLayer -- load
window.dataLayer = window.dataLayer || [];

// see if cookie exists, if not show cookiebar -- recommended to do this in head of page
if (!getCookie("CookieConsent")) {
  document.getElementsByClassName("js-cookiebar")[0].style.display = "block";
  window.dataLayer = [{
    'event': 'NoCookieExist'
  }];
} else {
  var cookieValue =
    "{" + '"cookieValue"' + ":" + getCookie("CookieConsent") + "}";
  var jsonData = JSON.parse(cookieValue);
  pushCookieValueToDataLayer(jsonData.cookieValue, "CookieBarStatus", false);
}

// get Cookie by name - credits to stackoverflow
function getCookie(cname) {
  var name = cname + "=",
    decodedCookie = decodeURIComponent(document.cookie),
    ca = decodedCookie.split(";");

  for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == " ") {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

// push cookieValue to dataLayer - set array, set eventName
function pushCookieValueToDataLayer(arr, eventName, boolean) {
    var x = arr.filter(function (v) {
        return v.value === true;
    });
    dataLayerType(x, eventName, boolean);
}

function dataLayerType(x, e, b) {
    if (b) {
        for (var i = 0; i < x.length; i++) {
            window.dataLayer.push(_defineProperty({}, x[i].name, x[i].value));
        }
        window.dataLayer.push({
            'event': e
        });
    } else {
        var dataInit = [];
        for (var i = 0; i < x.length; i++) {
            dataInit.push(_defineProperty({}, x[i].name, x[i].value));
        };
        dataInit.push({
            'event': e
        });
        window.dataLayer = dataInit;
    }
}

// set cookie on click
function onCookieButtonClick() {
  var basicValue = document.getElementById("basic_chkbx").checked,
    preferencesValue = document.getElementById("preferences_chkbx").checked,
    statisticsValue = document.getElementById("statistics_chkbx").checked,
    marketingValue = document.getElementById("marketing_chkbx").checked,
    options = [
      { name: "basic", value: basicValue },
      { name: "preferences", value: preferencesValue },
      { name: "statistics", value: statisticsValue },
      { name: "marketing", value: marketingValue }
    ],
    data = JSON.stringify(options),
    date = new Date();

  date.setTime(date.getTime() + 3650 * 24 * 60 * 60 * 1000);
  var expires = "expires=" + date.toUTCString();

  // set cookie
  document.cookie = "CookieConsent=" + data + ";" + expires + ";path=/";
  pushCookieValueToDataLayer(options, "CookiePreferencesChange", true);
  document.getElementsByClassName("js-cookiebar")[0].style.display = "none";
}

// show cookiebar on click
var changeCookie = document.getElementsByClassName("js-change-cookie")[0];

// Get cookievalue, set checkboxes to right value and show cookiebar
changeCookie.addEventListener(
  "click",
  function() {
    if (getCookie("CookieConsent")) {
      var cookieValue =
        "{" + '"cookieValue"' + ":" + getCookie("CookieConsent") + "}";
      var jsonData = JSON.parse(cookieValue);
      var x = jsonData.cookieValue.filter(function(v) {
        return v.value === true;
      });

      for (let i = 0; i < x.length; i++) {
        let y = x[i].name + "_chkbx";
        document.getElementById(y).checked = true;
      }
    }

    document.getElementsByClassName("js-cookiebar")[0].style.display = "block";
  },
  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.

Console