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.
<header>
<div class="banner"><h1> <i class="fas fa-plane"></i> Travel App</h1></div>
</header>
<div class="container">
<form action="" id="add-place">
<h2 id="form-header"><i class="fas fa-globe-europe"></i> Add Place</h2>
<fieldset>
<label for="country">Country:</label>
<input type="text" name="country" id="country" placeholder="Type a country name.." required="required" />
</fieldset>
<fieldset>
<label for="city">City:</label>
<input type="text" name="city" id="city" placeholder="Type a city name..." required="required" />
</fieldset>
<fieldset>
<legend>Select If you have visted</legend>
<input type="radio" id="visited" name="choice" value="true"/>
<label for="visited">Visited</label>
<input type="radio" id="unvisited" name="choice" checked value="false"/>
<label for="unvisited">Unvisited</label>
</fieldset>
<fieldset>
<label for="fav">Favourite:</label>
<input type="checkbox" name="fav" id="fav" checked>
</fieldset>
<fieldset>
<label for="date">Date if Visited:</label>
<input type="date" name="date" id="date">
</fieldset>
<fieldset>
<label for="image">Image URL:</label>
<input type="text" name="image" id="image" placeholder="add an image url.." required="required" />
</fieldset>
<input type="submit" id="submit" value="Add to list" />
</form>
<div class="placesContainer">
<h3>My Places</h3>
<p class="noplacesAdded">Nothing added yet!</p>
<div class="my-places">
<!-- places get added here -->
</div>
</div>
</div>
<footer>
<small>Designed and Developed with hand-coded Love by Aimee ♥ 2018</small>
</footer>
@import url('https://fonts.googleapis.com/css?family=Do+Hyeon|Lato:400,700');
html {
font-size: 10px;
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
font-family: 'Lato', sans-serif;
color: black;
font-size: 2rem;
background: #d1d1d1;
}
h1, h2, h3 {
font-family: 'Do Hyeon', sans-serif;
margin: 0;
padding: 0;
}
header {
color: white;
text-align: center;
padding: 3rem;
background-color: black;
}
.container {
width: 90%;
margin: 0 auto;
}
#add-place {
width: 100%;
background-color: #e5e5e5;
padding: 2rem;
#form-header {
background-color:black;
color: white;
height: auto;
padding: 2rem;
}
label {
font-size: 1.6rem;
font-weight: bold;
}
input:focus {
outline: 2px solid #a4d4a4;
}
input[type='text'], input[type='date'] {
width: 100%;
margin: .5rem 0;
padding: .5rem;
border:none;
}
input[type='radio'] {
padding: 0 3rem;
}
fieldset {
border: 1px dashed #a4d4a4;
margin: 2rem 0;
}
input[type='submit'] {
border:none;
padding: 1rem 2rem;
background-color: #a4d4a4;
color: white;
transition: all .5s ease-out;
&:hover {
background-color: darken(#a4d4a4, 20%);
}
}
}
// PLACES CONTAINER ====
.placesContainer {
background-color: white;
padding: 2rem;
h3 {
margin-bottom: 1em;
}
}
.my-places {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-gap: 2em;
.place {
border: 2px solid #a4d4a4;
padding: 1rem;
max-width: 400px;
}
img {
width:100%;
}
}
footer {
background-color: silver;
padding: 3rem;
text-align: center;
small {
font-size: 1.2rem;
}
}
let submitFormData = document.querySelector('#submit');
let radioBtns = document.getElementsByName('choice');
let myPlaces = document.querySelector('.my-places');
let placesPara = document.querySelector('.noplacesAdded');
// VARS
let country, image, city, date, fav, radioChoice, reverseDate, wantToGo;
// function that loops Radio buttons and gets the checked one for vitisted of unvisited.
function getRadioValue() {
let choice;
radioBtns.forEach((btn)=>{
if(btn.checked){
choice = btn.value;
//console.log(`your choice is ${choice}`);
}
});
return choice;
}
// LocalStorage is not enabled in CodePen for security reasons ====
// Check Local Storage for Data on Page Reload or use empty array.
// let allEntries = JSON.parse(document.localStorage.getItem("allEntries")) || [];
let allEntries = [];
// LocalStorage is not enabled in CodePen for security reasons ====
// CHECK IF THERE IS ANYTHING IN LOCAL STORAGE!!! ====
// if(document.localStorage.getItem("allEntries") !== null){
// console.log('entries in localstorage');
/// Loop through the array of entries to display on the Screen...
allEntries.map((entry, i) => {
const {country, city, fav, imageUrl, visited, date} = entry;
// - hide paragraph saying no places.
placesPara.style.display = 'none';
wantToGo = `${visited === 'Been' ? true : false}`;
let content = `<section class="place">
<img src="${imageUrl}" / alt="photo">
<p><span class="country">Country: ${country}</span><br/>
<span class="city">City: ${city}</span></br>
<span class="fav">${fav ? 'Favourite: ❤️' : ''}</span></br>
<span class="wanttogo">Visited/Unvisted: ${visited ? 'Been' : 'Wish'}</span></br>
<span class="date"> ${visited ? '<span class="date">Date Visited:' + ' ' + date + '</span>' : ''}</span></br>
</p></section>`
// adding the new content each time added to the existing content.
myPlaces.innerHTML += content;
})
// }
// ADDING PLACE FUNCTION =============
function placeAdded() {
// - hide paragraph saying no places.
placesPara.style.display = 'none';
// // create a new section -----
let content = `<section class="place">
<img src="${image}" / alt="photo">
<p><span class="country">Country: ${country}</span><br/>
<span class="city">City: ${city}</span></br>
<span class="fav">${fav ? 'Favourite: ❤️' : ''}</span></br>
<span class="wanttogo">Visited/Unvisted: ${wantToGo ? 'Been' : 'Wish'}</span></br>
${wantToGo ? '<span class="date">Date Visited:' + ' ' + reverseDate + '</span>' : ''}
</p></section>`
// adding the new content each time added to the existing content.
myPlaces.innerHTML += content;
}
// LocalStorage is not enabled in CodePen for security reasons ====
// SORT OUT ADDDING AND ARRAY THAT STAYS UPDATED AND DOESN'T Empty on refresh...
// Add data to localStorage ----
// function addLocalStorage(arr) {
// document.localStorage.setItem("allEntries", JSON.stringify(arr));
// }
//Check Errors of Form ===
function errorCheck(){
if(document.querySelector('#country').value == "" || document.querySelector('#city').value == "" || document.querySelector('#image').value === "") {
console.log('these fields are required!')
}
}
// Getting Values from Add Place Form =============
submitFormData.addEventListener('click', (e) => {
errorCheck()
e.preventDefault();
country = document.querySelector('#country').value;
city = document.querySelector('#city').value;
date = document.querySelector('#date').value;
image = document.querySelector('#image').value;
//Split the Date by the -, so you get an array of year, month, day
let splitDate = date.split("-");
// then reverse the array, so you will get a date
reverseDate = splitDate.reverse();
// call function to check if been or wish for visited.
radioChoice = getRadioValue();
wantToGo = radioChoice === 'true' ? true : false;
fav = document.querySelector('#fav').checked;
let entry = {
country: country,
city: city,
visited: wantToGo,
fav: fav,
date: reverseDate,
imageUrl: image
}
// allEntries.push(entry);
// function that added data to DOM
placeAdded();
// LocalStorage is not enabled in CodePen for security reasons ====
// Add to local storage function
// addLocalStorage(allEntries);
})
Also see: Tab Triggers