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 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.
<h1>What element can be selected with mouse</h1>
<div>
<p>I met a problem when I tried to select a link in Chrome. I just can select the link. I noticed that, that link is a little special. When I click at the wrapper of that link, the link will be focused. So I think there may be some relation with the focus. So I wrote this article. This verify my thought. I also verify some other conditions.</p>
<h2>Conclusion</h2>
<p>An element can be selected only if its first parent/grandparent which can be focused (which tabindex=0) is focused.</p>
<p><b>Note: </b>this may be not absolute accurate. Please leave a comment if you have any correction.</p>
</div>
<h2>Tests</h2>
<p>When you try to select an element (in this article, the element is a hyperlink), you should move your mouse after the element, then press your mouse and drag it to through the element. At last release the mouse. If <b>succeed to select</b>, the element will have a high contrast background and color. Like this <span class="selected">I am selected</span></p>
<p>In this article, the normal hyperlink looks like this <a href="#">normal</a>. The focused hyperlink looks like this <a href="#" class="focused">focused</a>. The normal wrapper looks likes this <span class="wrapper note-wrapper">normal</span>. The wrapper which is focused looks like this <span class="wrapper focused note-wrapper">focused</span></p>
<div tabindex="0" class="wrapper" onFocus="focusElement('link')">
<h3>Test 1. When wrapper get the focus, it will focus the link inside</h3>
<p><span>For test</span><a id="link" href="#">This <span class="not">can not</span> be selected in Chrome as the link is already focused, but <span class="can">can</span> be selected in Firefox</a></p>
</div>
<div tabindex="0" class="wrapper" onFocus="focusElement('link')">
<h3>Test 2. When wrapper get the focus, it will focus the link out of this wrapper (more specifically, it will focus the link in Test 1)</h3>
<p><span>For test</span><a href="#">This <span class="not">can not</span> be selected in Chrome as the focus is out of its parent, but <span class="can">can</span> be selected in Firefox (not perfect)</a></p>
</div>
<div tabindex="0" class="wrapper" onFocus="focusElement('siblingLink')">
<h3>Test 3. When wrapper get the focus, it will focus a link inside</h3>
<p><a href="#" id="siblingLink">The sibling Link that will be focused automatically</a></p>
<p><span>For test</span><a href="#">This <span class="not">can not</span> be selected in Chrome as its sibling is focused, but <span class="can">can</span> be selected in Firefox (not perfect)</a></p>
</div>
<div tabindex="0" class="wrapper" id="parentWrapper">
<h3>Test 4. When wrapper get the focus, it will focus its parent</h3>
<div tabindex="0" class="wrapper" onFocus="focusElement('parentWrapper')">
<p><span>For test</span><a href="#">This <span class="not">can not</span> be selected in Chrome as its grandparent wrapper is focused, but <span class="can">can</span> be selected in Firefox (not perfect)</a></p>
</div>
</div>
<div tabindex="0" class="wrapper" id="parentWrapper">
<h3>Test 5. When wrapper get the focus, it will focus its parent</h3>
<p>This is a little different with Test 4. The parent of following hyperlink have no property tabindex.</p>
<div class="wrapper" onFocus="focusElement('parentWrapper')">
<p><span>For test</span><a href="#">This <span class="can">can</span> be selected in Chrome even though its grandparent wrapper is focused, because its parent cannot be focused (without tabindex=0)</a></p>
</div>
</div>
<div tabindex="0" class="wrapper" id="selfWrapper" onFocus="focusElement('selfWrapper')">
<h3>Test 6. When wrapper get the focus, it will focus itself (manually)</h3>
<p><span>For test</span><a href="#">This <span class="can">can</span> be selected as its parent wrapper is focused</a></p>
</div>
<div tabindex="0" class="wrapper">
<h3>Test 7. When wrapper get the focus, do nothing</h3>
<p><span>For test</span><a href="#">This <span class="can">can</span> be selected as its parent wrapper is focused</a></p>
</div>
.wrapper {
padding: 10px;
border: 1px solid #cdcdcd;
margin-bottom: 10px;
}
.wrapper:focus,
.wrapper.focused {
border: 1px solid #f00;
outline: none;
}
.wrapper a {
text-decoration: none;
outline: none;
}
.wrapper a:focus,
.wrapper a:hover,
.wrapper a:active,
a.focused {
color: #f00;
text-decoration: underline;
}
.wrapper span {
display: inline-block;
padding-left: 10px;
padding-right: 10px;
margin-right: 10px;
background-color: #00f;
color: #fff;
}
span.can {
background-color: transparent;
color: #096;
padding: 0;
margin: 0;
}
span.not {
background-color: transparent;
color: #f00;
padding: 0;
margin: 0;
}
span.selected {
background-color: #09f;
color: #fff;
}
.note-wrapper {
display: inline-block;
}
var focusElement = function (id) {
var element = document.getElementById(id);
element && element.focus();
};
Also see: Tab Triggers