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.
<div class="section">
<div class="tabBox">
<div class="tabArea">
<div class="one_tab">
<a href="#tab01"><span class="tab_inner">Tab1</span></a>
</div>
<div class="one_tab">
<a href="#tab02"><span class="tab_inner">Tab2</span></a>
</div>
<div class="one_tab">
<a href="#tab03"><span class="tab_inner">Tab3</span></a>
</div>
</div>
</div><!-- /.tabBox -->
<div class="contents">
<div id="tab01" class="tab_main">
<div class="innerArea">Tab1 text</div>
</div><!-- /#tab01 -->
<div id="tab02" class="tab_main">
<div class="innerArea">Tab2 text</div>
</div><!-- /#tab02 -->
<div id="tab03" class="tab_main">
<div class="innerArea">Tab3 text</div>
</div><!--#tab03-->
</div><!--contents-->
<!-- ▼Tab under▼ -->
<div class="tabBox">
<div class="tabArea bottom">
<div class="one_tab">
<a href="#tab01"><span class="tab_inner">Tab1</span></a>
</div>
<div class="one_tab">
<a href="#tab02"><span class="tab_inner">Tab2</span></a>
</div>
<div class="one_tab">
<a href="#tab03"><span class="tab_inner">Tab3</span></a>
</div>
</div>
</div><!-- /.tabBox -->
<p class="_a"><a href="https://125naroom.com/web/2854" target="_blank" class="link">View the note</a></p>
</div>
.tabBox .tabArea {
width: 100%;
height: 80px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: flex-end;
}
.tabBox .tabArea .one_tab {
width: 32.5%;
}
.tabBox .tabArea .one_tab a {
display: block;
text-decoration: none;
transition-duration: 0.3s;
text-align: center;
color: #fff;
}
.tabBox .tabArea .one_tab a:hover {
opacity: 0.7;
text-decoration: none;
}
.tabBox .tabArea .one_tab .tab_inner {
display: flex;
justify-content: center;
align-items: center;
height: 60px;
transition-duration: 0.3s;
}
.tabBox .tabArea .one_tab:nth-child(1) .tab_inner {
background-color: #94ad73;
}
.tabBox .tabArea .one_tab:nth-child(2) .tab_inner {
background-color: #e6de6b;
}
.tabBox .tabArea .one_tab:nth-child(3) .tab_inner {
background-color: #e8a48b;
}
.tabBox .tabArea .one_tab a.select .tab_inner {
height: 80px;
}
.tabBox .tabArea.bottom {
align-items: flex-start;
}
.contents .tab_main {
display: none;
padding: 50px 25px;
text-align: center;
min-height: 280px;
border: 2px solid #94ad73;
transition-duration: 0.3s;
}
.tab_main.is_show {
display: block;
}
.tab_main:nth-child(1).is_show {
border: 2px solid #94ad73;
}
.tab_main:nth-child(2).is_show {
border: 2px solid #e6de6b;
}
.tab_main:nth-child(3).is_show {
border: 2px solid #e8a48b;
}
/*====================================================================
以下は不要です。
====================================================================*/
body {
font-family: YuGothic, "游ゴシック体", "Yu Gothic", "ヒラギノ角ゴ Pro", "Hiragino Kaku Gothic Pro", "メイリオ", Meiryo, "MS Pゴシック", "MS PGothic", sans-serif;
font-size: 16px;
letter-spacing: .025em;
line-height: 1.8;
margin: 0;
}
@media screen and (max-width: 1024px) {
body {
font-size: 14px;
}
}
.section {
max-width: 1024px;
margin: 0 auto;
padding: 20px 20px 500px;
}
.section p._a {
font-size: 12px;
font-weight: bold;
margin: 30px 0 0;
}
.section p._a .link {
display: inline-block;
color: #607D8B;
padding-left: 1.3em;
text-indent: -1.3em;
}
.section p._a .link:before {
content: '';
display: inline-block;
width: 5px;
height: 5px;
border-top: 2px solid #607D8B;
border-right: 2px solid #607D8B;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
margin-right: 10px;
}
$(function() {
var tabMenu = function() {
/**
* 変数の指定
* $tab_area : tabの親要素のjQueryオブジェクト
* $content : tabによって切り替わる要素のjQueryオブジェクト
* TAB_ACTIVE_CLASS : tabが選択されたスタイルを変更するclass名
* CONTENT_SHOW_CLASS : contentを表示させるためのclass名
* id_arr : $contentのIDを配列に格納
*/
var $tab_area = $('.tabArea');
var $content = $('.contents .tab_main');
var TAB_ACTIVE_CLASS = 'select';
var CONTENT_SHOW_CLASS = 'is_show';
var id_arr = $content.map(function() { return '#' + $(this).attr('id');}).get();
/**
* 該当するhashデータがある場合、hashを返す
* 該当とは id_arr[] に含まれるもの
* @return {string} 該当する場合
* @return {false} 該当しない(存在しない)場合
*/
var getHash = function() {
var hash = window.location.hash;
var index = id_arr.indexOf(hash);
if (index === -1) {
return false;
} else {
return id_arr[index];
}
};
/**
* ページ読み込み時に実行
* 1. hashがあれば、hashをhrefに持つタブのスタイル変更(専用のclass付与)
* 2. hashがあれば、hashをidに持つコンテンツを表示(専用のclassを付与)
* 3. hashがなければ、タブの先頭が選択された状態とする
*/
var initialize = function() {
var hash = getHash();
if (hash) {
$tab_area.find('a[href="'+hash+'"]').addClass(TAB_ACTIVE_CLASS); // 1
$(hash).addClass(CONTENT_SHOW_CLASS); // 2
$(window).on('load',function(){
setTimeout(function(){
// 移動先を100px上にずらす
var adjust = 100;
// スクロールの速度
var speed = 400; // ミリ秒
// 移動先を取得
var target = $(hash);
// 移動先を調整
var position = target.offset().top - adjust;
// スムーススクロール
$('body,html').animate({scrollTop:position}, speed, 'swing');
},100);
});
} else {
$tab_area.find('.one_tab:first > a').addClass(TAB_ACTIVE_CLASS); // 3
$($content[0]).addClass(CONTENT_SHOW_CLASS); // 3
}
};
/**
* タブのクリックイベント
* 1. クリックされたタブのhref, 該当するcontentを取得
* 2. 既にクリック済みの状態であればスキップ
* 3. 一旦タブ・contentの専用classを全削除
* 4. クリックしたタブのスタイルを変更、該当するcontentを表示(それぞれ専用のclassを付与)
*/
var addEvent = function() {
$tab_area.find('a').on('click', function() {
// 1
var href = $(this).attr('href');
var $targetContent = $(href);
// 2
if ($(this).hasClass(TAB_ACTIVE_CLASS)) {
return false;
}
// 3
$tab_area.find('a').removeClass(TAB_ACTIVE_CLASS);
$content.removeClass(CONTENT_SHOW_CLASS);
// 4
$(this).addClass(TAB_ACTIVE_CLASS);
$targetContent.addClass(CONTENT_SHOW_CLASS);
return false;
});
};
return [initialize(), addEvent()];
};
// 実行
tabMenu();
});
// 下のタブをクリックした場合に処理
$(function(){
$('.tabArea.bottom a[href^=#]').click(function() {
// 移動先を100px上にずらす
var adjust = 100;
// スクロールの速度
var speed = 400; // ミリ秒
// アンカーの値取得
var href= $(this).attr("href");
// 移動先を取得
var target = $(href == "#" || href == "" ? 'html' : href);
// 移動先を数値で取得
var position = target.offset().top - adjust;
// スムーススクロール
$('body,html').animate({scrollTop:position}, speed, 'swing');
return false;
});
});
// タブ連動
$(function(){
// tab01
$('.tabArea .one_tab:nth-child(1) a').on('click',function(){
$('.tabArea .one_tab:nth-child(1) a').addClass('select');
});
$('.tabArea .one_tab:not(:nth-child(1)) a').on('click',function(){
$('.tabArea .one_tab:nth-child(1) a').removeClass('select');
});
// tab02
$('.tabArea .one_tab:nth-child(2) a').on('click',function(){
$('.tabArea .one_tab:nth-child(2) a').addClass('select');
});
$('.tabArea .one_tab:not(:nth-child(2)) a').on('click',function(){
$('.tabArea .one_tab:nth-child(2) a').removeClass('select');
});
// tab03
$('.tabArea .one_tab:nth-child(3) a').on('click',function(){
$('.tabArea .one_tab:nth-child(3) a').addClass('select');
});
$('.tabArea .one_tab:not(:nth-child(3)) a').on('click',function(){
$('.tabArea .one_tab:nth-child(3) a').removeClass('select');
});
});
Also see: Tab Triggers