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 URL's 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 it's URL and the proper URL extention.
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.
%html{"ng-app" => "swankyChat", "ng-cloak" => "true"}
.container
.inbox
%aside
%ul{"ng-controller" => "chatCtrl as chat"}
%div{"ng-repeat" => "chat in chats"}
%li{"ng-click" => "uid(chat.id)"}
%img{:class => "avatar", :src => "{{chat.avatar}}"}
%p{:class => "username"} {{chat.username}}
%main{"ng-controller" => "chatCtrl as chat"}
.init
%i{:class => "fa fa-inbox"}
%h4 Choose a conversation from the left
.loader
%p
%h4 Loading
/ Set A Ng Repeat For Our Messages || Check To See If Our Value (Which Is Set Via Ng Click) Is Equal To The Id Of The Message List We Want To Show
.message-wrap{"ng-repeat" => "message in chats", "ng-show" => "value == message.id"}
/ Repeat Each Item In The Array Seperately
.message{"ng-repeat" => "i in message.messages track by $index"}
%p {{i}}
%img{'ng-src' => "{{message.avatar}}"}
%footer
%form{"ng-submit" => "add()"}
%input{:type => "text", :placeholder => "Enter a message", "ng-model" => "text"}
%input{:type => "submit", :value => "Send"}
// Variables
$bg-color: #2EC4B6;
$inbox-primary: #EDF2F4;
$inbox-secondary: lighten($bg-color, 7%);
$inbox-width: 650px;
$inbox-height: 450px;
$inbox-radius: 4px;
// Universal Selector
* {
margin: 0; padding: 0;
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
}
// Default Styles
html,body {
background: linear-gradient(180deg, $bg-color, #9EB1E9);
overflow-x: hidden;
}
// Container
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
// Inbox Styles
.inbox {
background: $inbox-primary;
width: $inbox-width;
height: $inbox-height;
display: flex;
border-radius: $inbox-radius;
// Aside Styles
aside {
background: $inbox-secondary;
flex: 1 1 auto;
height: 100%;
border-top-left-radius: $inbox-radius;
border-bottom-left-radius: $inbox-radius;
.avatar {
width: 30px;
height: 30px;
border: 2px solid #FFF;
border-radius: 100%;
}
// Li Elements In Aside
li {
background: darken($inbox-secondary, 3%);
list-style: none;
color: #FFF;
display: flex;
justify-content: space-between;
padding: 0 2em;
align-items: center;
height: 5em;
font-size: 0.8em;
cursor: pointer;
border-bottom: 1px solid lighten($inbox-secondary, 2%);
border-top-left-radius: $inbox-radius;
&:hover {
background: darken($inbox-secondary, 5%);
}
}
}
// Our Main Content Where Conversations Will Be Listed
main {
background: $inbox-primary;
height: 100%;
flex: 1 1 70%;
border-top-right-radius: $inbox-radius;
border-bottom-right-radius: $inbox-radius;
transform: scale(1.035);
.message-wrap {
height: 88%;
overflow-y: scroll;
}
.message {
background: $inbox-secondary;
width: 70%;
margin: 1em 6em;
padding: 1em;
border-radius: $inbox-radius;
opacity: 1;
transition: opacity ease-in-out .45s;
p {
font-size: 0.68em;
color: #FFF;
font-weight: 300;
}
img {
width: 30px;
height: 30px;
border-radius: 100%;
transform: translateX(-70px) translateY(-20px);
float: left;
}
&:nth-of-type(even) {
background: darken($inbox-secondary, 6%);
margin: 1em 1em;
}
}
// Our Footer To Our Main Content, Contains The Submit Form
footer {
position: fixed;
bottom: 0;
height: 12%;
width: 100%;
display: flex;
align-items: center;
border-top: 1px solid darken($inbox-primary, 4%);
input[type="text"] {
border: none;
background: transparent;
padding: 0.8em;
outline: none;
color: #AAA;
width: 100%;
}
input[type="submit"] {
background: $inbox-secondary;
color: #FFF;
width: 17%;
border-radius: 4px;
padding: 0.8em;
margin: 0 1em;
border: none;
cursor: pointer;
appearance: none;
}
form {
width: 100%;
display: flex;
justify-content: space-between;
}
}
}
}
// Initial Start Up Screen
.init {
display: flex;
justify-content: center;
align-items: center;
flex-flow: column wrap;
height: 100%;
position: absolute;
left: 0;
right: 0;
z-index: -1;
text-align: center;
i {
font-size: 5em;
color: $inbox-secondary;
}
h4 {
margin: 1em auto;
color: $inbox-secondary;
}
}
// Custom Animation Loading Screen
.loader {
opacity: 0;
display: flex;
justify-content: center;
align-items: center;
flex-flow: column wrap;
height: 100%;
position: absolute;
margin: 0 auto;
left: 0;
right: 0;
z-index: -1;
text-align: center;
p {
background: $inbox-secondary;
width: 20px;
height: 20px;
border-radius: 100%;
animation: loading 2000ms cubic-bezier(0.470, 0.000, 0.745, 0.715) infinite;
&:before {
content: '';
background: $inbox-secondary;
width: 40px;
height: 40px;
opacity: 1;
display: block;
transform: translateX(-10px) translateY(-10px);
border-radius: 100%;
animation: loading 2000ms cubic-bezier(0.470, 0.000, 0.745, 0.715) infinite;
animation-delay: 50ms;
}
}
h4 {
margin: 1em auto;
color: $inbox-secondary;
}
}
// Loading Animation
@keyframes loading {
0% {
opacity: 0;
}
50% {
opacity: 0.7;
}
100% {
opacity: 0;
}
}
// Custom Scrollbars
::-webkit-scrollbar {
width: 0px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.1);
}
angular.module("swankyChat", [])
// Set Up Chat Controller
.controller("chatCtrl", function($scope, $timeout, $rootScope) {
$scope.chats = [{
id: 0,
username: "Leela",
avatar: "https://imgflip.com/s/meme/Futurama-Leela.jpg",
messages: [
"I can explain. It's very valuable. You won't have time for sleeping, soldier, not with all the bed making you'll be doing",
"Who am I making this out to? We'll go deliver this crate like professionals, and then we'll go home",
"No! The cat shelter's on to me. I never loved you",
"Oh Leela! You're the only person I could turn to",
"Um, is this the boring, peaceful kind of taking to the streets",
"That's right, baby. I ain't your loverboy Flexo, the guy you love so much. You even love anyone pretending to be him!"
]
}, {
id: 1,
username: "Bender",
avatar: "http://orig02.deviantart.net/9689/f/2012/027/9/c/mr_bender______classy__by_sgtconker1r-d4nqpzu.png",
messages: [
"Stop! Don't shoot fire stick in space canoe! Cause explosive decompression!",
"Fry! Stay back! He's too powerful! You guys aren't Santa!",
"Hi, I'm a naughty nurse, and I really need someone to talk to. $9.95 a minute",
"Who are you, my warranty?!",
"I will destroy you"
]
}, {
id: 2,
username: "Fry",
avatar: "http://www.wallpaperno.com/thumbnails/detail/20121027/futurama%20fry%201920x1080%20wallpaper_www.wallpaperno.com_68.jpg",
messages: [
"Ooh, name it after me! But I've never been to the moon!",
"You don't know how to do any of those",
"The key to victory is discipline, and that means a well made bed",
"Stop bickering or I'm going to come back there and change your opinions manually",
"Can we have Bender Burgers again"
]
}, {
id: 3,
username: 'Zoidberg',
avatar: "http://images2.fanpop.com/images/photos/3300000/Zoidberg-futurama-3305418-1024-768.jpg",
messages: [
"All I want is to be a monkey of moderate intelligence who wears a suit",
"Oh, I don't have time for this",
"No! The kind with looting and maybe starting a few fires!",
"Now, now. Perfectly symmetrical violence never solved anything",
"Dissect its brain"
]
}];
// Assign Pushed Messages To A User
$scope.text;
$scope.add = function() {
var vlu = $scope.value;
if($scope.text) {
$scope.chats[vlu].messages.push(this.text);
$scope.text = '';
console.log(vlu);
}
}
// Setting The Value Scope Equal To The Chat.id Which Is Retrieved Via Ng Click - We Pass The Chat.id Through The Function
$scope.value;
$scope.uid = function(ix) {
console.log(ix);
function ixy() {
$rootScope.value = ix;
}
// Delay Our Scope Change To Create A Smoother Transition
$timeout(ixy, 750);
}
});
// Animation Styles
$(function() {
var index = 0;
function initScroll() {
$(".message-wrap").animate({
scrollTop: $("main").height()
}, 1000);
}
function scroll() {
$(".message-wrap").animate({
scrollTop: 9000
}, 1000);
}
$("input[type='submit']").click(function() {
scroll();
});
$("aside").find("li").click(function() {
initScroll();
$(".init").animate({
'opacity': '0'
}, 500);
});
$("aside").find("li").click(function() {
if (index == 1) {
index = 0;
$(".message-wrap").find(".message").css({
'opacity': '1'
});
} else {
index = 0;
$(".message-wrap").find(".message").css({
'opacity': '0'
});
$(".loader").delay(500).animate({
'opacity': '1'
});
setTimeout(function() {
index = 0;
$(".message-wrap").find(".message").css({
'opacity': '1'
});
$(".loader").animate({
'opacity': '0'
});
}, 3000)
}
});
});
Also see: Tab Triggers