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 URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
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.
If the stylesheet 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 CSS 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.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/main.css">
<title>Responsive Tables</title>
</head>
<body>
<section>
<ol class="collection collection-container">
<!-- The first list item is the header of the table -->
<li class="item item-container">
<div class="attribute"></div>
<div class="attribute" data-name="#">#</div>
<!-- Enclose semantically similar attributes as a div hierarchy -->
<div class="attribute-container part-information">
<div class="attribute-container part-id">
<div class="attribute" data-name="Part Number">Part Number</div>
<div class="attribute" data-name="Part Description">Part Description</div>
</div>
<div class="attribute-container vendor-information">
<div class="attribute">Vendor Number</div>
<div class="attribute">Vendor Name</div>
</div>
</div>
<div class="attribute-container quantity">
<div class="attribute">Order Qty</div>
<div class="attribute">Receive Qty</div>
</div>
<div class="attribute-container cost">
<div class="attribute">Cost</div>
<div class="attribute">Extended Cost</div>
</div>
<div class="attribute-container duty">
<div class="attribute">Duty %</div>
<div class="attribute">Duty</div>
</div>
<div class="attribute-container freight">
<div class="attribute">Freight %</div>
<div class="attribute">Freight</div>
</div>
<div class="attribute">UOM</div>
<div class="attribute">Vendor Part Number</div>
</li>
<!-- The rest of the items in the list are the actual data -->
<li class="item item-container">
<div class="attribute" data-name="Select"><input type="checkbox" name="" id=""></div>
<div class="attribute" data-name="#">1</div>
<div class="attribute-container part-information">
<div class="attribute-container part-id">
<div class="attribute" data-name="Part Number">100-10001</div>
<div class="attribute" data-name="Part Description">Description of part</div>
</div>
<div class="attribute-container vendor-information">
<div class="attribute" data-name="Vendor Number">001</div>
<div class="attribute" data-name="Vendor Name">Vendor Name A</div>
</div>
</div>
<div class="attribute-container quantity">
<div class="attribute" data-name="Order Qty">10</div>
<div class="attribute" data-name="Receive Qty">20</div>
</div>
<div class="attribute-container cost">
<div class="attribute" data-name="Cost">$5.00</div>
<div class="attribute" data-name="Extended Cost">$2.00</div>
</div>
<div class="attribute-container duty">
<div class="attribute" data-name="Duty %">3.0%</div>
<div class="attribute" data-name="Duty">$0.15</div>
</div>
<div class="attribute-container freight">
<div class="attribute" data-name="Freight %">3.0%</div>
<div class="attribute" data-name="Freight">$0.15</div>
</div>
<div class="attribute" data-name="UOM">EA</div>
<div class="attribute" data-name="Vendor Part Number">100001</div>
</li>
<li class="item item-container">
<div class="attribute" data-name="Select"><input type="checkbox" name="" id=""></div>
<div class="attribute" data-name="#">2</div>
<div class="attribute-container part-information">
<div class="attribute-container part-id">
<div class="attribute" data-name="Part Number">100-10002</div>
<div class="attribute" data-name="Part Description">A long description of part. This description may overflow.
</div>
</div>
<div class="attribute-container vendor-information">
<div class="attribute" data-name="Vendor Number">002</div>
<div class="attribute" data-name="Vendor Name">Vendor Name B</div>
</div>
</div>
<div class="attribute-container quantity">
<div class="attribute" data-name="Order Qty">10</div>
<div class="attribute" data-name="Receive Qty">20</div>
</div>
<div class="attribute-container cost">
<div class="attribute" data-name="Cost">$5.00</div>
<div class="attribute" data-name="Extended Cost">$2.00</div>
</div>
<div class="attribute-container duty">
<div class="attribute" data-name="Duty %">3.0%</div>
<div class="attribute" data-name="Duty">$0.15</div>
</div>
<div class="attribute-container freight">
<div class="attribute" data-name="Freight %">3.0%</div>
<div class="attribute" data-name="Freight">$0.15</div>
</div>
<div class="attribute" data-name="UOM">EA</div>
<div class="attribute" data-name="Vendor Part Number">E4-64B</div>
</li>
</ol>
</section>
</body>
</html>
ol.collection {
margin: 0px;
padding: 0px;
}
li {
list-style: none;
}
* {
box-sizing: border-box;
}
/* 2 Column Card Layout */
@media screen and (max-width: 736px) {
.collection-container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
}
.item {
border: 1px solid gray;
border-radius: 2px;
padding: 10px;
}
/* Don't display the first item, since it is used to display the header for tabular layouts*/
.collection-container>li:first-child {
display: none;
}
.attribute::before {
content: attr(data-name);
}
/* Attribute name for first column, and attribute value for second column. */
.attribute {
display: grid;
grid-template-columns: minmax(9em, 30%) 1fr;
}
}
/* 1 Column Card Layout */
@media screen and (max-width:580px) {
.collection-container {
display: grid;
grid-template-columns: 1fr;
}
}
/* Tabular Layout */
@media screen and (min-width: 737px) {
/* The maximum column width, that can wrap */
.item-container {
display: grid;
grid-template-columns: 2em 2em 10fr 2fr 2fr 2fr 2fr 5em 5em;
}
.attribute-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(var(--column-width-min), 1fr));
}
/* Definition of wrapping column width for attribute groups. */
.part-information {
--column-width-min: 10em;
}
.part-id {
--column-width-min: 10em;
}
.vendor-information {
--column-width-min: 8em;
}
.quantity {
--column-width-min: 5em;
}
.cost {
--column-width-min: 5em;
}
.duty {
--column-width-min: 5em;
}
.freight {
--column-width-min: 5em;
}
.collection {
border-top: 1px solid gray;
}
/* In order to maximize row lines, only display one line for a cell */
.attribute {
border-right: 1px solid gray;
border-bottom: 1px solid gray;
padding: 2px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.collection-container>.item-container:first-child {
background-color: blanchedalmond;
}
.item-container:hover {
background-color: rgb(200, 227, 252);
}
/* Center header labels */
.collection-container>.item-container:first-child .attribute {
display: flex;
align-items: center;
justify-content: center;
text-overflow: initial;
overflow: auto;
white-space: normal;
}
}
Also see: Tab Triggers