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 id="wrap">
<h1>Responsive <span>Table</span> Layout Sample</h1>
<p class="description">レスポンシブデザインのテーブルレイアウト例</p>
<ul class="btnList">
<li><button class="addThead">Thead追加</button></li>
<li><button class="removeThead">Thead削除</button></li>
<li><button class="increaseText">テキスト増やす</button></li>
<li><button class="cutBackText">テキスト減らす</button></li>
</ul>
<div class="tableBlock pattern01">
<table>
<caption>レスポンシブテーブル パターン1:単純に幅可変</caption>
<tbody>
<tr>
<th>見出し1</th>
<td>テキスト1-1</td>
<td>テキスト1-2</td>
</tr>
<tr>
<th>見出し2</th>
<td>テキスト2-1</td>
<td>テキスト2-2</td>
</tr>
<tr>
<th>見出し3</th>
<td>テキスト3-1</td>
<td>テキスト3-2</td>
</tr>
</tbody>
</table>
<!-- /.tableBlock pattern01 --></div>
<div class="tableBlock pattern02">
<table>
<caption>レスポンシブテーブル パターン2:フォントサイズ縮小</caption>
<tbody>
<tr>
<th>見出し1</th>
<td>テキスト1-1</td>
<td>テキスト1-2</td>
</tr>
<tr>
<th>見出し2</th>
<td>テキスト2-1</td>
<td>テキスト2-2</td>
</tr>
<tr>
<th>見出し3</th>
<td>テキスト3-1</td>
<td>テキスト3-2</td>
</tr>
</tbody>
</table>
<!-- /.tableBlock pattern02 --></div>
<div class="tableBlock pattern03">
<table>
<caption>レスポンシブテーブル パターン3:縦並び</caption>
<tbody>
<tr>
<th>見出し1</th>
<td>テキスト1-1</td>
<td>テキスト1-2</td>
</tr>
<tr>
<th>見出し2</th>
<td>テキスト2-1</td>
<td>テキスト2-2</td>
</tr>
<tr>
<th>見出し3</th>
<td>テキスト3-1</td>
<td>テキスト3-2</td>
</tr>
</tbody>
</table>
<!-- /.tableBlock pattern03 --></div>
<div class="tableBlock pattern04">
<table>
<caption>レスポンシブテーブル パターン4:横スクロール</caption>
<tbody>
<tr>
<th>見出し1</th>
<td>テキスト1-1</td>
<td>テキスト1-2</td>
</tr>
<tr>
<th>見出し2</th>
<td>テキスト2-1</td>
<td>テキスト2-2</td>
</tr>
<tr>
<th>見出し3</th>
<td>テキスト3-1</td>
<td>テキスト3-2</td>
</tr>
</tbody>
</table>
<!-- /.tableBlock pattern04 --></div>
<div class="tableBlock pattern05">
<table>
<caption>レスポンシブテーブル パターン5:リスト化</caption>
<tbody>
<tr>
<th>見出し1</th>
<td>テキスト1-1</td>
<td>テキスト1-2</td>
</tr>
<tr>
<th>見出し2</th>
<td>テキスト2-1</td>
<td>テキスト2-2</td>
</tr>
<tr>
<th>見出し3</th>
<td>テキスト3-1</td>
<td>テキスト3-2</td>
</tr>
</tbody>
</table>
<!-- /.tableBlock pattern05 --></div>
<div class="tableBlock pattern06">
<table>
<caption>レスポンシブテーブル パターン6:thead縦横切替</caption>
<tbody>
<tr>
<th>見出し1</th>
<td>テキスト1-1</td>
<td>テキスト1-2</td>
</tr>
<tr>
<th>見出し2</th>
<td>テキスト2-1</td>
<td>テキスト2-2</td>
</tr>
<tr>
<th>見出し3</th>
<td>テキスト3-1</td>
<td>テキスト3-2</td>
</tr>
</tbody>
</table>
<!-- /.tableBlock pattern06 --></div>
<!-- /#wrap --></div>
@import url(https://fonts.googleapis.com/css?family=Righteous);
#wrap {
margin:2em auto;
font-family: Arial, Roboto, “Droid Sans”, “游ゴシック”, YuGothic, “ヒラギノ角ゴ ProN W3”, “Hiragino Kaku Gothic ProN”, “メイリオ”, Meiryo, sans-serif;
max-width:960px;
}
h1, h2 {
text-align:center;
font-family: 'Righteous', cursive;
}
h1 {
font-size: 2.5em;
}
h1 span {
color:#ffc045;
}
p.description {
margin-top: 1em;
letter-spacing:2px;
text-align:center;
}
.btnList {
margin-top: 2em;
text-align:center;
}
.btnList li {
display:inline-block;
}
/* 基本スタイル */
.tableBlock {
margin-top:2em;
}
table {
width:100%;
table-layout:fixed;
-webkit-box-sizing:border-box;
box-sizing:border-box;
border:1px solid #cfcfcf;
}
table caption {
padding:1em;
line-height: 1.5;
text-align: left;
background:#ffc045;
}
table tr th {
background:#f2f2f2;
}
table tr th,
table tr td {
padding:1em;
line-height: 1.5;
text-align:left;
border:1px solid #cfcfcf;
}
/* パターン4:テーブルを横スクロールに */
.tableBlock.pattern04 {
overflow-x:auto;
}
.tableBlock.pattern04 table {
width:960px;
}
/* スクロールバー全体 */
.tableBlock.pattern04::-webkit-scrollbar{
height: 0.5em;
background-color: #F1F1F1;
}
/* スクロールバーのつまみ(可動部分) */
.tableBlock.pattern04::-webkit-scrollbar-thumb{
background-color: #BCBCBC;
border-radius: 12px;
border-radius: 1.2rem;
}
.tableBlock.pattern04::-webkit-scrollbar-thumb:hover{
background-color: #A9A9AA;
}
/* Tablet */
@media screen and (max-width:768px){
/* パターン2:フォントサイズ縮小 */
.tableBlock.pattern02 table {
font-size:75%;
}
/* パターン3:テーブルセルを縦並びに */
.tableBlock.pattern03 table,
.tableBlock.pattern03 table caption,
.tableBlock.pattern03 table thead,
.tableBlock.pattern03 table tbody,
.tableBlock.pattern03 table tr,
.tableBlock.pattern03 table tr th,
.tableBlock.pattern03 table tr td {
display:block;
}
.tableBlock.pattern03 table tr th,
.tableBlock.pattern03 table tr td {
margin:-1px; /* borderが二重になるのを防ぐ */
}
/* パターン5:リスト化 */
.tableBlock.pattern05 table,
.tableBlock.pattern05 table caption,
.tableBlock.pattern05 table thead,
.tableBlock.pattern05 table tbody,
.tableBlock.pattern05 table tr,
.tableBlock.pattern05 table tr th {
display:block;
}
.tableBlock.pattern05 table tr th {
margin:-1px; /* borderが二重になるのを防ぐ */
}
.tableBlock.pattern05 table tr td {
display:list-item;
list-style:disc inside;
border:none;
}
.tableBlock.pattern05 table tr td + td {
padding-top:0;
}
/* パターン6:縦横切替 */
.tableBlock.pattern06 table,
.tableBlock.pattern06 table caption,
.tableBlock.pattern06 table thead,
.tableBlock.pattern06 table tbody,
.tableBlock.pattern06 table tr,
.tableBlock.pattern06 table tr th,
.tableBlock.pattern06 table tr td {
display:block;
}
.tableBlock.pattern06 table tr th,
.tableBlock.pattern06 table tr td {
margin:-1px; /* borderが二重になるのを防ぐ */
}
.tableBlock.pattern06 table thead {
display:none;
}
.tableBlock.pattern06 table tbody tr td[data-th]:before {
content: attr(data-th) " : ";
font-weight: bold;
display: inline-block;
margin-right:0.25em;
}
/* Tablet */ }
/* SmartPhone */
@media screen and (max-width:480px){
/* パターン2:フォントサイズ縮小 */
.tableBlock.pattern02 table {
font-size:50%;
}
/* Smartphone */ }
$(function(){
// thead追加
$('.btnList .addThead').click(function(){
tableReset();
$('table caption').after('<thead><tr><th></th><th>見出し●●</th><th>見出し××</th></tr></thead>');
tableData() // パターン6:縦横切替
});
// thead削除
$('.btnList .removeThead').click(function(){
tableReset();
});
// テーブルリセット
function tableReset(){
$('table thead').remove();
$('table td').each(function(){
$(this).removeAttr('data-th');
});
}
// デフォルトのテキストを配列に格納
var defTextArr = new Array();
$('table td').each(function(i){
defTextArr[i] = $(this).text();
});
// テキスト増やす
var count = 1;
$('.btnList .increaseText').click(function(){
count++;
$('table td').each(function(e){
$(this).text( $(this).text() + $(this).text() );
});
});
// テキスト減らす
$('.btnList .cutBackText').click(function(){
for(t=0; t<defTextArr.length; t++) {
var txt = defTextArr[t];
if(count >= 1) {
$('table td').each(function(){
$(this).text( $(this).text().replace(txt, '' ) );
});
}
}
});
// パターン6:縦横切替のテーブルにdata属性を追加
function tableData(){
var index ='';
var headTxt ='';
$('.tableBlock.pattern06 table').each(function() {
$(this).find('thead tr th').each(function() {
// theadの位置やテキストを取得
index = $(this).index()-1;
headTxt = $(this).text();
// tbodyのセルにdata属性を追加
$(this).parents('table').find('tbody tr').each(function() {
$(this).find('td').eq(index).attr('data-th',headTxt);
});
});
});
}
tableData();
});
Also see: Tab Triggers