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.
<div class="row" id="EventDate">
<label for="Date">Event date <em class="asterisk"><span>*</span></em></label>
<div class="selectmenu xsmall-type1 inputDOB">
<select id="Date" name="EventDateDay" aria-required="true" class="js-selectmenu" data-val-required="Please tell us your event date" data-val="true">
<option value="">DD</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
</div>
<div class="selectmenu xsmall-type1 inputDOB">
<select id="Month" name="EventDateMonth" aria-required="true" class="js-selectmenu" data-val-required="Please tell us your full date of birth" data-val="true">
<option value="">MM</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
</div>
<input id="EventYear"
type="text"
name="EventYear"
class="form_input--inline inputDOB"
aria-required="true"
placeholder="YYYY"
data-val-required="Please tell us your full date of birth"
data-val-length-max="4" data-val-regex="Event Date is invalid."
data-val-length="Event Date must be less than 4 characters."
data-val-daymonthyear="{0} is required."
data-val-regex-pattern="^[0-9]*$"
maxlength="4"
data-val="true" />
<div class="error-message" role="alert">
<div class="error-text">
<p><span class="field-validation-valid" data-valmsg-for="DOB" data-valmsg-replace="true">Please tell us your event date</span></p>
<img src="http://res.cloudinary.com/df821af5o/image/upload/v1499521750/mcr-error-bg_wfz31v.png" alt="">
</div>
</div>
<div class="inline-error-message">
<div class="error-text">
<p></p>
</div>
</div>
</div>
<div class="row" id="EventDateEnd">
<label for="DateEnd">Event End Date (optional) </label>
<div class="selectmenu xsmall-type1 inputDOB">
<select id="DateEnd" name="EventFullDateEnd" class="js-selectmenu" data-val="true">
<option value="">DD</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
</div>
<div class="selectmenu xsmall-type1 inputDOB">
<select id="MonthEnd" name="EventFullDateEnd" class="js-selectmenu" data-val="true">
<option value="">MM</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
</div>
<input id="EventYearEnd"
type="text"
name="EventFullDateEnd"
class="form_input--inline inputDOB"
placeholder="YYYY"
data-val-length-max="4" data-val-regex="Event Date is invalid."
data-val-length="Event Date must be less than 4 characters."
data-val-daymonthyear="{0} is required."
data-val-regex-pattern="^[0-9]*$"
maxlength="4"
data-val="true" />
<div class="error-message" role="alert">
<div class="error-text">
<p><span class="field-validation-valid" data-valmsg-for="EventFullDateEnd" data-valmsg-replace="true">Please tell us your event end date</span></p>
<img src="http://res.cloudinary.com/df821af5o/image/upload/v1499521750/mcr-error-bg_wfz31v.png" alt="">
</div>
</div>
<div class="inline-error-message">
<div class="error-text">
<p></p>
</div>
</div>
</div>
.macmillan-form .field .error-text {
color: #FFF;
display: block;
font-size: 14px;
padding: 10px;
position: relative;
z-index: 2;
}
.error-handler .error-text {
color: #FFF;
display: block;
font-size: 14px;
padding: 10px;
position: relative;
z-index: 2;
}
.error-handler .error-text img {
width: 100%;
height: 100%;
top: 0;
right: 0;
position: absolute;
z-index: -1;
}
error-handler .error-text p {
font-size: 1em;
margin: 0;
}
.error-handler .error-message {
display: block !important;
margin: 0;
max-width: 454px;
width: 100%;
z-index: 2;
}
.error-message {
position: relative;
padding-top: 15px;
display: none;
}
.error-message {
position: relative;
padding-top: 15px;
display: none;
}
//Event date validation starts here
var validEventDate = true;
$('#Date, #Month, #EventYear').on('change', function() {
if (validateEventDate()) {
if ($('#DateEnd').val() === "" && $('#MonthEnd').val() === '' && $('#EventYearEnd').val() === '') {
handleErrorMessage(true)
validEventDate = true
console.log("error2-1")
} else {
var startDate1 = new Date($('#EventYear').val() + '-' + $('#Month').val() + '-' + $('#Date').val())
var endDate1 = new Date($('#EventYearEnd').val() + '-' + $('#MonthEnd').val() + '-' + $('#DateEnd').val())
if (endDate1 >= startDate1) {
handleErrorMessage(true)
validEventDate = true;
//added later
handleErrorMessageEnd(true)
validEventDateEnd = true;
console.log("error2-2")
} else {
validEventDateEnd = false;
//handleErrorMessageLessthan(false);
handleErrorMessageEnd(false)
console.log("error2-3")
}
//handleErrorMessageEnd(true)
//validEventDateEnd = true;
handleErrorMessage(true)
validEventDate = true;
console.log("special-error1")
}
} else {
handleErrorMessage(false)
validEventDate = false
console.log("error2-4")
}
})
function handleErrorMessage(op) {
if (!op) {
$('#EventDate').addClass('error-handler')
$('#EventDate').find('.error-message').find('.error-text p').html('Please enter a valid event date.')
} else {
$('#EventDate').removeClass('error-handler')
$('#EventDate').find('.error-message').find('.error-text p').html('')
}
}
function handleErrorMessageLessthan(op) {
if (!op) {
$('#EventDate').addClass('error-handler')
$('#EventDate').find('.error-message').find('.error-text p').html('Please enter a valid event date less than event end date.')
} else {
$('#EventDate').removeClass('error-handler')
$('#EventDate').find('.error-message').find('.error-text p').html('')
}
}
function validateEventDate() {
var $day = $('select[id="Date"] option:selected'),
$month = $('select[id="Month"] option:selected'),
$year = $('input[id="EventYear"]'),
dayStr = $day.text(),
monthStr = $month.text(),
yearStr = $year.val(),
dayIndex = $day.index(),
monthIndex = $month.index(),
yearIndex = yearStr;
if (dayIndex > 0 || monthIndex > 0 || yearIndex > 0) {
if (dayIndex > 0 && monthIndex > 0 && yearIndex > 0) {
if (dayIndex > 29 && monthIndex == 2) {
return false
}
if ((dayIndex > 30) && (monthIndex == 4 || monthIndex == 6 || monthIndex == 9 || monthIndex == 11)) {
return false
}
eventDate = new Date(yearStr + '/' + monthStr + '/' + dayStr);
nowDate = new Date();
var holidays = [new Date("2017/12/25"), new Date("2017/12/26"), new Date("2017/12/27")];
if (isNaN(eventDate)) {
return false;
} else {
if (eventDate < nowDate || eventDate.getDay() === 6 || eventDate.getDay() === 0 ) {
return false;
} else {
// var eventHoliday = holidays.filter(function(holiday) {
// return holiday === eventDate
// });
for (var i = 0; i < holidays.length; i++) {
if (eventDate.getTime() === holidays[i].getTime()) {
return false;
}
}
// for (var i = 0; i < holidays.length; i++) {
// if (eventDate.getTime() !== holidays[i].getTime()) {
// console.log('foo');
// return true
// } else {
// return false
// }
// }
// if (!!eventHoliday) {
// return false
// } else {
// return true
// }
return true
}
}
} else {
return false;
}
} else {
return false;
}
}
//Event date validation ends here
//Event End date validation starts here
var validEventDateEnd = true;
$('#DateEnd, #MonthEnd, #EventYearEnd').on('change', function() {
if (validateEventDateEnd()) {
if ($('#Date').val() === "" && $('#Month').val() === '' && $('#EventYear').val() === '') {
handleErrorMessage(false)
validEventDate = false;
console.log("error0")
} else {
var startDate = new Date($('#EventYear').val() + '-' + $('#Month').val() + '-' + $('#Date').val())
var endDate = new Date($('#EventYearEnd').val() + '-' + $('#MonthEnd').val() + '-' + $('#DateEnd').val())
console.log("error1")
if (endDate >= startDate) {
handleErrorMessageEnd(true)
validEventDateEnd = true;
console.log("error2")
} else {
handleErrorMessageEnd(false)
validEventDateEnd = false;
console.log("special-error2")
}
console.log("error3")
}
} else {
if ($('#DateEnd').val() === "" && $('#MonthEnd').val() === '' && $('#EventYearEnd').val() === '') {
if (validateEventDate() ) {
handleErrorMessage(true)
validEventDate = true;
console.log("error4-1")
} else {
handleErrorMessageEnd(false)
validEventDateEnd = false;
console.log("error4-2")
}
handleErrorMessageEnd(true)
validEventDateEnd = true;
console.log("error4")
} else {
handleErrorMessageEnd(false)
validEventDateEnd = false;
console.log("error5")
}
}
})
function handleErrorMessageEnd(op) {
if (!op) {
$('#EventDateEnd').addClass('error-handler')
$('#EventDateEnd').find('.error-message').find('.error-text p').html('Please enter a valid event end date greater or same than the event date.')
} else {
$('#EventDateEnd').removeClass('error-handler')
$('#EventDateEnd').find('.error-message').find('.error-text p').html('')
}
}
function validateEventDateEnd() {
var $day = $('select[id="DateEnd"] option:selected'),
$month = $('select[id="MonthEnd"] option:selected'),
$year = $('input[id="EventYearEnd"]'),
dayStr = $day.text(),
monthStr = $month.text(),
yearStr = $year.val(),
dayIndex = $day.index(),
monthIndex = $month.index(),
yearIndex = yearStr;
if (dayIndex > 0 || monthIndex > 0 || yearIndex > 0) {
if (dayIndex > 0 && monthIndex > 0 && yearIndex > 0) {
if (dayIndex > 29 && monthIndex == 2) {
return false
}
if ((dayIndex > 30) && (monthIndex == 4 || monthIndex == 6 || monthIndex == 9 || monthIndex == 11)) {
return false
}
eventDate = new Date(yearStr + '/' + monthStr + '/' + dayStr);
nowDate = new Date();
if (isNaN(eventDate)) {
return false;
} else {
if (eventDate < nowDate) {
return false;
} else {
return true
}
}
} else {
return false;
}
} else {
return false;
}
}
//Event End date validation ends here
function navigateToError() {
var errorDiv = $('.error-message:visible').first();
var scrollPosition = errorDiv.offset().top - 60;
$(window).scrollTop(scrollPosition);
}
// For all steps-forms and other forms -Enter key disble submit forms
$('.js-macmillan-stepped-form input').on('keyup keypress', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) {
e.preventDefault();
return false;
}
});
Also see: Tab Triggers