Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

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.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <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>
              
            
!

CSS

              
                .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;
}
              
            
!

JS

              
                var focusElement = function (id) {
  var element = document.getElementById(id);
  element && element.focus();
};
              
            
!
999px

Console