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.
<header>
<h1>サイトタイトルサイトタイトルサイトタイトル</h1>
</header>
<div id="contents" class="clearfix">
<div id="main">
<article>
<h2>タイトル1タイトル1タイトル1タイトル1</h2>
<p>テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
<h3>タイトル1-2タイトル1-2タイトル1-2タイトル1-2</h3>
<p>テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
<h4>タイトル1-2-1タイトル1-2-1タイトル1-2-1タイトル1-2-1</h4>
<p>テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
<h4>タイトル1-2-2タイトル1-2-2タイトル1-2-2タイトル1-2-2</h4>
<p>テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
<h4>タイトル1-2-3タイトル1-2-3タイトル1-2-3タイトル1-2-3</h4>
<p>テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
<h3>タイトル1-3タイトル1-3タイトル1-3タイトル1-3</h3>
<p>テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
<h2>タイトル2タイトル2タイトル2タイトル2</h2>
<p>テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
<h3>タイトル2-1タイトル2-1タイトル2-1タイトル2-1</h3>
<p>テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
<h3>タイトル2-2タイトル2-2タイトル2-2タイトル2-2</h3>
<p>テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>
</article>
<!-- #main --></div>
<div id="side">
<div class="mokuji">
<!-- .mokuji --></div>
<!-- #side --></div>
<!-- /.contents --></div>
<footer>
<p>フッターフッターフッター</p>
</footer>
body {
font-family:"游ゴシック",YuGothic,"ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro",Verdana,"メイリオ",Meiryo,Osaka,"MS Pゴシック","MS PGothic",sans-serif;
}
header {
padding: 1em 1em .8em;
color: #6c501b;
font-size:2em;
background: #fdd835;
text-align:center;
}
#contents {
position:relative;
width:92%;
max-width:960px;
margin:30px auto 450px;
}
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
#main {
width:100%;
padding-right:320px;
box-sizing:border-box;
}
article h2 {
margin-bottom:1em;
padding: 1em 1.25em .9em;
font-size: 120%;
border-top: 4px solid #ffc045;
background: #f2f2f2;
text-shadow: 1px 1px 0 rgba(255,255,255,0.5);
}
article h3 {
margin: 2em 0;
padding: .5em 1.25em .4em;
border-left: 4px solid #ffc045;
}
article h4 {
display: inline-block;
margin-bottom: 1em;
padding: .5em 1em;
color: #6c501b;
font-weight:bold;
background: #fdd835;
border-radius: 3px;
}
article p {
margin-bottom:2em;
line-height:1.5;
}
/* サイドバー */
#side {
position:absolute;
top:0;
right:0;
width:300px;
}
/* 目次 */
.mokuji {
background:#fff;
box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.1);
}
.mokuji.fixed-side {
position:fixed;
top:30px;
left:auto;
width:300px;
box-shadow: 0px 5px 30px rgba(0, 0, 0, 0.2);
}
.mokuji h4 {
position:relative;
padding:1em 1em 0.8em;
color:#6C501B;
font-size:96%;
font-weight:bold;
background:#FDD835;
text-shadow:1px 1px 0 rgba(255,255,255,0.5);
}
.mokuji h4 .kao {
display:inline-block;
*display:inline;
*zoom:1;
margin-left:0.5em;
font-weight:normal;
}
.mokuji h4 .closeBtn {
cursor:pointer;
position:absolute;
top:11px;
right:12px;
font-size:1.5em;
-webkit-transition:0.2s;
-moz-transition:0.2s;
transition:0.2s;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transform-origin:center;
-moz-transform-origin:center;
-ms-transform-origin:center;
-o-transform-origin:center;
transform-origin:center;
}
.mokuji h4 .closeBtn.active {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
.mokuji .mokujiInner {
border:1px solid #ddd;
border-top:none;
}
/* インデント */
.mokuji li {
overflow:hidden;
position:relative;
cursor:pointer;
width:100%;
height:100%;
/*text-indent:-1em;*/
list-style:none;
-webkit-transition:0.2s;
-moz-transition:0.2s;
transition:0.2s;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
.mokuji ul.mokujiShare li {
list-style:none;
text-align:center;
background:#f2f2f2;
}
.mokuji ol ol { display:none; }
.mokuji ol ol li { padding-left:1em; }
.mokuji ol ol ol li { padding-left:2em; }
.mokuji li a {
display:block;
padding:1em;
color:#333;
font-size:75%;
line-height:1.5;
text-decoration:none;
}
.mokuji > ol li.accordion .inner a {
padding-left:0;
}
.mokuji li:hover {
background:#f2f2f2;
}
.mokuji li.current {
background:#FFECB3;
}
.mokuji li.active {
background:#f00;
}
.mokuji li.current a {
color:#6C501B;
font-weight:bold;
}
/* アコーディオン */
.mokuji li.accordion {
padding:0;
}
.mokuji li.accordion .inner {
display:table;
width:100%;
table-layout:fixed;
}
.mokuji li.accordion .inner a {
display:table-cell;
width:100%;
text-indent:0;
padding: 1em;
vertical-align:middle;
}
.mokuji li.accordion .inner .accBtn {
display:table-cell;
width: 30px;
margin-top:12px;
font-size: 1.5em;
text-indent:0;
color:#fff;
background:#555;
text-align:center;
vertical-align:middle;
}
/* フッター */
footer {
position:relative;
padding: 2em 0;
color:#fff;
background: #333;
z-index:2;
}
footer p {
width:92%;
max-width:960px;
margin:0 auto;
}
/* タブレット・スマートフォン */
@media screen and (max-width:768px){
#main {
padding-right:0;
}
#side {
width:auto;
}
.mokuji {
display:none;
}
}
$(function() {
/* -------------------------------------------------------
記事の見出しから目次作成
--------------------------------------------------------*/
function makeMokuji() {
var idcount = 1;
var mokuji = '';
var currentlevel = 0
var sectionTopArr = new Array();
// 見出しを回してリストに格納
$('article h2, article h3, article h4').each(function(i){
// IDを保存
this.id = 'chapter-' + idcount;
idcount ++;
// 見出しの入れ子
var level = 0;
if(this.nodeName.toLowerCase() == 'h2') {
level = 1;
} else if(this.nodeName.toLowerCase() == 'h3') {
level = 2;
} else if(this.nodeName.toLowerCase() == 'h4') {
level = 3;
}
while(currentlevel < level) {
mokuji += '<ol class="chapter">';
currentlevel ++;
}
while(currentlevel > level) {
mokuji += '</ol>';
currentlevel --;
}
// リストを生成
mokuji += '<li><a href="#' + this.id + '">' + $(this).html() + '</a></li>\n';
});
while(currentlevel > 0) {
mokuji += '</ol>';
currentlevel --;
}
// HTML出力
strMokuji = '<h4>目次で流し読みする <span class="kao">・*・:≡( ε:)</span> <span class="closeBtn"><i class="fa fa-times-circle-o"></i></span></h4>\
<div class="mokujiInner">'
+ mokuji +
'<!-- /.mokujiInner --></div>';
$('.mokuji').html(strMokuji);
/* -------------------------------------------------------
リストクリックでスムーズスクロール
--------------------------------------------------------*/
$('.mokuji li').not('.accordion, .accBtn').click(function(){
var speed = 800;
var href = $(this).find('a').attr('href');
var target = $(href == '#' || href == '' ? 'html' : href);
var position = target.offset().top;
$('html, body').stop().animate({scrollTop:position}, speed, 'easeInOutCirc');
return false;
});
/* -------------------------------------------------------
目次のアコーディオン
--------------------------------------------------------*/
$('.mokuji ol').prev().addClass('accordion').append('<span class="accBtn"><i class="fa fa-plus-square-o"></i></span>');
$('.mokuji li.accordion').wrapInner('<div class="inner clearfix"></div>');
// 開閉ボタンを押した時
$('.accBtn').click(function(){
// 開閉処理
$(this).parents('li').next().stop().slideToggle(300, 'easeInOutCirc');
// 閉じるボタンアイコン切替
$('.closeBtn').removeClass('active').addClass('active');
// アイコン切替
if( $(this).find('i').hasClass('fa-plus-square-o') ){
$(this).find('i').removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
} else {
$(this).find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
}
return false;
});
// 閉じるボタンの表示切替
var closeBtnFlag = '';
$('.mokuji li').each(function() {
if( $(this).hasClass('accordion') ) {
closeBtnFlag = false;
}
});
if( closeBtnFlag == true ) {
$('.closeBtn').hide();
}
// 全て閉じるボタンを押した時
$('.closeBtn').click(function(){
// 閉じるアイコン切替
$(this).toggleClass('active');
// classの有無を確認
if( $(this).hasClass('active') ){
$('.mokuji ol ol').stop().slideDown(300, 'easeInOutCirc');
$('.accBtn').find('i').removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
} else {
$('.mokuji ol ol').stop().slideUp(300, 'easeInOutCirc');
$('.accBtn').find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
}
});
/* -------------------------------------------------------
カレント表示切替
--------------------------------------------------------*/
var secTopArr = new Array();
secTopArr.length = 0;
var current = -1;
// 現在位置の取得
$('article [id^="chapter"]').each(function(i){
secTopArr[i] = $(this).offset().top;
});
//スクロールイベント
$(window).on('load scroll',function(){
for (var i = secTopArr.length-1; i>=0; i--) {
if ($(window).scrollTop() > secTopArr[i] - 20) {
$('.mokuji li').removeClass('current').eq(i).addClass('current');
$('.mokuji ol ol li.current').parent('ol').prev().addClass('current');
break;
}
}
});
}
makeMokuji();
/* -------------------------------------------------------
目次固定
--------------------------------------------------------*/
function fixedSide() {
// ウィンドウ幅・人気記事を取得
var w = window.innerWidth;
var mainH = $('#main').height();
var sideH = $('#side').height();
var fixedElm = '';
if(mainH > sideH) { // サイドバーより長ければ
fixedElm = $('.mokuji');
// 要素の位置を取得
var fixedSideTop = fixedElm.offset().top;
var footerTop = $('footer').offset().top;
var scrollBottom = $('body').height() - $(window).height() - $('footer').outerHeight();
$(window).scroll(function(){
// スクロール位置を取得
y = $(window).scrollTop();
// スクロールがサイドバーを上回ったら
if(y > fixedSideTop){
fixedElm.addClass('fixed-side');
} else {
fixedElm.removeClass('fixed-side');
}
});
}
}
fixedSide();
});
Also see: Tab Triggers