Created
November 23, 2015 03:01
-
-
Save Teino1978-Corp/fca18616eacb368737fe to your computer and use it in GitHub Desktop.
Selectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
"http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head><title>Static Positioning</title> | |
<link href="style.css" rel="stylesheet" type="text/css"> | |
</head> | |
<body class="element"> | |
<ul> | |
<li data-selector="element" class="selected">h2</li> | |
<li data-selector="id">div#main</li> | |
<li data-selector="class">.header</li> | |
<li data-selector="descend">div > div</li> | |
<li data-selector="complex">h2 + div > div[title~="one"]</li> | |
</ul> | |
<div title="main one"><div title="main one" /></div> | |
<h2 class="header"><h2 class="header" /></h2> | |
<div><div> | |
<div id="main" title="main one"><div id="main" title="main one" /></div> | |
<div class="header part" title="a second"><div class="header part" title="a second" /></div> | |
<div title="one more"><div title="one more" /></div></div> | |
</div> | |
<!-- Code below is to toggle source and load scripts --> | |
<button id="source">Toggle Source</button> | |
<script type="text/javascript" | |
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<script src="script.js" type="text/javascript"></script> | |
<script src="https://gist.github.com/2156149.js" type="text/javascript"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
$("li").on("click", function(event) { | |
var target = $(event.delegateTarget); | |
var body = $(document.body); | |
body.removeClass(); | |
body.addClass(target.data("selector")); | |
$("ul > li").removeClass("selected"); | |
target.addClass("selected") | |
}); | |
// Code to support toggling scripts | |
$("#source").on("click", function(event) { | |
$(".gist").toggle(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body.element h2, | |
body.id div#main, | |
body.class .header, | |
body.descend div > div, | |
body.complex h2 + div > div[title~="one"] { | |
background-color: #deb887; | |
} | |
body > ul + * { | |
margin-top: 2em; | |
} | |
body > ul { | |
padding: 1em 0 0 0; | |
margin: 0; | |
list-style-type: none; | |
width: 100%; | |
box-sizing: border-box; | |
background-color: #deb887; | |
} | |
body > ul > li { | |
padding: 0; | |
margin: 0; | |
background-color: #deb887; | |
} | |
body > ul > li.selected { | |
background-color: #ff7f50; | |
display: block; | |
position: fixed; | |
width: 100%; | |
top: 0; | |
} | |
h2 { | |
font-size: 1em; | |
margin: 0; | |
padding: 0; | |
} | |
div > div { | |
margin-left: 1em; | |
} | |
html, body { | |
padding: 0; | |
margin: 0; | |
} | |
/* Styles to support toggling the source view */ | |
.gist { | |
font-size: 0.5em; | |
display: none; | |
} | |
div.gist .gist-file { | |
position: relative; | |
margin: 3em 0; | |
} | |
.gist-meta { | |
position: absolute; | |
top: -2.5em; | |
left: -30000px; | |
} | |
.gist-meta a { | |
display: none; | |
} | |
.gist-meta a:nth-child(2) { | |
position: relative; | |
padding-left: 30000px; | |
display: inline; | |
} | |
#source { | |
float: right; | |
clear: both; | |
} | |
body { | |
font-size: 4em; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment