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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
.wrapper
header
h1 今更ながら、モーダルを作ってみる
main
.content.content-1
p 吾輩は猫である。名前はまだ無い。
p どこで生れたかとんと見当がつかぬ。
p 何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。
a.modal-link(href="javascript:void(0)" data-id="modal-1") モーダル1を開く
.content.content-2
p 木曾路はすべて山の中である。
p あるところは岨づたいに行く崖の道であり、あるところは数十間の深さに臨む木曾川の岸であり、あるところは山の尾をめぐる谷の入り口である。
a.modal-link(href="javascript:void(0)" data-id="modal-2") モーダル2を開く
footer フッター
.modal
#modal-1.modal-inner
.modal-content
h2 モーダル1
figure
img(src="http://placeimg.com/1000/480/animals")
p 吾輩はここで始めて人間というものを見た。
p しかもあとで聞くとそれは書生という人間中で一番獰悪な種族であったそうだ。
p この書生というのは時々我々を捕えて煮て食うという話である。
a.modal-close(href="javascript:void(0)") 閉じる
#modal-2.modal-inner
.modal-content
h2 モーダル2
figure
img(src="http://placeimg.com/1000/480/nature")
p 一筋の街道はこの深い森林地帯を貫いていた。
p 東ざかいの桜沢から、西の十曲峠まで、木曾十一宿はこの街道に添うて、二十二里余にわたる長い谿谷の間に散在していた。
p 道路の位置も幾たびか改まったもので、古道はいつのまにか深い山間に埋もれた。
p 名高い桟も、蔦のかずらを頼みにしたような危い場処ではなくなって、徳川時代の末にはすでに渡ることのできる橋であった。
p 新規に新規にとできた道はだんだん谷の下の方の位置へと降って来た。
p 道の狭いところには、木を伐って並べ、藤づるでからめ、それで街道の狭いのを補った。
a.modal-close(href="javascript:void(0)") 閉じる
/* モーダル関連のスタイル*/
body {
&.modal-open {
overflow: hidden;
}
}
.wrapper {
.modal-open & {
position: fixed;
top: 0;
left: 0;
width: 100%;
}
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10;
background: rgba(#000, 0.7);
.modal-open & {
display: block;
}
&-inner {
display: none;
overflow-y: auto;
position: absolute;
top: 0;
height: 100%;
&#modal-1 {
justify-content: center;
align-items: center;
left: 0;
width: 100%;
padding: 0 10px;
&.active {
display: flex;
}
.modal-content {
width: 650px;
background: rgba(#fff, 0.5);
}
}
&#modal-2 {
right: 0;
width: 80%;
background: rgba(#fff, 0.5);
&.active {
display: block;
}
.modal-content {
width: 100%;
min-height: 100%;
}
}
}
&-content {
padding: 30px;
h2 {
padding: 0 0 10px;
border-bottom: 1px solid #32a238;
font-size: 28px;
}
p {
font-size: 16px;
line-height: 1.5;
}
figure {
img {
max-width: 100%;
height: auto;
}
}
}
&-close {
overflow: hidden;
position: fixed;
top: 20px;
right: 20px;
width: 30px;
height: 30px;
z-index: 10;
border-radius: 3px;
background: #fff;
text-indent: 200%;
white-space: nowrap;
box-shadow: 0 0 3px rgba(0,0,0,0.75);
transition: opacity 0.2s ease-in-out;
text-decoration: none;
&:hover {
opacity: 0.7;
}
&:before {
content: 'X';
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top:0;
left: 0;
width: 100%;
height: 100%;
color: #000;
font-size: 16px;
font-weight: bold;
text-indent: 0;
}
}
}
/* ここはただの箱のスタイル */
body {
display: flex;
flex-direction: column;
height: 100%;
font-family: "M PLUS Rounded 1c";
* {
box-sizing: border-box;
}
}
figure {
margin: 0;
}
.wrapper {
display: flex;
flex-direction: column;
position: relative;
min-height: 100vh;
z-index: 5;
}
header,
footer {
display: flex;
justify-content: center;
align-items: center;
padding: 0 10px;
background: #32a238;
color: #fff;
font-size: 40px;
font-weight: bold;
letter-spacing: 0.075em;
box-sizing: border-box;
}
header {
height: 100px;
h1 {
font-size: 30px;
}
}
footer {
height: 150px;
margin: auto 0 0;
font-size: 30px;
transform: translateY(0) !important;
}
main {
padding: 50px 10px;
}
.content {
max-width: 600px;
margin: 50px auto 0;
padding: 25px 20px;
border: 1px solid #32a238;
color: #32a238;
&:first-child {
margin-top: 0;
}
> *:first-child {
margin-top: 0;
}
p {
font-size: 20px;
line-height: 1.7
}
a {
display: flex;
justify-content: center;
align-items: center;
width: 200px;
height: 40px;
margin: 30px 0 0 auto;
border-radius: 5px;
background: #32a238;
color: #fff;
font-size: 20px;
text-decoration: none;
transition: opacity 0.2s ease-in-out;
&:hover {
opacity: 0.7;
}
}
}
(function(window, $) {
'use strict';
// Set Namespace
var APP = (window.APP = window.APP || {});
APP.SetModal = function($elm) {
var that = this;
that.$elm = $elm;
that.$body = $('body');
that.$wrapper = $('.wrapper');
that.$target = $('#'+$elm.data('id'));
that.$close = that.$target.find('.modal-close');
that.OPEN = 'modal-open';
that.ACTIVE = 'active';
$elm.on('click', function() {
that.open();
});
that.$close.on('click', function() {
that.close();
});
};
APP.SetModal.prototype = {
open: function() {
var that = this;
that.scrollTop = $(window).scrollTop();
that.$body.addClass(that.OPEN);
that.$target.addClass(that.ACTIVE);
that.$wrapper.css({ // 元の画面を
'top': -(that.scrollTop)
});
},
close: function() {
var that = this;
that.$body.removeClass(that.OPEN);
that.$target.removeClass(that.ACTIVE);
that.$wrapper.css({
'top': 0
});
$('html, body').prop({
scrollTop: that.scrollTop
});
}
};
$(function() {
$('.modal-link').each(function() {
new APP.SetModal($(this));
});
});
})(window, jQuery);
Also see: Tab Triggers