Skip to content

Instantly share code, notes, and snippets.

@andyfitz
Created October 3, 2012 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyfitz/3824547 to your computer and use it in GitHub Desktop.
Save andyfitz/3824547 to your computer and use it in GitHub Desktop.
using neighbour selectors to style and adjust e-reader preferences
<article class="book-reader">
<input type="checkbox" id="fullscreen">
<label for="fullscreen"></label>
<input type="checkbox" id="invert">
<label for="invert"></label>
<header>
<a href="#home">Home</a>
<h1><a href="#">Book</a></h1>
</header>
<nav>
<ul>
<li><a href="#">previous</a></li>
<li><a href="#">contents</a></li>
<li><a href="#">next</a></li>
</ul>
</nav>
<section>
<div class="page">
<h1> Click the top right buttons!</h1>
<p>Quinoa magna pitchfork pickled food truck, irony cliche single-origin coffee. Irure skateboard gastropub bushwick. Beard mollit wes anderson PBR, food truck reprehenderit fanny pack officia mustache before they sold out. Before they sold out gastropub consectetur ut synth, consequat ethical. Placeat ethnic flexitarian, chillwave laboris mlkshk sartorial cred semiotics odio aute keffiyeh selvage street art. Banh mi placeat adipisicing veniam nostrud, put a bird on it williamsburg eiusmod kogi art party. Assumenda aliqua delectus accusamus.
</p>
<p>
Officia post-ironic VHS, incididunt pork belly single-origin coffee viral mumblecore four loko truffaut. Vice organic hoodie reprehenderit duis pitchfork. Beard raw denim direct trade ea lomo. Lo-fi labore ut, wes anderson nostrud velit blog nisi put a bird on it sartorial commodo stumptown. Authentic sriracha voluptate nisi gastropub. Non adipisicing in, magna twee flexitarian leggings cosby sweater photo booth sartorial farm-to-table fap fixie shoreditch Austin. Est marfa squid, mixtape sed minim fugiat polaroid mcsweeney's sustainable.</p>
<img src="http://theawesomer.com/photos/2010/06/061210_venn_diagram_math_1.jpg" alt="" />
<p>Irure fugiat odd future, marfa eiusmod Austin craft beer aute mumblecore pitchfork banh mi viral helvetica butcher veniam. Chillwave nisi anim kale chips, mcsweeney's photo booth truffaut. Typewriter letterpress next level tumblr, bushwick odio dreamcatcher 3 wolf moon helvetica. Terry richardson beard squid irony, ethnic post-ironic vegan. Ethical pinterest exercitation laborum, aute proident put a bird on it carles magna DIY wayfarers. High life wes anderson polaroid, fanny pack vegan occaecat veniam. Aliquip in helvetica, messenger bag fingerstache put a bird on it lo-fi veniam anim assumenda stumptown.
</p>
<img src="http://d3gqasl9vmjfd8.cloudfront.net/cbd6879c-fcf9-4685-83aa-488e78584eec.png" />
</div>
</section>
</article>
// nojavascript boieeee
// noScript users rejoice in their functional book reader.
// text from hipsteripsum
@import "compass";
@import url(http://fonts.googleapis.com/css?family=Open+Sans:300,600);
$grey: #777;
$baseline: 1.75em;
body{
/*for demo only -
this should really be applied to
your container div*/
top:0;
bottom:0;
left:0;
right:0;
position:absolute;
display:block;
height: 100%; width:100%;
margin:0 auto;
overflow:hidden;
background-color:$grey;
position:relative;
position:fixed;
padding:0em;
background-color:lighten($grey, 10%);
font:{
family:"Open Sans", sans-serif;
weight: 300;
size: 16px;
}
line-height:$baseline;
}
*{box-sizing: border-box;}
/*base style for book and chrome - no magic yet */
.book-reader{
header,nav{user-select:none;}
header{height: $baseline*2;
@include box-shadow(
0 .5em 1em rgba(0,0,0,0.4),
inset 0 -1px rgba(0,0,0,0.6),
inset 0 -2px rgba(255,255,255,0.15));
@include background(
linear-gradient(top ,
lighten(rgba(0,0,0,0.0), 0%) 0%,
darken(rgba(0,0,0,0.4), 10%) 99%));
z-index:99;
position:fixed;
width: 100%;
background-color: #444;
a{line-height:$baseline*2;
text-decoration: none;
display:inline-block;
color:#aaa; &:hover{
color: white;
}
}
h1{position: absolute;
top:0;
text-align:center; font-weight: 600;
width: 100%;
font-size: $baseline/1.5;
line-height: $baseline;
a{padding:0 1em;
line-height:$baseline;
display:inline;
z-index:9; box-shadow: none;
}
}
a[href="#home"]{
z-index:9;
position:relative;
color: #888;
&:hover{
color:white
}
@include box-shadow(
inset -1px 0 rgba(255,255,255,0.2),
inset -2px 0 rgba(0,0,0,0.4));
text-align:center;
background-color:rgba(0,0,0,0.13);
display:block;
width: 12em; }
}
nav{
position:absolute;
z-index:8;
bottom:0;
@include background(
linear-gradient(top ,
lighten(rgba(0,0,0,0.0), 0%) 0%,
darken(rgba(0,0,0,0.5), 10%) 99%));
display:table;
width: 100%;
padding:0;
line-height: $baseline*2;
height: $baseline*2;
background:{
color:#555;
}
@include box-shadow( 0 0 1em rgba(0,0,0,0.4), inset 0 1px rgba(0,0,0,0.6), inset 0 2px rgba(255,255,255,0.3));
color:white;
text-transform: capitalize;
ul{display:table-row;
list-style:none;
margin:0;padding:0;
li{display:table-cell; width: 33.3333%;
a{color:#aaa;text-decoration: none;display:block; width: 100%; text-align:center; &:hover{color:white; background-color: rgba(0,0,0,0.2);;}
}
}
}
}
header, nav{transition: all .2s ease;}
section{ transition: all .13s ease;
background-color: #fafafa; text-shadow: 0 1px #fff;
position:absolute;
padding: 2em;
overflow: auto;
top: $baseline*2;
bottom: $baseline*2;
width: 90%; left: 5%;
/*@include box-shadow( inset 0 0 5em rgba(0,0,0,0.3), 0 0 1em rgba(0,0,0,0.4));*/
@include background(
linear-gradient(left ,
#ddd 0%,
#fafafa 9%,
#fafafa 91%,
#ddd 100%));
.page{
max-width: 40em;
margin: $baseline auto; }
p{margin: $baseline auto ;
color: #666;}
h1{
font-size:$baseline*1.5;
color:#444;
font-weight: 300;
}
}
img{
padding:1em;
background-color: white;
box-shadow: 0 .2em .5em rgba(0,0,0,0.2);
width: 100%; }
a{transition: all .15s ease;
@include box-shadow(
inset 1px 0 rgba(255,255,255,0.2),
inset 2px 0 rgba(0,0,0,0.52));}
}
/*
,__ __
/| | | o
| | | __, __, __
| | | / | / | | /
| | |_/\_/|_/\_/|/|_/\___/
/|
\|
here is the fullscreen magic
you can use this technique to do other magic things like themed styles. scaling text and anything else you can do with css and a toggle to invoke it
*/
label[for="fullscreen"], label[for="invert"]{
transition:all .2s ease;
background-color: rgba(255,255,255,0.05);
position: absolute;
top:0; right:0%;
text-align:center;
padding:0 2em;
z-index:100; color:white;
height: $baseline*2;
cursor:pointer;
width: 11em;
line-height: $baseline*2;
user-select:none;
@include box-shadow(
inset 1px 0 rgba(255,255,255,0.2),
inset 2px 0 rgba(0,0,0,0.52));
&:hover{
background-color: #730;
}
}
#fullscreen{
position:absolute;
top: 0;
z-index:-1;
opacity:0;
/* neighbour selector all up in this*/
&:checked ~ nav{bottom: -$baseline*2;}
&:checked ~ header{top: -$baseline*2;}
&:checked ~ section{top:0; bottom:0;}
&:checked ~ label[for="invert"]{top: -$baseline*2;}
&:checked ~ label[for="fullscreen"]{ width: 7em; padding:0;
color:#aaa;
background-color:#fff;
@include box-shadow(
inset 0 0 0 1px #fff,
inset 0 0 0 2px #eee,
0 .2em .4em rgba(0,0,0,0.2));
&:before{content: "Exit";}
}
}
@media
(max-width: 50em),
(max-height: 25em)
{
body{font-size:12px !important}
}
label[for="invert"]{right: 11em; width: 6em;
&:before{content: "go dark"}
}
#invert{
position:absolute;
top: 2em;
z-index:-1;
opacity:0;
&:checked ~ label{color: white; background-color: rgba(0,0,0,0.35) ;
&:before{content: "Day"}
}
&:checked ~ section{
background-image: none;
background-color: black ; box-shadow: 0 0 0 14em rgba(0,0,0,0.8); color: white ; text-shadow: none;
p, h1{color: white}}
}
label[for="fullscreen"]:before{content: "Fullscreen";}
label[for="invert"]:before{content: "Night"; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment