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.
<body>
<header id="header" class="wrapper">
<h1 class="site-title">
<a href="index.html"><img src="https://i.pinimg.com/564x/63/fb/20/63fb204f34531dcf3aed7ed61381fae8.jpg" alt=""></a>
</h1>
<nav id="navi">
<ul class="nav-menu">
<li><a href="">PRODUCTS</a></li>
<li><a href="">ABOUT</a></li>
<li><a href="">COMPANY</a></li>
<li><a href="">CONTACT</a>
<!-- <a href="mailto:xxxxx@xxx.xxx.com?subject=お問い合わせ">CONTACT</a> -->
</li>
</ul>
</nav>
<div id="mask"></div>
<div class="toggle_btn">
<span></span>
<span></span>
</div>
</header>
<main>
<div id="top" class="wrapper">
</div>
</main>
</body>
</html>
@charset "UTF-8";
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
font-size: 100%;
}
body {
color: #333;
font-size: 1rem;
}
a {
color: #333;
text-decoration: none;
transition: all 0.5s;
}
a:hover {
opacity: 0.7;
}
img {
max-width: 100%;
}
li {
list-style: none;
}
/*
コンテンツ幅を設定するための共通クラス
*/
.wrapper {
width: 80%;
max-width: 1360px;
margin: 0 auto;
padding: 0 40px;
}
/*-------------------------------------------
ヘッダー
-------------------------------------------*/
/*
「position: fixed;」でヘッダーを固定し、「z-index: 10;」で前面に表示
※他のコンテンツでpositionをrelative、absolute、fixedのいずれかに
設定している場合は、z-indexの数値が大きい方が前面に表示される
*/
#header {
/* width: 100%; */
height: 80px;
background-color: #fff;
display: flex;
align-items: center;
justify-content: space-between;
left: 0;
right: 0;
z-index: 10;
position: relative;
}
/*
ハンバーガーメニュー
メニューが閉じている時は、「left: -300px;」で画面左に隠し、
「opacity: 0;」で非表示にしている
*/
#navi {
position: fixed;
top: 0;
left: -300px;
width: 300px;
color: #fff;
padding: 36px 50px;
transition: all 0.5s;
z-index: 20;
opacity: 0;
}
#navi a {
color: #fff;
}
#navi li {
margin-bottom: 14px;
}
.site-title img {
width: 100px;
}
/*
ハンバーガーメニュー
メニューが開いている時は、「left: 0;」「opacity: 1;」で
画面左に表示する
*/
.open #navi {
left: 10%;
opacity: 1;
}
/*
ハンバーガーメニューの位置の設定(ポイント:position:relative,z-indexに大きめの数字,transitionはspanに)
*/
.toggle_btn {
width: 30px;
height: 30px;
position: relative;
transition: all 0.5s;
cursor: pointer;
z-index: 20;
}
/*
ハンバーガーメニューの線の設定(メニューが閉じている時)
*/
.toggle_btn span {
display: block;
position: absolute;
width: 30px;
height: 2px;
background-color: #333;
border-radius: 4px;
transition: all 0.5s;
}
/*
1本目の線の位置を設定
*/
.toggle_btn span:nth-child(1) {
top: 10px;
}
/*
2本目の線の位置を設定
*/
.toggle_btn span:nth-child(2) {
bottom: 10px;
}
/*
ハンバーガーメニューの線の設定(メニューが開いている時 .openがつく)
線の色を白に変更
*/
.open .toggle_btn span {
background-color: #fff;
}
/*
1本目の線を-45度回転 nth-child()で指定する
*/
.open .toggle_btn span:nth-child(1) {
-webkit-transform: translateY(4px) rotate(-225deg);
transform: translateY(4px) rotate(-225deg); /* ちょっと多めに回転させてる */
}
/*
2本目の線を45度回転
*/
.open .toggle_btn span:nth-child(2) {
-webkit-transform: translateY(-4px) rotate(225deg);
transform: translateY(-4px) rotate(225deg);
}
/* 黒背景は最初は非表示 */
#mask {
background: #000;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 20;
visibility: hidden;
opacity: 0;
transition: opacity 1s ease, visibility 1s ease;
}
/*
メニューを開いている時は、全体を黒背景にする
*/
.open #mask {
opacity: 1
transition: opacity .6s ease, visibility .6s ease;
visibility: visible;
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: .9;
z-index: 10; /* 2本線より低い数字 */
cursor: pointer;
}
$(function(){
/*=================================================
ハンバーガーメニュー
===================================================*/
// ハンバーガーメニューのクリックイベント
$('.toggle_btn').on('click', function() {
// #headerにopenクラスが存在する場合
if ($('#header').hasClass('open')) {
// openクラスを削除
// openクラスを削除すると、openクラスのCSSがはずれるため、
// メニューが非表示になる
$('#header').removeClass('open');
// #headerにopenクラスが存在しない場合
} else {
// openクラスを追加
// openクラスを追加すると、openクラスのCSSが適応されるため、
// メニューが表示される
$('#header').addClass('open');
}
});
// メニューが表示されている時に画面をどこでもクリックした場合
$('#mask').on('click', function() {
// openクラスを削除して、メニューを閉じる
$('#header').removeClass('open');
});
});
Also see: Tab Triggers