Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ConFoo: CSS3 Selectors
Search
Rachel Andrew
February 28, 2013
Technology
5
400
ConFoo: CSS3 Selectors
Links and notes can be found at:
http://www.rachelandrew.co.uk/presentations/css3-selectors
Rachel Andrew
February 28, 2013
Tweet
Share
More Decks by Rachel Andrew
See All by Rachel Andrew
MirrorConf: Solving Layout Problems with CSS Grid & Friends
rachelandrew
1
300
Start using CSS Grid Layout
rachelandrew
2
480
The New CSS Layout
rachelandrew
4
330
Your Speakers
rachelandrew
1
990
Flexible Boxes and Grids
rachelandrew
1
160
Configuration Management with Puppet for Developers
rachelandrew
1
130
Food hacking
rachelandrew
2
260
CSS Grid Layout for Paris Web
rachelandrew
0
1.1k
The business of front-end development
rachelandrew
1
590
Other Decks in Technology
See All in Technology
AWS Community Builderのススメ - みんなもCommunity Builderに応募しよう! -
smt7174
0
170
2025年の挑戦 コーポレートエンジニアの技術広報/techpr5
nishiuma
0
140
Alignment and Autonomy in Cybozu - 300人の開発組織でアラインメントと自律性を両立させるアジャイルな組織運営 / RSGT2025
ama_ch
1
2.4k
カップ麺の待ち時間(3分)でわかるPartyRockアップデート
ryutakondo
0
140
今から、 今だからこそ始める Terraform で Azure 管理 / Managing Azure with Terraform: The Perfect Time to Start
nnstt1
0
220
2024AWSで個人的にアツかったアップデート
nagisa53
1
110
あなたの知らないクラフトビールの世界
miura55
0
120
Docker Desktop で Docker を始めよう
zembutsu
PRO
0
160
Bring Your Own Container: When Containers Turn the Key to EDR Bypass/byoc-avtokyo2024
tkmru
0
850
[IBM TechXchange Dojo]Watson Discoveryとwatsonx.aiでRAGを実現!事例のご紹介+座学②
siyuanzh09
0
110
アジャイルチームが変化し続けるための組織文化とマネジメント・アプローチ / Agile management that enables ever-changing teams
kakehashi
3
3.3k
生成AI × 旅行 LLMを活用した旅行プラン生成・チャットボット
kominet_ava
0
150
Featured
See All Featured
Code Review Best Practice
trishagee
65
17k
Six Lessons from altMBA
skipperchong
27
3.6k
Documentation Writing (for coders)
carmenintech
67
4.5k
Speed Design
sergeychernyshev
25
740
Producing Creativity
orderedlist
PRO
343
39k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
98
18k
Building Applications with DynamoDB
mza
93
6.2k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
210
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
960
Building Your Own Lightsaber
phodgson
104
6.2k
Transcript
CSS3 Selectors Rachel Andrew: ConFoo 2013 Thursday, 28 February 13
Thursday, 28 February 13
What is CSS3? Thursday, 28 February 13
CSS3 is the next version of CSS Thursday, 28 February
13
CSS3 is Modular Thursday, 28 February 13
Some CSS3 modules are more complete than others Thursday, 28
February 13
W3C Maturity Levels Working Draft Candidate Recommendation Proposed Recommendation W3C
Recommendation Thursday, 28 February 13
CSS3 is supported by browsers Some browsers and some (parts
of) modules. Thursday, 28 February 13
Selectors module W3C Recommendation http://www.w3.org/TR/css3-selectors/ Thursday, 28 February 13
h1 {} p {} .thing {} #uniquething {} .thing p
Basic Selectors Thursday, 28 February 13
The problem with CSS2 selectors Thursday, 28 February 13
<h1>My heading</h1> <p class=”first”> ... </p> <p> ... </p> Adding
classes Thursday, 28 February 13
CSS3 Selectors “Common sense” new selectors target elements more precisely
without adding classes Thursday, 28 February 13
Attribute Selectors Select elements based on attributes Thursday, 28 February
13
form input[type="text"] { } ! form input[type="submit"] { } Attribute
Selectors Thursday, 28 February 13
Attribute Selectors Thursday, 28 February 13
label[for="fContact"] { ! float: none; ! width: auto; } Attribute
Selectors Thursday, 28 February 13
a[href ^="mailto:"] { padding-right: 20px; ! background-image:url(email.png); ! background-repeat: no-repeat;
! background-position: right center; } Attribute Selectors Thursday, 28 February 13
Structural pseudo-class selectors Thursday, 28 February 13
a:link {} a:visited {} Pseudo-Class Selectors Thursday, 28 February 13
a:hover {} a:active {} Dynamic Pseudo-Class Thursday, 28 February 13
:first-child target an element when it is the first child
of a parent element Thursday, 28 February 13
<div class=”wrapper”> <p> ... </p> <p> ... </p> <p> ...
</p> </div> :first-child Thursday, 28 February 13
:first-child Thursday, 28 February 13
.wrapper p { ! ! font-size: 1.5em; } :first-child Thursday,
28 February 13
.wrapper p:first-child { ! ! font-size: 1.5em; } :first-child Thursday,
28 February 13
:first-child Thursday, 28 February 13
:last-child target an element when it is the last child
of a parent element Thursday, 28 February 13
:last-child Thursday, 28 February 13
.navigation li:last-child { ! ! border-bottom: none; } :last-child Thursday,
28 February 13
:last-child Thursday, 28 February 13
:nth-child select multiple elements according to their position in the
document tree Thursday, 28 February 13
:nth-child Thursday, 28 February 13
tr:nth-child(odd) td { ! ! background-color: #f0e9c5; } :nth-child Thursday,
28 February 13
:nth-child Thursday, 28 February 13
tr:nth-child(3) td { ! ! background-color: #f0e9c5; } :nth-child Thursday,
28 February 13
:nth-child Thursday, 28 February 13
tr:nth-child(2n+1) td { ! ! background-color: #f0e9c5; } :nth-child http://css-tricks.com/how-nth-child-works/
Thursday, 28 February 13
:nth-of-type select multiple elements according to their position in the
document tree BUT only those elements that are the same as the type the rule is applied to. Thursday, 28 February 13
p:nth-of-type(odd) { ! ! background-color: #f0e9c5; } :nth-of-type Thursday, 28
February 13
:nth-of-type Thursday, 28 February 13
:only-child matches an element if it is the only child
element of it’s parent. Thursday, 28 February 13
li { ! list-style-type: disc; } ! li:only-child { !
list-style-type: none; } :only-child Thursday, 28 February 13
:only-child Thursday, 28 February 13
:empty matches an element if it is empty Thursday, 28
February 13
p { ! padding: 0 0 1em 0; ! margin:
0; } ! p:empty { ! padding: 0; } :empty Thursday, 28 February 13
For input elements Structural pseudo-classes for use with forms. Thursday,
28 February 13
:checked the checked state of a checkbox or radio button
Thursday, 28 February 13
.agreeterms:checked { border:2px solid blue; } :checked Thursday, 28 February
13
enabled and disabled detecting input element states Thursday, 28 February
13
input:enabled { color: #000; } :enabled Thursday, 28 February 13
input:disabled { color: #999; } :disabled Thursday, 28 February 13
The CSS3 Basic User Interface Module http://www.w3.org/TR/css3-ui/ (Working Draft) Thursday,
28 February 13
:default :valid :invalid :in-range :out-of-range :required :optional :read-only :read-write Thursday,
28 February 13
<input type="text" name="fName" id="fName" required="required" /> ! ! <input type="email"
name="fEmail" id="fEmail" required="required" placeholder="
[email protected]
" /> HTML5 attributes Thursday, 28 February 13
input:focus:required:invalid { background-image: url(error.png); background-position: 98% center; background-repeat: no-repeat; }
Adding an icon to required fields Thursday, 28 February 13
Adding an icon to required fields Thursday, 28 February 13
input:required:valid { background-image: url(accept.png); background-position: 98% center; background-repeat: no-repeat; }
Adding an icon to valid fields Thursday, 28 February 13
Adding an icon to valid fields Thursday, 28 February 13
input[type="email"]:focus:required:invalid { ! background-image: url(email_error.png); } Show a different icon
for the field type Thursday, 28 February 13
Show a different icon for the field type Thursday, 28
February 13
the Negation pseudo- class :not(selector) Thursday, 28 February 13
<p> ... </p> <p class=”box”> ... </p> <p> ... </p>
:not Thursday, 28 February 13
p:not(.box) { ! ! padding: 1em; ! ! border:2px solid
#000; ! } :not Thursday, 28 February 13
:not Thursday, 28 February 13
Pseudo-elements Thursday, 28 February 13
:first-letter the first character of the first line of text
Thursday, 28 February 13
.wrapper:first-letter { ! font-size: 200%; ! font-weight: bold; ! color:
red; } :first-letter Thursday, 28 February 13
:first-letter Thursday, 28 February 13
:first-line the first formatted line of text Thursday, 28 February
13
.wrapper:first-line { ! font-size: 200%; ! font-weight: bold; ! color:
red; } :first-line Thursday, 28 February 13
:first-line Thursday, 28 February 13
:before Render content before the element when using generated content
Thursday, 28 February 13
<div class=”content”> ... </div> :before Thursday, 28 February 13
.content:before { content: "Start here:"; } :before Thursday, 28 February
13
:before Thursday, 28 February 13
:after Render content after the element when using generated content
Thursday, 28 February 13
.content:after { content: "End here:"; } :after Thursday, 28 February
13
Generated content can be very useful... Thursday, 28 February 13
CSS Arrow Please Thursday, 28 February 13
Adding a bird Thursday, 28 February 13
.clearfix:after { visibility: hidden; display: block; font-size: 0; content: "
"; clear: both; height: 0; } .clearfix { display: inline-block; } /* start commented backslash hack \*/ * html .clearfix { height: 1%; } .clearfix { display: block; } /* close commented backslash hack */ Clear Fix Thursday, 28 February 13
::selection Content selected in browser by the user Thursday, 28
February 13
.wrapper p::selection {! background-color: red; } ::selection Thursday, 28 February
13
::selection Thursday, 28 February 13
Combinators Combining selectors to target elements Thursday, 28 February 13
Descendant Selector Select all elements that are descendants of a
specified parent Thursday, 28 February 13
.wrapper p { ! font-size: 1.5em; } Descendant Selector Thursday,
28 February 13
Child Selector Select all elements that are immediate children of
a specified parent Thursday, 28 February 13
<ul> <li>Item 1 <ol> <li>Sub list item 1</li> <li>Sub list
item 2</li> </ol> </li> <li>Item 2</li> </ul> Child Selector Thursday, 28 February 13
li { ! color: #000; } ! ul > li
{ ! color: red; } Child Selector Thursday, 28 February 13
Child Selector Thursday, 28 February 13
Adjacent Sibling Select elements that are the adjacent siblings of
an element Thursday, 28 February 13
.wrapper h1 + p { ! font-size: 1.5em; } Adjacent
Sibling Thursday, 28 February 13
Adjacent Sibling Thursday, 28 February 13
General Sibling Select elements that are the siblings of an
element Thursday, 28 February 13
.wrapper h2~p { ! color: red; } General Sibling Thursday,
28 February 13
General Sibling Thursday, 28 February 13
Browser Support Thursday, 28 February 13
Browser Support Thursday, 28 February 13
Your options Thursday, 28 February 13
Do Nothing. or serve a simpler layout to older browsers
Thursday, 28 February 13
JavaScript Plug the holes in browser support using JavaScript. Thursday,
28 February 13
div#wrapper p:first-child, div#wrapper p.first { ! ! font-size: 1.5em; }
jQuery: first-child <script src="http://code.jquery.com/jquery-latest.js"></ script> <script> $(document).ready(function(){ ! $("div#wrapper p:first-child").addClass("first"); }); </script> Thursday, 28 February 13
ul#navigation li:last-child, ul#navigation li.last { ! ! border-bottom: none; }
jQuery: last-child <script src="http://code.jquery.com/jquery-latest.js"></ script> <script> $(document).ready(function(){ ! $("ul#navigation li:last-child").addClass("last"); }); </script> Thursday, 28 February 13
tr:nth-child(odd) td, td.odd { ! background-color: #f0e9c5; } jQuery: nth-child
<script src="http://code.jquery.com/jquery-latest.js"></ script> <script> $(document).ready(function(){ ! $("tr:nth-child(odd) td").addClass("odd"); }); </script> Thursday, 28 February 13
CSS “PolyFills” plugging the holes in support Thursday, 28 February
13
What is a polyfill? A polyfill, or polyfiller, is a
piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively. http://remysharp.com/2010/10/08/what-is-a-polyfill/ Thursday, 28 February 13
selectivizr http://selectivizr.com/ Thursday, 28 February 13
Check your stats. Thursday, 28 February 13
greenbelt.org.uk Thursday, 28 February 13
IE8 Thursday, 28 February 13
var patch_css = function() { ! ! // supporting css
stuff ! ! ! ! $('input[type=submit]').addClass('submit'); ! ! $('h1+h2').addClass('stacked'); ! ! $('h1+p').addClass('stacked'); ! ! ! }; patch_css Thursday, 28 February 13
CSS3 Workflow How I approach my projects. Thursday, 28 February
13
CSS3 Workflow Develop without any polyfill or JavaScript fixes in
place. Thursday, 28 February 13
CSS3 Workflow Validate. Thursday, 28 February 13
CSS3 Workflow Test & Fix in older browsers Thursday, 28
February 13
CSS3 Workflow Decide if you need to use a polyfill
and which kind Thursday, 28 February 13
CSS3 Workflow Test again. Thursday, 28 February 13
Thank You! @rachelandrew rachelandrew.co.uk edgeofmyseat.com grabaperch.com Thursday, 28 February 13