Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ 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

Auto Save

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

              
                <h2>Weekly Coding Challenge #16 - Notifications</h2>
<div class="notification-container" id="notification-container">
	<div class="notification notification-info">
		<strong>Info:</strong> Lorem ipsum dolor sit amet.
	</div>

	<div class="notification notification-success">
		<strong>Success:</strong> Lorem ipsum dolor sit amet consectetur adipisicing elit.
	</div>

	<div class="notification notification-warning">
		<strong>Warning:</strong> Lorem ipsum dolor sit amet, consectetur adipisicing.
	</div>

	<div class="notification notification-danger">
		<strong>Danger:</strong> Lorem ipsum dolor sit amet consectetur.
	</div>
</div>

<footer>
	<p>
		Created with <i class="fa fa-heart"></i> by
		<a target="_blank" href="https://florin-pop.com">Florin Pop</a>
		- Read how I created this and how you can join the challenge
		<a target="_blank" href="https://www.florin-pop.com/blog/2019/06/how-to-create-a-notification-box">here</a>
	</p>
</footer>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Roboto:400,500&display=swap');

* {
	box-sizing: border-box;
}

body {
	background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
	
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;

	min-height: 100vh;
	font-family: 'Roboto', sans-serif;
	margin: 0;
}

h2 {
	text-align: center;
}

.notification-container {
	position: fixed;
	top: 15px;
	right: 15px;
	width: 500px;
	max-width: calc(100% - 30px);
}

.notification {
	background-color: #fff;
	border-radius: 5px;
	box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
	color: #fff;
	font-size: 16px;
	padding: 15px 20px;
	line-height: 20px;
	margin-bottom: 15px;
	animation: grow 0.5s ease-in forwards;
}

@keyframes grow {
	from {
		opacity: 0;
		transform: scale(0.8);
	}
	to {
		opacity: 1;
		transform: scale(1);
	}
}

.notification.hide {
	animation: shrink 0.3s ease-out forwards;
}

@keyframes shrink {
	to {
		opacity: 0;
		transform: scale(0.8);
	}
}

.notification strong {
	font-size: 12px;
	line-height: 20px;
	letter-spacing: 0.5px;
	text-transform: uppercase;
}

.notification-info {
	background-color: #00cae3;
}

.notification-success {
	background-color: #55b559;
}

.notification-warning {
	background-color: #ff9e0f;
}

.notification-danger {
	background-color: #f55145;
}

footer {
    background-color: #222;
    color: #fff;
    font-size: 14px;
    bottom: 0;
    position: fixed;
    left: 0;
    right: 0;
    text-align: center;
    z-index: 999;
}

footer p {
    margin: 10px 0;
}

footer i {
    color: red;
}

footer a {
    color: #3c97bf;
    text-decoration: none;
}
              
            
!

JS

              
                const notificationContainer = document.getElementById('notification-container');
const NOTIFICATION_TYPES = {
	INFO: 'info',
	SUCCESS: 'success',
	WARNING: 'warning',
	DANGER: 'danger'
}

function addNotification(type, text) {
    // create the DIV and add the required classes
    const newNotification = document.createElement('div');
    newNotification.classList.add('notification', `notification-${type}`);

    const innerNotification = `
		<strong>${type}:</strong> ${text}
	`;

    // insert the inner elements
    newNotification.innerHTML = innerNotification;

    // add the newNotification to the container
    notificationContainer.appendChild(newNotification);

    return newNotification;
}

function removeNotification(notification) {
	notification.classList.add('hide');

	// remove notification from the DOM after 0.5 seconds
	setTimeout(() => {
		notificationContainer.removeChild(notification);
	}, 500);
}

// adding and removing notification for DEMO purposes
const info = addNotification(NOTIFICATION_TYPES.INFO, 'Info text added');
setTimeout(() => {
	removeNotification(info);
}, 5000);

setTimeout(() => {
	const success = addNotification(NOTIFICATION_TYPES.SUCCESS, 'You are the boss!');
	setTimeout(() => {
		removeNotification(success);
	}, 5000);
}, 1000);

setTimeout(() => {
	const warning = addNotification(NOTIFICATION_TYPES.WARNING, 'Be careful!');
	setTimeout(() => {
		removeNotification(warning);
	}, 5000);
}, 2200);

setTimeout(() => {
	const danger = addNotification(NOTIFICATION_TYPES.DANGER, 'Noooooooo!');
	setTimeout(() => {
		removeNotification(danger);
	}, 5000);
}, 3700);
              
            
!
999px

Console