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="carousel">
<!-- スライドのリスト -->
<div class="contains">
<!-- スライドを選択するためのラジオボタンリスト。 -->
<!-- 数は増減しても構わないです。 最初は1番目を選択状態(checked)にします。-->
<!-- Slide各ラジオボタンに個別のidを定義して、nameはすべて同じ値にします。 -->
<input class="slide_select" type="radio" id="SlideA" name="slide_check" checked />
<input class="slide_select" type="radio" id="SlideB" name="slide_check" />
<input class="slide_select" type="radio" id="SlideC" name="slide_check" />
<input class="slide_select" type="radio" id="SlideD" name="slide_check" />
<!-- スライド -->
<!-- 上のラジオボックスと同じ数だけ記述します。-->
<div class="slide">
<!-- スライドの前へ、次へとスクロールさせるボタン -->
<div class="scroll_controler">
<!-- 前へボタン forで戻る先のラジオボタンのidを書きます。-->
<!-- 先頭要素なので、最後のスライドのidである"SlideD"を書いています。 -->
<label class="scroll_button scroll_prev" for="SlideD"></label>
<!-- 次へボタン 上と同様にforで進む先のラジオボタンのidを書きます。-->
<!-- 進み先は2番目の要素なので、2番目のスライドのid"SlideB"を書いています。 -->
<label class="scroll_button scroll_next" for="SlideB"></label>
</div>
<!-- スライドの内容(ここでは画像)を記述します。 -->
<!-- div要素に変えれば文字を加えることもできます。 -->
<img src="https://picsum.photos/320/180?random=1">
</div>
<!-- スライド(2番目)内容は1個めと同じ -->
<div class="slide">
<div class="controler_scroll">
<label class="scroll_button scroll_prev" for="SlideA"></label>
<label class="scroll_button scroll_next" for="SlideC"></label>
</div>
<img src="https://picsum.photos/320/180?random=2">
</div>
<!-- スライド(3番目)内容は1個めと同じ -->
<div class="slide">
<div class="controler_scroll">
<label class="scroll_button scroll_prev" for="SlideB"></label>
<label class="scroll_button scroll_next" for="SlideD"></label>
</div>
<img src="https://picsum.photos/320/180?random=3">
</div>
<!-- スライド(4番目)内容は1個めと同じ -->
<div class="slide">
<div class="controler_scroll">
<label class="scroll_button scroll_prev" for="SlideC"></label>
<label class="scroll_button scroll_next" for="SlideA"></label>
</div>
<img src="https://picsum.photos/320/180?random=4">
</div>
<!-- スライド移動用ボタン -->
<div class="move_controler">
<!-- 1個目のスライドのボタン -->
<!-- 一番上のラジオボタンの1個目のスライドのid”A”をforに定義します-->
<label class="button_move" for="SlideA"></label>
<label class="button_move" for="SlideB"></label>
<label class="button_move" for="SlideC"></label>
<label class="button_move" for="SlideD"></label>
</div>
</div>
</div>
/* カルーセル全体 */
.carousel {
/* 水平方向中央寄せ */
display: flex;
justify-content: center;
}
/* カルーセル内容 */
.contains {
/* サイズは自由に変更してください。*/
/* 下の.slideも同じサイズにしてください。 */
width: 320px;
height: 180px;
overflow: hidden;
position: relative;
padding: 0;
list-style: none;
}
/* スライド切り換え用ラジオボタンは常に非表示 */
.slide_select {
display: none;
}
/* 各スライド */
.slide {
/* サイズは自由に変更してください。*/
/* 上の.containsも同じサイズにしてください。 */
width: 320px;
height: 180px;
position: absolute;
/* スライドの初期値は選択されていないので透明にしておく */
opacity: 0;
}
/* 前へ次へボタン */
.scroll_button {
position: absolute;
display: block;
height: 30px;
width: 30px;
/* 縦中央から20px上の位置 */
top: 50%;
margin-top: -20px;
/* 上辺と右辺のみ幅5pxの枠線 */
border-width: 5px 5px 0 0;
border-style: solid;
border-color: #fdfdfd;
cursor: pointer;
/* 普段はボタンはやや薄くする */
opacity: 0.5;
/* スライドよりも前面にする */
z-index: 3;
}
/* ホバー時にボタンを強調 */
.scroll_button:hover {
opacity: 1;
}
/* 前へボタン */
.scroll_prev {
left: 15px;
/* 上辺と右辺の枠線を回転して"<"にする */
transform: rotate(-135deg);
}
/* 次へボタン */
.scroll_next {
right: 15px;
/* 上辺と右辺の枠線を回転して">"にする */
transform: rotate(45deg);
}
/* スライド移動ボタンエリア */
.move_controler {
position: absolute;
bottom: 20px;
width: 100%;
text-align: center;
}
/* スライド移動の各ボタン */
.button_move {
display: inline-block;
height: 15px;
width: 15px;
margin: 0 2px;
border-radius: 100%;
cursor: pointer;
/* 普段はやや薄くする */
opacity: 0.5;
/* スライドより前面にする */
z-index: 2;
}
/* ホバー時はやや明るくする */
.button_move:hover {
opacity: 0.75;
}
/* スライド移動ボタンの色 */
.button_move {
background-color: #fdfdfd;
}
/* 1番目のスライド選択時 */
/* 1番目のスライドの透明度を0にして表示する */
.slide_select:nth-of-type(1):checked ~ .slide:nth-of-type(1) {
opacity: 1;
}
/* 1番目のスライドの前へ次へボタンの領域を */
.slide_select:nth-of-type(1):checked
~ .move_controler
.button_move:nth-of-type(1) {
opacity: 1;
}
.slide_select:nth-of-type(2):checked ~ .slide:nth-of-type(2) {
opacity: 1;
}
.slide_select:nth-of-type(2):checked
~ .move_controler
.button_move:nth-of-type(2) {
opacity: 1;
}
.slide_select:nth-of-type(3):checked ~ .slide:nth-of-type(3) {
opacity: 1;
}
.slide_select:nth-of-type(3):checked
~ .move_controler
.button_move:nth-of-type(3) {
opacity: 1;
}
.slide_select:nth-of-type(4):checked ~ .slide:nth-of-type(4) {
opacity: 1;
}
.slide_select:nth-of-type(4):checked
~ .move_controler
.button_move:nth-of-type(4) {
opacity: 1;
}
Also see: Tab Triggers