HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Blackout Poetry</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h3>Instructions:</h3>
<div class="info">
<p>A blackout poem is made by selecting indivual words from a longer story. In the Story Snippet below, clicking individual words marks them in yellow and adds them to your poem in the order they appear. "block/unblock unmarked words" will block out all words that are not marked in yellow.Use the existing story below or copy and paste your own story into the window below and hit submit.</p></div>
<div class="upload">
<form class="upload" onSubmit="return newStory();">
<textarea class="textarea"></textarea>
<input type="submit" value="Submit">
</form>
</div>
</div>
</div>
<div class = "row">
<div class = "col-md-6 story-section">
<h3>Story Snippet: (click words to add to poem)</h3>
<div class="story">
</div>
</div>
<div class = "col-md-6">
<h3>Your Poem:</h3>
<div class="poem">(your poem appears here)
</div>
</div>
</div>
<div class = "row">
<div class="menu">
<p>Click a word mark it. </p>
<div class="btn blockOut">blockout/unblock unmarked words</div>
<div class="btn clearMarked">clear marked words</div>
<div class="btn reset">Reset all words</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/app.js"></script>
</body>
.poem {
font-size: 28px;
}
.story-section{
background-color: aliceblue
}
.blocked {
background-color: #222222;
transition: background-color 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
border-radius: 8px;
}
.faded {
opacity: .0;
transition: opacity 0.5s ease-in-out;
border-radius: 8px;
}
span {
opacity: 1;
transition: opacity 0.5s ease-in-out;
transition: background 0.5s ease-in-out;
border-radius: 8px;
}
.story {
font-size:18px;
margin-top:5px;
}
h3{
padding-top:1em;
}
div.menu{
background: #CCCCCC;
padding: 3px;
border: 1px solid black;
}
.marked {
background-color: yellow;
}
div.btn.reset { background: red; }
div.btn {
border-radius: 8px;
background: #FFFFFF;
/*display: inline-block;*/
vertical-align: middle;
margin: 4px 4px 4px 4px;
padding: 5px 5px 5px 5px;
}
.active{
background: yellow;
}
var story = "I had scarcely thought of the theater for some years, when Kean arrived in this country; and it was more from curiosity than from any other motive, that I went to see, for the first time, the great actor of the age. I was soon lost to the recollection of being in a theater, or looking upon a great display of the \"mimic art.\" The simplicity, earnestness, and sincerity of his acting made me forgetful of the fiction, and bore me away with the power of reality and truth. If this be acting, said I, as I returned home, I may as well make the theater my school, and henceforward study nature at second hand. \nHow can I describe one who is almost as full of beauties as nature itself,—who grows upon us the more we become acquainted with him, and makes us sensible that the first time we saw him in any part, however much he may have moved us, we had but a partial apprehension of the many excellences of his acting? We cease to consider it as a mere amusement. It is an intellectual feast; and he who goes to it with a disposition and capacity to relish it, will receive from it more nourishment for his mind, than he would be likely to do in many other ways in twice the time. Our faculties are opened and enlivened by it; our reflections and recollections are of an elevated kind; and the voice which is sounding in our ears, long after we have left him, creates an inward harmony which is for our good. \nKean, in truth, stands very much in that relation to other players whom we have seen, that Shakspeare does to other dramatists. One player is called classical; another makes fine points here, and another there; Kean makes more fine points than all of them together; but in him these are only little prominences, showing their bright heads above a beautifully undulated surface. A continual change is going on in him, partaking of the nature of the varying scenes he is passing through, and the many thoughts and feelings which are shifting within him.";
// VARIABLES
var blockedOut = false;
var faded = false;
var punctuation = /([—.,?!;:"'])/;
// FUNCTIONS
function displayStory(storytext) {
var poem = '';
var array = storytext.split(' ');
array.forEach(function(word){
poem += "<span class>" + word + " </span>"
});
$(".story").html(poem);
}
// Update text of poem
function updatePoem () {
$("div.poem").html($("span.marked").text());
}
function newStory (){
var storytext = $(".textarea").val()
$('.story').html(displayStory(storytext));
$(".textarea").val('');
return false;
}
displayStory(story);
// CLICK RESET: Remove all classes, clear poem
$(".reset").on('click',function(){
$("span").removeClass('blocked faded marked');
$(".poem").html('(Marks words above to populate your poem)');
});
// Clicking on Words
$("div.story").on("click",function (evt){
if (this === evt.target || $(evt.target).hasClass('faded') ){
// do nothing
} else {
$(evt.target).removeClass("blocked")
$(evt.target).toggleClass("marked")
}
updatePoem();
});
// Block out all words not "marked"
$(".blockOut").on('click', function(){
if(blockedOut){
$("span:not('.marked')").removeClass("blocked");
blockedOut = false;
} else {
$("span:not('.marked')").addClass("blocked");
blockedOut = true;
}
});
//
$(".clearMarked").on('click', function(){
$("span").removeClass("marked");
$(".poem").html('(Marks words above to populate your poem)');
});
Also see: Tab Triggers