A Pen by ChihMingChang on CodePen.
Last active
October 20, 2016 18:05
-
-
Save cchang62/da9f21e3e901f83e93972c943746f0d0 to your computer and use it in GitHub Desktop.
Css Selector
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
<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors --> | |
<div class="hello-example"> | |
<a href="http://example.com">English:</a> | |
<span lang="en-us en-gb en-au en-nz">Hello World!</span> | |
</div> | |
<div class="test"> | |
<div class="hello-example"> | |
<a href="#portuguese">Portuguese:</a> | |
<span lang="pt">Olá Mundo!</span> | |
</div> | |
</div> | |
<div class="classSelector"> | |
<div class='hello-ex'> | |
<a href="#japanese">Japanese:</a> | |
<span lang="jp">「こんにちは世界」</span> | |
</div> | |
</div> | |
<div class="hello-example"> | |
<a href="http://example.cn">Chinese (Simplified):</a> | |
<span lang="zh-CN">世界您好!</span> | |
</div> | |
<div class="hello-example"> | |
<a href="http://example.cn">Chinese (Traditional):</a> | |
<span lang="zh-TW">世界您好!</span> | |
</div> |
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
//Practice DOMLogger | |
function DOMLogger(elem) { | |
var obj = document.querySelectorAll(elem); | |
console.log("DOMLogger: "); | |
console.dir(obj); | |
} |
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
/* All spans with a "lang" attribute are bold */ | |
span[lang] {font-weight:bold;} | |
/* All spans in Portuguese are green */ | |
span[lang="pt"] {color:green;} | |
/* All spans in US English are blue */ | |
span[lang~="en-us"] {color: blue;} | |
/* Any span in Chinese is red, matches | |
simplified (zh-CN) or traditional (zh-TW) */ | |
span[lang|="zh"] {color: red;} | |
/* All internal links have a gold background */ | |
a[href^="#"] {background-color: gold;} | |
/* All spans whose first declared class begins with "main" have a yellow background */ | |
/* Span with the class="banner main" would not be affected. */ | |
span[class^="main"] {background-color: yellow;} | |
/* All links to urls ending in ".cn" are red */ | |
a[href$=".cn"] {color: red;} | |
/* All links with "example" in the url have a grey background */ | |
a[href*="example"] {background-color: #CCCCCC;} | |
/* All email inputs have a blue border */ | |
/* This matches any capitalization of | |
"email", e.g. "email", "EMAIL", "eMaIL", etc. */ | |
input[type="email" i] {border-color: blue;} | |
div[class*="test"]{border-color: black;} | |
.classSelector [class*="hello"]{background-color: pink;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Practice css selector: match part of class string