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="root"></div>
* {
margin: 0;
padding: 0;
}
*:focus {
outline: 3px solid red;
}
// variables
$col-primary-text: #4c4c4c;
$col-link: #0088ff;
$col-border-separator: #cccccc;
$col-icon-grey: #929292;
$font-family-default: "Courier", sans-serif;
body {
font-family: $font-family-default;
color: $col-primary-text;
}
.tab-left-control {
width: 220px;
min-height: 100vh; // default 480px
background: white;
box-sizing: border-box;
border-right: 1px solid $col-border-separator;
overflow-y: scroll;
}
button.tab-control {
display: block;
width: 100%;
border: 0;
border-radius: 0;
text-align: left;
font-family: $font-family-default;
}
.tab-control-child {
font-size: 0.875rem;
color: #919191;
background: #f2f2f2;
}
.tab-control-parent {
font-size: 1.3rem;
}
.tab-control {
letter-spacing: 1px;
text-transform: uppercase;
letter-spacing: 1px;
text-transform: uppercase;
padding-top: 0.8rem;
padding-bottom: 0.8rem;
padding-left: 1rem;
box-sizing: border-box;
cursor: pointer;
&.selected {
background: $col-link;
color: white;
}
}
.tab-left-main {
position: relative;
display: flex;
}
.tab-left__content-wrapper {
width: calc(100% - 220px);
height: 100%;
}
.tab-content {
width: 100%;
min-height: 100vh;
background: orange;
padding: 1rem;
box-sizing: border-box;
}
p.large {
font-size: 6rem;
}
console.clear();
/**********************************/
// Main Tab
/**********************************/
class TabLeftMain extends React.Component {
constructor(props) {
super(props);
this.state = {
active: this.props.defaultActive
};
this.updateActive = this.updateActive.bind(this);
}
updateActive = id => {
this.setState(
{
active: id
},
() => {
// call back that can be triggered on Tab Change
this.props.onSelectedTabChange(this.state.active);
}
);
};
getTabContentChildrenForRender = () => {
return React.Children.toArray(this.props.children).find(
child => child.props.id === this.state.active
);
};
render() {
const tabContentChildren = this.getTabContentChildrenForRender();
return (
<div className="tab-left-main">
<TabLeftControl
updateActive={this.updateActive}
navData={this.props.navData}
active={this.state.active}
tabContentWrapperHeight={this.state.tabContentWrapperHeight}
/>
<div
className="tab-left__content-wrapper"
ref={tabContentWrapperRef =>
(this.tabContentWrapperRef = tabContentWrapperRef)
}
>
{tabContentChildren}
</div>
</div>
);
}
}
/**********************************/
// Tab Content Wrapper
/**********************************/
const TabContent = ({ id, active, children }) => {
const activeClass = id === active ? "selected" : "";
return <div className={`tab-content ${activeClass}`}>{children}</div>;
};
/**********************************/
// Tab Controls
/**********************************/
const TabControlUnitMain = ({ mainItem, updateActive, children, active }) => {
if (mainItem.defaultActive === active && !children) {
if (!children) {
return (
<button className="tab-control tab-control-parent selected">
{mainItem.title}
</button>
);
}
} else {
return (
<div className="tab-control-parent-wrapper">
<button
className="tab-control tab-control-parent"
onClick={() => {
updateActive(mainItem.defaultActive);
}}
>
{mainItem.title}
</button>
{children}
</div>
);
}
};
const TabControlUnitChild = ({ childItem, updateActive, active }) => {
if (active === childItem.id) {
return (
<button
className="selected tab-control tab-control-child"
onClick={() => {
updateActive(childItem.id);
}}
>
{childItem.title}
</button>
);
} else {
return (
<button
className="tab-control tab-control-child"
onClick={() => {
updateActive(childItem.id);
}}
>
{childItem.title}
</button>
);
}
};
class TabLeftControl extends React.Component {
render() {
const { updateActive, navData, active } = this.props;
return (
<div className="tab-left-control">
{navData.map(mainItem => {
if (mainItem.children.length === 0) {
return (
<TabControlUnitMain
active={active}
mainItem={mainItem}
key={mainItem.id}
updateActive={updateActive}
/>
);
} else {
return (
<TabControlUnitMain
mainItem={mainItem}
key={mainItem.id}
updateActive={updateActive}
>
{mainItem.children.map(childItem => (
<TabControlUnitChild
key={childItem.id}
childItem={childItem}
updateActive={updateActive}
active={active}
/>
))}
</TabControlUnitMain>
);
}
})}
</div>
);
}
}
const navData = [
{
id: "0.0",
title: "Metal",
defaultActive: "0.1",
children: [
{
id: "0.1",
title: "Seasons in the Abyss"
},
{
id: "0.2",
title: "There's Something. ."
}
]
},
{
id: "1.0",
title: "Food",
defaultActive: "1.1",
children: [
{
id: "1.1",
title: "Mango"
}
]
},
{
id: "2.0",
title: "Something Big",
defaultActive: "2.0",
children: []
}
];
class App extends React.Component {
render() {
return (
<TabLeftMain
onSelectedTabChange={selectedTabId => {
// triggering callback
console.log("updated tabID: ", selectedTabId);
}}
navData={navData}
defaultActive="0.1"
>
<SeasonsInTheAbyss id="0.1" />
<TheresSomething id="0.2" />
<Mango id="1.1" />
<Something id="2.0" />
</TabLeftMain>
);
}
}
// Tab Content Components
const SeasonsInTheAbyss = ({ id, active }) => (
<TabContent id={id} active={active}>
<h2>Seasons in the Abyss - Slayer</h2>
<p>
Razors edge<br /> Outlines the dead<br /> Incisions in my head<br />{" "}
Anticipation the stimulation<br /> To kill the exhilaration<br /> Close
your eyes<br />Look deep in your soul<br /> Step outside yourself<br />And
let your mind go<br /> Frozen eyes stare deep in your mind as you die<br />{" "}
Close your eyes<br /> And forget your name<br /> Step outside yourself<br />{" "}
And let your thoughts drain<br /> As you go insane, insane<br /> Inert
flesh<br />
A bloody tomb<br /> A decorated splatter brightens the room<br /> An
execution a sadist ritual <br />Mad intervals of mind residuals<br />{" "}
Close your eyes<br /> Look deep in your soul <br />Step outside yourself{" "}
<br />And let your mind go <br />Frozen eyes stare deep in your mind as
you die <br />Close your eyes and forget your name <br />Step outside
yourself and let your thoughts drain <br />As you go insane, insane<br />
Innate seed <br />To watch you bleed <br />A demanding physical need<br />{" "}
Desecrated eviscerated <br />Times prostrated
</p>
</TabContent>
);
const TheresSomething = ({ id, active }) => (
<TabContent id={id} active={active}>
<h2>There's Something on My Side - Down</h2>
<p className="large">
It took a lot to sell my soul The same thing happened yesterday I paid my
price, then felt alive But no pulse is within my veins Never will I lie
and say I'm still alive Come what may to me, there's something on my side
I'm left with heart, 'cause inside me's gone Compulsion drives me anyway I
play my part and my part is large Makes me stronger every day Never will I
lie and say I'm still alive Come what may to me, there's something on my
side One year and it ain't so bad I'm trying to see things clearly The
clearer it gets, the more I'm confused I'm thinking more about blindness
Thinking hard about blindness Thinking purely of blindness There's
something on my side There's something on my side There's something on my
side There's something on my side
</p>
</TabContent>
);
const Mango = ({ id, active }) => (
<TabContent id={id} active={active}>
<h2>Mango</h2>
</TabContent>
);
const Something = ({ id, active }) => (
<TabContent id={id} active={active}>
<h1>Something</h1>
</TabContent>
);
ReactDOM.render(<App />, document.getElementById("root"));
Also see: Tab Triggers