Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mgiulio/63041e79c006b7511254 to your computer and use it in GitHub Desktop.
Save mgiulio/63041e79c006b7511254 to your computer and use it in GitHub Desktop.
Scrolling wrapper left on checking a checkbox
<h1>Scroll a block to right and then click a label</h1>
<h3>Hide a checkbox using "left: -9999px;"</h3>
<p>I'm scrolling left on checking</p>
<div class="wrapper">
<div class="inner">
<input class="option1" type="checkbox" id="some-id-1" />
<label for="some-id-1">scroll right and then click me</label>
</div>
</div>
<h3>Hide a checkbox using "visibility: hidden;"</h3>
<p>I'm NOT scrolling left on checking</p>
<div class="wrapper">
<div class="inner">
<input class="option2" type="checkbox" id="some-id-2" />
<label for="some-id-2">scroll right and then click me</label>
</div>
</div>
// CHECKBOXES OPTIONS
.option1{
position: absolute;
left: -9999px;
}
.option2{
position: absolute;
visibility: hidden;
}
// COMMON
.wrapper{
width: 300px;
overflow-x: auto;
}
.inner{
width: 500px;
text-align: center;
}
[type=checkbox] + label{
background-color: green;
}
[type=checkbox]:checked + label{
background-color: yellow;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment