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 lang="en">
<head>
    <meta charset="UTF-8">
    <title>Changing colors</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
    <link rel="stylesheet" href="changing.css">
</head>
<body>
    <div class="container">
        <header class="row">
            <h1 id="page-title" class="text-center w-100">Change my colors!</h1>
        </header>
        <div class="row d-flex justify-content-center mt-2">
            <nav class="btn-group">
                <button id="color-button-blue" class="btn btn-secondary">Blue</button>
                <button id="color-button-brown" class="btn btn-secondary">Brown</button>
                <button id="color-button-green" class="btn btn-secondary">Green</button>
                <button id="color-button-none" class="btn btn-secondary">None</button>
            </nav>
        </div>
        <main class="row mt-4">
            <section class="col-sm-10 offset-sm-1 list-group">
                <article class="list-group-item">
                    <h5>A Blog Post</h5>
                    <p>Hide at bottom of staircase to trip human. Ask for petting. Roll on the floor purring your whiskers off. Trip on catnip nap all day, eat too much then proceed to regurgitate all over living room carpet while humans eat dinner nya nya nyan. Attack the child groom yourself 4 hours - checked, have your beauty sleep 18 hours - checked, be fabulous for the rest of the day - checked playing with balls of wool.</p>
                </article>
            </section>
        </main>
        <div class="row">
            <div class="col-sm-10 offset-sm-1 text-right">
                <button class="btn btn-secondary" id="add-post">Add Post</button>
                <button class="btn btn-secondary" id="remove-post">Remove Last Post</button>
            </div>
        </div>
    </div>
    <script src="scripts.js"></script>
</body>
</html>
              
            
!

CSS

              
                .blue-background {
    background-color: #092E5C;
}

.brown-background {
    background-color: #B54135;
}

.green-background {
    background-color: #63750B;
}
              
            
!

JS

              
                // Get access to DOM elements
const header = document.querySelector('header');
const blueButton = document.getElementById('color-button-blue');
const brownButton = document.getElementById('color-button-brown');
const greenButton = document.getElementById('color-button-green');
const noneButton = document.getElementById('color-button-none');

const addPostButton = document.getElementById('add-post');
const articleSection = document.querySelector('section');

// Click event listeners
blueButton.addEventListener('click', () => {
    header.classList.remove('brown-background', 'green-background');
    header.classList.add('blue-background', 'text-white');
}); 

brownButton.addEventListener('click', () => {
    header.classList.remove('blue-background', 'green-background');
    header.classList.add('brown-background', 'text-white');
});

greenButton.addEventListener('click', () => {
    header.classList.remove('blue-background', 'brown-background');
    header.classList.add('green-background', 'text-white');
});

noneButton.addEventListener('click', () => {
    header.classList.remove('blue-background', 'brown-background', 'green-background', 'text-white');
});

addPostButton.addEventListener('click', () => {
    const newPost = createNewPost();
    articleSection.appendChild(newPost);
});

// Page functions
function createNewPost() {
  let newArticle = document.createElement('article');
  let newHeading = document.createElement('h5');
  let newParagraph = document.createElement('p');
  
  newHeading.textContent = 'Another blog post!';
  newParagraph.textContent = 'Love me! gnaw the corn cob intently sniff hand meow for food, then when human fills food dish, take a few bites of food and continue meowing really likes hummus meow all night having their mate disturbing sleeping humans. Run in circles pose purrfectly to show my beauty for when owners are asleep, cry for no apparent reason sit by the fire or lies down or paw at your fat belly.';
  
  newArticle.appendChild(newHeading);
  newArticle.appendChild(newParagraph);
  
  newArticle.classList.add('list-group-item');
  return newArticle;
}
              
            
!
999px

Console