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

              
                <!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>CSS Code Snippet Generator</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- Bootstrap CDN with 'Sketchy' Bootswatch Theme -->
	<link href="https://stackpath.bootstrapcdn.com/bootswatch/4.2.1/sketchy/bootstrap.min.css" rel="stylesheet" integrity="sha384-Yr9hLdz4zKsdMcB2IUf0I2Y+KFalEfJez2d0H2rgQoAYjvm/mzbm2egxZ9Gc9kkg" crossorigin="anonymous">
	<!-- PrettyPrint Styling -->
	<link href="main.css" rel="stylesheet">
</head>

<body>
  <h1 class="title">CSS Snippet Generator</h1>
  <!--  Instructions  -->
  <h3 class="title">Generate the snippets, then print!</h3>
  <h5 class="title">You can edit the dynamic (green) values at the top of the JS file</h5>
  <!-- CSS Snippet Container	-->
  <div class="container" id="css_print"></div>
  <!-- CSS Snippet Template -->
  <pre class="container prettyprint" id="css-snippet">
    .post-<span class="nocode" id="postNumber"></span>.is_sample {
      background: linear-gradient(
        rgba(0, 0, 0, 0.9),
        rgba(255, 20, 147, 0.3)
      ),
      url(https://www.example.com/thumbnails/<span class="nocode" id="thumbnail"></span>.png);
      background-size: cover;
      background-repeat: no-repeat;
      background-position: center;
    } </pre>

  <div class="container" id="buttons">
    <button class="btn btn-secondary" onclick="generateCss()">Generate Snippets</button>
    <button class="btn btn-primary" onclick="printCss()">Print Snippets</button>
  </div>

  <!-- CSS Snippet Output Script-->
  <script src="generator.js"></script>
  <!-- PrettyPrint JS -->
  <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
</body>
</html>
              
            
!

CSS

              
                /* Pretty printing styles. Used with prettify.js. */
/* Vim sunburst theme by David Leibovic */

pre span, code span { color: greenyellow; }
pre .str, code .str { color: #65B042; } /* string  - green */
pre .kwd, code .kwd { color: #E28964; } /* keyword - dark pink */
pre .com, code .com { color: #AEAEAE; font-style: italic; } /* comment - gray */
pre .typ, code .typ { color: #89bdff; } /* type - light blue */
pre .lit, code .lit { color: #3387CC; } /* literal - blue */
pre .pun, code .pun { color: #fff; } /* punctuation - white */
pre .pln, code .pln { color: #fff; } /* plaintext - white */
pre .tag, code .tag { color: #89bdff; } /* html/xml tag    - light blue */
pre .atn, code .atn { color: #bdb76b; } /* html/xml attribute name  - khaki */
pre .atv, code .atv { color: #65B042; } /* html/xml attribute value - green */
pre .dec, code .dec { color: #3387CC; } /* decimal - blue */

pre.prettyprint, code.prettyprint {
	background-color: #000;
	border-radius: 8px;
}

pre.prettyprint, #css-snippet  {
	width: 100%;
	margin: 1em auto;
	padding: 1em;
	white-space:pre-wrap;
}

/* Specify class=linenums on a pre to get line numbering */
ol.linenums { margin-top: 0; margin-bottom: 0; color: #AEAEAE; } /* IE indents via margin-left */
li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8 { list-style-type: none; background-color: purple}
/* Alternate shading for lines */
li.L1,li.L3,li.L5,li.L7,li.L9 { background-color: orange}

@media print {
	pre .str, code .str { color: #060; }
	pre .kwd, code .kwd { color: #006; font-weight: bold; }
	pre .com, code .com { color: #600; font-style: italic; }
	pre .typ, code .typ { color: #404; font-weight: bold; }
	pre .lit, code .lit { color: #044; }
	pre .pun, code .pun { color: #440; }
	pre .pln, code .pln { color: #000; }
	pre .tag, code .tag { color: #006; font-weight: bold; }
	pre .atn, code .atn { color: #404; }
	pre .atv, code .atv { color: #060; }
}

/* Buttons & Title */
.title, #buttons {
	text-align: center;
}
.title, .btn {
	margin: 0.5em
}

/* css_print container */
#css_print {
	padding-left: 0;
	padding-right: 0;
}

/* controls mobile font scaling */
@media only screen and (max-width: 506px) {
  body.vsc-initialized {
    font-size: .85rem !important;
  }
}

pre {
  margin: 0 auto;
}
              
            
!

JS

              
                // User Can Edit These Values
var thumbnail = 1; // Starting thumbnail image number
var postNumber = 20; // Starting post ID
const moduleCount = 3; // Number of snippets to display
// Store
var storeVals = []; // Stores thumnail and post number values
var storeCode = []; // Empty array to store CSS code blocks

var css_block = (css_block = document.getElementById("css-snippet")); // Stores CSS snippet template
var thumbnail_output = document.getElementById("thumbnail");
var postNum_output = document.getElementById("postNumber");
var css_print = document.getElementById("css_print");

thumbnail_output.innerHTML = thumbnail;
postNum_output.innerHTML = postNumber;

function generateCss() {
  for (let module = 1; module < moduleCount; module++) {
    thumbnail++;
    postNumber++;

    storeVals[module] = { thumbnail, postNumber };

    console.log(module, storeVals[module]);
  }
}

function printCss() {
  document.getElementById("buttons").style.display = "none"; // Hide buttons

  for (let module = 1; module < moduleCount; module++) {
    var pre = document.createElement("pre");
    var code = document.createElement("code");

    code.innerHTML = css_block.innerHTML;
    pre.className = "prettyprint container";
    pre.appendChild(code);
    pre.style.padding = "1em";
    css_print.appendChild(pre); // Append new 'pre' block to css_print div

    thumbnail_output.innerHTML = storeVals[module].thumbnail;
    postNum_output.innerHTML = storeVals[module].postNumber;

    console.log(module, storeVals[module]);
  }
}

              
            
!
999px

Console