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.
<h1>CSS attempts at text with inline skewed background</h1>
<p class="gray">Update: Some corrections and elaborations on 18/02/2019.</p>
<h2>Notes:</h2>
<ul class="gray">
<li>Using skew is only rendered if the item is display block or inline-block.</li>
<li>Some of these look the same on a wide viewport but fail differently as the viewport width is decreased.</li>
</ul>
<section>
<h2>Attempt 1 - only use 1 element</h2>
<ul>
<li>🤷♀️ Text will be skewed the same as the background. Don't know how to straighten the text, if straight text is desired.</li>
<li>⚠️ If multiline, preceding and following text is ejected to the next line even if there is space for it inline.</li>
<li>✅ Text always stays within background.</li>
</ul>
<p class="attempt-1">Some text with some <em>skewed words</em> in the middle.</p>
<p class="attempt-1">Lorem ipsum dolor sit amet, consectetur <em>adipisicing elit. Assumenda, eius consequuntur. Culpa possimus rem quibusdam odit facilis dolorum mollitia, voluptates</em> sapiente dolor doloribus quos nam quasi, repellendus blanditiis saepe fuga.</p>
</section>
<section>
<h2>Attempt 2 - 1 element and a pseudo element</h2>
<ul>
<li>⚠️ If multiline, preceding and following text is ejected to the next line.</li>
<li>⚠️ Multi line text like this won't always sit on the background properly or will escape outside the background.</li>
<li>⚠️ Some weird z-index to get the background behind the text.</li>
</ul>
<p class="attempt-2">Some text with some <em>skewed words</em> in the middle.</p>
<p class="attempt-2">Lorem ipsum dolor sit amet, consectetur <em>adipisicing elit. Assumenda, eius consequuntur. Culpa possimus rem quibusdam odit facilis dolorum mollitia, voluptates</em> sapiente dolor doloribus quos nam quasi, repellendus blanditiis saepe fuga.</p></section>
<section>
<h2>Attempt 3 - 1 element, box-decoration-break: clone</h2>
<ul>
<li>🛑 No skew - seems to be ignored on inline elements (in Webkit at least).</li>
<li>✅ Multi line consistency</li>
<li>✅ No multiline following text eject to next line.</li>
<li>⚠️ If multiline, following lines can cover the decenders of previous line's characters.</li>
<li>⚠️ Poor multiline left-to-right gradient background color; visible lines in most cases.</li>
</ul>
<p class="attempt-3">Some text with some <em>skewed words</em> in the middle.</p>
<p class="attempt-3">Lorem ipsum dolor sit amet, consectetur <em>adipisicing elit. Assumenda, eius consequuntur. Culpa possimus rem quibusdam odit facilis dolorum mollitia, voluptates</em> sapiente dolor doloribus quos nam quasi, repellendus blanditiis saepe fuga.</p></section>
<section>
<h2>Attempt 4 - double wrapping elements</h2>
<ul>
<li>✅ Avoids pseudo element z-index issues.</li>
<li>🤷♂️ Don't know if double skewing elements causes subtle text rendering changes</li>
<li>⚠️ If multiline, preceding and following text is ejected to the next line.</li>
</ul>
<p class="attempt-4">Some text with some <em><span>skewed words</span></em> in the middle.</p>
<p class="attempt-4">Lorem ipsum dolor sit amet, consectetur <em><span>adipisicing elit. Assumenda, eius consequuntur. Culpa possimus rem quibusdam odit facilis dolorum mollitia, voluptates</span></em> sapiente dolor doloribus quos nam quasi, repellendus blanditiis saepe fuga.</p>
</section>
<section>
<h2>Attempt 5 - double pseudo elements at ends</h2>
<ul>
<li>⚠️ Poor multiline rendering. Pseudo elements don't always line up nicely. Can cause sharp corners or gaps.</li>
<li>⚠️ If multiline, preceding and following text is ejected to the next line.</li>
</ul>
<p class="attempt-5">Some text with some <em>skewed words</em> in the middle.</p>
<p class="attempt-5">Lorem ipsum dolor sit amet, consectetur <em>adipisicing elit. Assumenda, eius consequuntur. Culpa possimus rem quibusdam odit facilis dolorum mollitia, voluptates</em> sapiente dolor doloribus quos nam quasi, repellendus blanditiis saepe fuga.</p>
</section>
$c1: mediumturquoise;
$c2: mediumpurple;
$g1: linear-gradient(to right, $c1, $c2);
.attempt-1{
font-size: 1.5rem;
em{
font-style: normal;
padding: 0.1em 0.3em;
border-radius: 0.2em;
position: relative;
background: white;
background: $g1;
transform: skewX(-10deg);
display: inline-block;
}
}
.attempt-2{
font-size: 1.5rem;
position: relative;
z-index: 0;
em{
font-style: normal;
padding: 0.1em 0.3em;
position: relative;
display: inline-block;
&::after{
content: "";
position: absolute;
background: white;
background: $g1;
top:0;
left:0;
right:0;
bottom:0;
z-index: -1;
border-radius: 0.2em;
transform: skewX(-10deg);
}
}
}
.attempt-3{
font-size: 1.5rem;
em{
font-style: normal;
position: relative;
display: inline;
box-decoration-break: clone;
padding: 0.1em 0.2em;
border-radius: 0.2em;
background: white;
background: $g1;
transform: skewX(-10deg); // this is ignored on inline elements, in Webkit at least.
}
}
.attempt-4{
font-size: 1.5rem;
em{
display: inline-block;
font-style: normal;
padding: 0.1em 0.3em;
border-radius: 0.2em;
position: relative;
background: white;
background: $g1;
transform: skewX(-10deg);
span{
display: inline-block;
transform: skewX(10deg);
}
}
}
.attempt-5{
font-size: 1.5rem;
position: relative;
z-index: 0;
em{
font-style: normal;
padding: 0.1em 0;
margin-left: 0.5em;
margin-right: 0.5em;
position: relative;
background: white;
background: $g1;
display: inline-block;
&::before,
&::after{
content: "";
border-radius: 0.2em;
background: white;
display: inline-block;
width: 1em;
transform: skewX(-10deg);
position: absolute;
z-index: -1;
}
&::before{
top: 0;
bottom: 0;
left: -0.3em;
background: $c1;
}
&::after{
top: 0;
bottom: 0;
right: -0.3em;
background: $c2;
}
}
}
/* Setup CSS unrelated to core task. */
body{
background: #ccc;
background: linear-gradient(to right, #abd, #bce);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-weight: 300;
width: min(90vw, 600px);
margin-left: auto;
margin-right: auto;
margin-top: 5rem;
margin-bottom: 5rem;
}
section {
background: rgba(white,.6);
padding: 2rem;
margin: 2rem auto;
border-radius: 0.3rem;
border: 1px solid rgba(white,.2);
}
h1,
h2{
font-weight: 400;
}
.gray {
color: #666;
}
li{
margin-bottom: 0.5em;
}
Also see: Tab Triggers