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.
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sheep Weather App</title>
<meta name="author" content="Top section graphics and turn mobile icon are designed by Freepik (http://www.freepik.com/), weather icons come from http://forecastfont.iconvau.lt/ (designed by https://twitter.com/alisisk). The Sheep Weather App is designed and coded by the doer.">
<meta name="description" content="The project created during Free Code Camp course">
</head>
<body>
<section class="top">
<div class="pull-right toggle">
<label class="checkbox-inline">
<input id="toggle" type="checkbox" checked data-toggle="toggle" data-on="Celsius" data-off="Fahrenheit" data-onstyle="info" data-offstyle="warning" data-style="toggle-pace">
</label>
</div>
</section>
<section class="middle">
<div id="more-info-box" class="parent">
<div class="cell text-center">
<div id="wind">
<p>Wind: <span></span></p>
</div>
<div id="humidity">
<p>Humidity: <span></span></p>
</div>
<div id="description">
<p>Weather Sheep says:<br/><span></span></p>
</div>
</div> <!-- cell -->
</div>
</section>
<section class="bottom">
<div id="more-btn" class="more" aria-labelledby="more weather information" tabindex="0">
More
</div>
<div class= "container-fluid">
<div id="weather-box" class="info-box row hidden">
<div id="data" class="col-xs-6 col-xs-offset-1 col-md-5 col-md-offset-1">
<div id="city"></div>
<div id="temperature">
<span id="number"></span>
</div>
</div> <!-- col weather details -->
<div class="col-xs-5">
<ul class = "weather-icon hidden" id="01d">
<li class = "icon-sun"></li>
</ul>
<ul class = "weather-icon hidden" id="01n">
<li class = "icon-moon"></li>
</ul>
<ul class = "weather-icon hidden" id="02d">
<li class = "basecloud"></li>
<li class = "icon-sunny"></li>
</ul>
<ul class = "weather-icon hidden" id="02n">
<li class = "basecloud"></li>
<li class = "icon-night"></li>
</ul>
<ul class = "weather-icon hidden" id="03d">
<li class = "basecloud"></li>
<li class = "icon-sunny"></li>
</ul>
<ul class = "weather-icon hidden" id="03n">
<li class = "basecloud"></li>
<li class = "icon-night"></li>
</ul>
<ul class = "weather-icon hidden" id="04d">
<li class = "icon-cloud"></li>
</ul>
<ul class = "weather-icon hidden" id="04n">
<li class = "icon-cloud"></li>
</ul>
<ul class = "weather-icon hidden" id="09d">
<li class = "basecloud"><li>
<li class = "icon-showers icon-sunny"></li>
</ul>
<ul class = "weather-icon hidden" id="09n">
<li class = "basecloud"><li>
<li class = "icon-showers icon-night"></li>
</ul>
<ul class = "weather-icon hidden" id="10d">
<li class = "basecloud"></li>
<li class = "icon-rainy"></li>
</ul>
<ul class = "weather-icon hidden" id="10n">
<li class = "basecloud"></li>
<li class = "icon-rainy icon-night"></li>
</ul>
<ul class = "weather-icon hidden" id="11d">
<li class = "basethundercloud"></li>
<li class = "icon-thunder"></li>
</ul>
<ul class = "weather-icon hidden" id="11n">
<li class = "basethundercloud"></li>
<li class = "icon-thunder icon-night"></li>
</ul>
<ul class = "weather-icon hidden" id="13d">
<li class = "basecloud"></li>
<li class = "icon-snowy"></li>
</ul>
<ul class = "weather-icon hidden" id="13n">
<li class = "basecloud"></li>
<li class = "icon-snowy icon-night"></li>
</ul>
<ul class = "weather-icon hidden" id="50d">
<li class = "icon-mist"></li>
</ul>
<ul class = "weather-icon hidden" id="50n">
<li class = "icon-mist"></li>
</ul>
</div> <!-- col weather icon -->
</div> <!-- info-box details --->
<div id="intro-text" class="info-box row">
<div class="col-xs-12 text-center">
<h1>Sheep Weather App</h1>
<p class="thanks">Graphics by <a href="http://www.freepik.com/" target="_blank">Freepik</a> and <a href="https://twitter.com/alisisk" target="_blank">Ali Sisk</a></p>
</div>
</div> <!-- info box intro, default state before positoion set -->
</div> <!-- container fluid -->
</section> <!-- bottom section -->
<section class="turn-around-mobile">
<div class="text-center">
<h2>Turn your phone vertically</h2>
</div>
</section>
</body>
</html>
html {
width: 100vw;
height: 100vh;
}
body {
width: 100%;
height: 100%;
background-color: lightblue;
color: #455A64;
}
.top {
height: 60vh;
width: 100vw;
background-image: url(http://theonewhodo.es/weatherapp-images/intro-screen.png);
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
/* top background sheep, day */
.top#top-01d {
background-image: url(http://theonewhodo.es/weatherapp-images/01d.png);
}
.top#top-02d {
background-image: url(http://theonewhodo.es/weatherapp-images/02d.png);
}
.top#top-03d {
background-image: url(http://theonewhodo.es/weatherapp-images/03d.png);
}
.top#top-04d {
background-image: url(http://theonewhodo.es/weatherapp-images/04d.png);
}
.top#top-09d {
background-image: url(http://theonewhodo.es/weatherapp-images/09d.png);
}
.top#top-10d {
background-image: url(http://theonewhodo.es/weatherapp-images/10d.png);
}
.top#top-11d {
background-image: url(http://theonewhodo.es/weatherapp-images/11d.png);
}
.top#top-13d {
background-image: url(http://theonewhodo.es/weatherapp-images/13d.png);
}
.top#top-50d {
background-image: url(http://theonewhodo.es/weatherapp-images/50d.png);
}
/* top background sheep, night */
.top#top-01n {
background-image: url(http://theonewhodo.es/weatherapp-images/01n.png);
}
.top#top-02n {
background-image: url(http://theonewhodo.es/weatherapp-images/02n.png);
}
.top#top-03n {
background-image: url(http://theonewhodo.es/weatherapp-images/03n.png);
}
.top#top-04n {
background-image: url(http://theonewhodo.es/weatherapp-images/04n.png);
}
.top#top-09n {
background-image: url(http://theonewhodo.es/weatherapp-images/09n.png);
}
.top#top-10n {
background-image: url(http://theonewhodo.es/weatherapp-images/10n.png);
}
.top#top-11n {
background-image: url(http://theonewhodo.es/weatherapp-images/11n.png);
}
.top#top-13n {
background-image: url(http://theonewhodo.es/weatherapp-images/13n.png);
}
.top#top-50n {
background-image: url(http://theonewhodo.es/weatherapp-images/50n.png);
}
/*extra cases*/
.top#top-windy {
background-image: url(http://theonewhodo.es/weatherapp-images/sunny-sheep.jpg);
}
.top#top-cold {
background-image: url(http://theonewhodo.es/weatherapp-images/sunny-sheep.jpg);
}
.top#top-hot {
background-image: url(http://theonewhodo.es/weatherapp-images/sunny-sheep.jpg);
}
.top#top-calm {
background-image: url(http://theonewhodo.es/weatherapp-images/sunny-sheep.jpg);
}
.bottom {
height: 40vh;
background-color: lightblue;
color: #FFF;
font-size: 1.5em;
}
.info-box {
padding: 1.5em 0 0;
font-size: 2em;
}
.toggle {
margin: 1em 1em 0 0;
visibility: hidden;
}
.toggle-pace .toggle-group {
transition: left 0.7s; -webkit-transition: left 0.4s;
}
.weather-icon {
font-size: 0.4em;
margin: -10px 0 0;
padding-left: 10px;
}
.weather-icon, .weather-icon li {
margin-bottom: 5px;
}
.weather-icon li {
list-style: none;
}
.icon-cloud::after {
content: "\f106";
color: #FFF;
}
.basecloud:before {
content: '\f105';
color: #FFF;
}
.turn-around-mobile {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #fff;
z-index: 1000;
display: none;
background: url(http://theonewhodo.es/weatherapp-images/mobile-vertical.png) no-repeat;
background-position: center center;
}
.turn-around-mobile h2 {
padding-top: 1em;
}
.more {
background-color: pink;
color: #FFF;
width: 70px;
height: 40px;
position: absolute;
left: 50%;
margin: 0 0 0 -35px;
border-radius: 0 0 10px 10px;
text-align: center;
border: 1px white dotted;
cursor: pointer;
}
.extra-info .more {
border-style: hidden dotted dotted dotted;
}
.middle {
position: absolute;
bottom: 40vh;
left: 0;
right: 0;
height: 0;
transition: height 0.5s;
background-color: pink;
border-radius: 20px 20px 0 0;
overflow: hidden;
}
.extra-info .middle {
height: 30vh;
transition: height 1.5s;
}
/* vertical align center*/
.parent {
display: table;
height: 100%;
width: 100%;
}
.cell {
display: table-cell;
vertical-align: middle;
position: relative;
}
.middle p > * {
font-weight: bold;
}
.thanks {
padding-top: 1em;
font-size: 12px;
}
#intro-text a {
color: #FFECB3;
}
/* media queries */
@media screen and (min-width: 768px){
.info-box {
padding: 2em;
font-size: 2.5em;
}
#data {
text-align: right;
}
.more {
font-size: 2em;
width: 170px;
height: 60px;
margin-left: -85px;
}
.middle p {
font-size: 1.8em;
}
}
@media only screen and (max-height: 415px) and (orientation: landscape){
.turn-around-mobile {
display: block;
}
section:not(.turn-around-mobile) {
display: none;
}
}
@media screen and (max-width: 767px) {
.info-box {
font-size: 1.5em;
text-align: left;
}
.middle p {
font-size: 1.5em;
}
}
@media screen and (min-width: 1200px) {
.middle {
width: 1000px;
position: absolute;
margin: 0 auto;
}
}
var userPosition = null;
// origin of 3 next variables acting as constants http://openweathermap.org/weather-conditions
var COLD = 903;
var HOT = 904;
var CALM = 951;
function savePosition (position) {
userPosition = position;
getWeather(position.coords.latitude, position.coords.longitude, "metric");
}
function getWeather (lat, lon, units) {
$.getJSON("https://procreative.eu/proxy/proxy.php?APPID=db4847852e5b0041310008ebb15c573a&units=" + units +"&lat=" + lat + "&lon=" + lon, function (result){
$("#city").html(result.name);
if (units=="metric") {
$("#number").html((result.main.temp|0) + "° C");
} else {
$("#number").html((result.main.temp|0) + " F");
}
// setting more info
if (units=="metric") {
$("#wind span").html((result.wind.speed|0) + " meters/sec");
} else {
$("#wind span").html((result.wind.speed|0) + " miles/hour");
}
$("#humidity span").html((result.main.humidity|0) + "%");
$("#description span").html(result.weather[0].description);
// setting the icon
$(".weather-icon").addClass("hidden");
$(".weather-icon#" + result.weather[0].icon).removeClass("hidden");
$("#weather-box").removeClass("hidden");
$("#intro-text").addClass("hidden");
// setting toggle ready
$('.toggle').css('visibility', 'visible');
// setting the top section background including situations without bottom section icons
$(".top").attr("id", "top-" + result.weather[0].icon);
if(result.weather[0].id >= 900 && result.weather[0].id !== COLD && result.weather[0].id !== HOT && result.weather[0].id !== CALM) {
$(".top").attr("id", "top-windy");
} else if (result.weather[0].id == COLD) {
$(".top").attr("id", "top-cold");
} else if (result.weather[0].id == HOT) {
$(".top").attr("id", "top-hot");
} else if (result.weather[0].id == CALM) {
$(".top").attr("id", "top-calm");
}
});
}
function accessibleToggle(checkbox, ariaLabel) {
var targetItem = checkbox.parent(".toggle.btn");
targetItem.attr({
"tabindex": 1,
"aria-label": ariaLabel
});
targetItem.on("keyup", function(e) {
//keyup in ASCII code == which
if(e.which == 13) {
checkbox.bootstrapToggle("toggle");
}
});
}
// make more accessible without changing and restyling to a link
function moreBtn() {
$("#more-btn").on("keyup", function(e) {
if(e.which == 13) {
$("#more-btn").trigger("click");
}
});
}
$(document).ready(function() {
accessibleToggle($("#toggle"), "change measure");
moreBtn();
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(savePosition, function(error) {
// the message when geolocation cannot be read
alert("Allow Geolocation On Your Device");
}, {
enableHighAccuracy: true,
timeout : 5000
});
}
$("#toggle").on("change", function(){
if ($(this).prop("checked")) {
getWeather (userPosition.coords.latitude, userPosition.coords.longitude, "metric");
} else {
getWeather (userPosition.coords.latitude, userPosition.coords.longitude, "imperial");
}
});
$(".more").on("click", function (){
$("body").toggleClass("extra-info");
if($("body").hasClass("extra-info")){
$(this).text("Less");
} else {
$(this).text("More");
}
});
});
Also see: Tab Triggers