SlideShare ist ein Scribd-Unternehmen logo
1 von 106
Downloaden Sie, um offline zu lesen
CSS Lessons Learned the Hard Way 
Zoe Mickley Gillenwater 
@zomigi 
Generate Conference 
London 26 September 2014
I make things…
…some of which come out nicely…
Web sites
Books 
Stunning CSS3: A Project-based Guide to the Latest in CSS 
www.stunningcss3.com 
Flexible Web Design: Creating Liquid and Elastic Layouts with CSS 
www.flexiblewebbook.com
Kids
Cakes
…but sometimes I make mistakes…
Gardening
Gardening 
https://www.flickr.com/photos/coachjeff/3600883487/
“I can’t start until I know enough to do it perfectly.”
You don’t need everything 
http://www.flickr.com/photos/montage_man/4713541238/
Start using Sass in four easy steps.
Install Prepros from http://alphapixels.com/prepros/ 
Step 1
Drag your web site’s folder into Prepros. 
Step 2
In this folder, create a file named styles.scss. 
Step 3
Write in it this: 
Step 4 
$green: #4F9F1A; 
$blue: #1D6783; 
$lightgray: #D6D6D6; 
body { 
background: $lightgray; 
color: $green; 
} 
a { 
color: $blue; 
} 
button { 
background: $blue; 
color: $lightgray; 
}
Never compare your inside with somebody else’s outside.
If you walk around with the idea that there are some people who are so gifted—they have these wonderful things in their head, but you’re not one of them, you’re just sort of a normal person, you could never do anything like that— then you live a different kind of life. 
Brian Eno
Innovation requires a mindset that rejects the fear of failure and replaces that fear of failure with the joy of exploration and experimental learning. 
Dr. Edward D. Hess
We also need to accept and embrace the concept of failure, not because failure is a good thing but because it’s a natural part of the path of progress. If you’re failing, at least that means you’re trying — not remaining on the outside of the arena, looking in. 
Helen Walters
Creative people experiment a lot more, therefore succeed a lot more, therefore fail a lot more.
Some of my recent CSS mistakes
Flexbox demo 
www.smoresday.us 
Use Chrome, Opera, Safari 7, Firefox 28+, or IE 10+ for full effect
.action 
.component
HTML without flexbox 
<form class="builder"> 
<div class="wrap"> 
<section class="component"> 
<section class="component"> 
<section class="component"> 
<section class="component"> 
</div> 
<section class="action"> 
</form>
HTML for flexbox version 
<form class="builder"> 
<section class="component"> 
<section class="component"> 
<section class="component"> 
<section class="component"> 
<section class="action"> 
</form>
Allow boxes to wrap 
.builder { 
display: flex; 
flex-wrap: wrap; 
justify-content: space-between; 
margin: 0 0 40px -20px; 
}
Using flex to control width/height 
.flex-item { 
flex: 1 0 100px; 
} 
flex-grow 
flex-shrink 
flex-basis
Defining the flex property 
flex-grow 
how much flex item will grow relative to other items if extra space is available (proportion of extra space that it gets) 
flex-shrink 
how much item will shrink relative to others if there is not enough space (proportion of overflow that gets shaved off) 
flex-basis 
the initial starting size before free space is distributed (any standard width/height value, including auto)
My first attempt 
.component { 
flex: 1; 
} 
.action { 
flex: 1 1 100%; 
} 
Zoe’s Brain Said: 
“Since .action starts out at 100%, it won’t have space to sit on the first line with the content preceding it, and will wrap to a second line.”
Flexbox fail
This fixed it 
.component { 
flex: 1; 
margin-right: 1px; 
}
/* this is needed to make .action wrap to second line. why??? */ 
My comment on the 1px margin
The hidden flex-basis value 
.component { 
flex: 1 1 0px; 
} 
.action { 
flex: 1 1 100%; 
} 
Reality: 
Since it’s fine for each .component to shrink to only 0px wide, a 100% wide element can and will sit on the same line as all the components.
That’s why margin “fixed” it 
.component { 
flex: 1; 
margin-right: 1px; 
} 
.action { 
flex: 1 1 100%; 
} 
What’s happening: 
Now each .component starts out taking up 1px of space, so a 100% wide element can’t and won’t sit on the same line with any of the components.
Fixing flex-basis to force the wrap 
.component { 
flex: 1 1 200px; 
} 
.action { 
flex: 1 1 100%; 
} 
Fixed: 
.action will always wrap to new line, and .component boxes will wrap to additional lines when there’s less space than their combined flex-basis values (plus margin, etc.).
This was not just a case of succeeding despite a mistake. It was a case of succeeding because of a mistake.
flex-basis mistake round two
flex can be proportional 
Setting flex-grow/flex-shrink to different values can make flex items size themselves relative to each other 
flex: 1; 
flex: 1; 
flex: 2;
Trying to make one twice as wide 
.gallery-item { 
flex: 1 0 200px; 
} 
.feature { 
flex: 2 0 200px; 
}
Expected rendering
Actual rendering
What I figured out 
Having widths be in multiples of each other only works if flex-basis is 0 
flex: 1 0 0px; 
flex: 1 0 0px; 
flex: 2 0 0px;
If flex-basis isn’t 0px… 
…the widths may not end up as you expect 
The third box gets twice as much of the extra, but that doesn’t make it twice as wide overall 
flex: 1 0 10px; 
flex: 1 0 10px; 
flex: 2 0 10px; 
10px + 5px extra = 15px 
10px + 5px extra = 15px 
10px + 10px extra = 20px 
if 50px available
It’s because flex-basis = 200px
I really get flex-basis now
Takeaway: don’t use CSS shorthand without understanding all the pieces
Let’s talk about another mistake
Shadow style inspiration 
http://sliderpro.net/examples/minimal-slider/
The plan: create shadow with generated content, skew it with CSS perspective
My first attempt 
.lightbox:before { 
content: ""; 
position: absolute; 
z-index: -2; 
left: 2%; 
bottom: 0; 
width: 96%; 
height: 1px; 
box-shadow: 0 25px 30px 15px hsla(0,0%,0%,.4); 
transform: perspective(20em); 
}
Perspective fail
What does rotateX actually do?
The 3 axes 
X horizontal, left-right 
Y vertical, up-down 
Z away-towards you 
A helpful diagram: your hand. 
Photo: http://www.smashingmagazine.com/2012/01/06/adventures-in-the-third-dimension-css-3-d-transforms/
Or, if your hand is effed up: 
http://architecture.gtu.ge/MPL/Multimodal%20Explorer/Acad_11/14control_workplane0/control_workplane.htm
Rotate around the axis not in the direction of the axis 
As explained well by Peter Gasston in http://www.smashingmagazine.com/2012/01/06/adventures- in-the-third-dimension-css-3-d-transforms/
My quick sketch
Adding rotateX with perspective 
.lightbox:before { 
content: ""; 
position: absolute; 
z-index: -2; 
left: 6%; 
bottom: 0; 
width: 88%; 
height: 1px; 
box-shadow: 0 25px 30px 15px hsla(0,0%,0%,.4); 
transform: perspective(20em) rotateX(50deg); 
}
Perspective working
Takeaway: sometimes pen and paper can make a new concept real to you
A more public mistake
Sometimes you need to add special content for screen reader users…
…and occasionally you need to hide content from screen reader users.
I needed CSS classes to: 
1.Hide content visually and aurally 
2.Hide just the text of an element, not whole element, but keep text spoken 
3.Hide whole element visually but keep its text spoken by screen readers
Hide content visually and aurally 
.hidden-silent { 
display: none; 
visibility: hidden; 
}
Hide text only but keep it spoken 
.hidden-text-spoken { 
text-indent: -999em; 
overflow: hidden; 
display: inline-block; 
}
Hide element but keep it spoken 
Yahoo! Accessibility blog said to use: 
.hidden-spoken { 
position: absolute !important; 
clip: rect(1px 1px 1px 1px); /* IE 6-7 */ 
clip: rect(1px, 1px, 1px, 1px); 
padding: 0 !important; 
border: 0 !important; 
height: 1px !important; 
width: 1px !important; 
overflow: hidden; 
} 
Article now online at https://developer.yahoo.com/blogs/ydn/clip-hidden-content-better-accessibility-53456.html
Problem: NVDA in Firefox wouldn’t read <label> with this class
Delete half the code, see if bug goes away, repeat
I narrowed it down to overflow: hidden 
Removing this part caused labels to be read correctly in Firefox by NVDA
But removing it still kept the content hidden. 
So why was it there to begin with?
This scrollbar is what overflow fixes
Now that I understood what overflow did, I could decide if I needed it.
How I fixed my mistake 
•Removed overflow:hidden from new instances going forward (but sadly not fixed in existing style sheets) 
•Updated documentation to advise adding it on as-needed basis
(By the way, this FF/NVDA bug seems to be gone now.)
Takeaway: one-size-fits-all isn’t always best for your needs
Takeaway: you can get help when you share your confusion publicly
Be willing to fail…
…and then tell us about it.
Vulnerability is not weakness. And that myth is profoundly dangerous. 
Dr. Brené Brown
Vulnerability is the birthplace of innovation, creativity, and change. To create is to make something that has never existed before. There's nothing more vulnerable than that. 
Dr. Brené Brown
We all do imperfect work
/* this is needed to make .action wrap to second line. why??? */
The evidence in the comments 
// Dear future me. Please forgive me. // I can't even begin to express how sorry I am. 
// I am not sure if we need this, but too scared to delete. 
// Magic. Do not touch.
Revisiting comments 
// TODO: Fix this. Fix what? 
// somedev1 - 6/7/02 Adding temporary tracking of Login screen // somedev2 - 5/22/07 Temporary my ass
YAY! Mediocrity!
YAY! Being human!
Hiding mistakes seems to be human nature
But sharing mistakes has benefits
Try to shift “Who can I blame?” to “Who can I teach?”
http://www.flickr.com/photos/stilleben/49644790/
99% of the population of the world doesn’t know CSS. 
Zoe’s made-up statistic
You are awesome, but and you make mistakes.
Let’s use our confidence in our skills to build others up and bravely admit our own shortcomings.
Thank you 
Zoe Mickley Gillenwater 
@zomigi 
Generate Conference 
London 26 September 2014

Weitere ähnliche Inhalte

Was ist angesagt?

[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
Christopher Schmitt
 
jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013
dmethvin
 

Was ist angesagt? (20)

Web Development for UX Designers
Web Development for UX DesignersWeb Development for UX Designers
Web Development for UX Designers
 
Stop reinventing the wheel: Build Responsive Websites Using Bootstrap
Stop reinventing the wheel: Build Responsive Websites Using BootstrapStop reinventing the wheel: Build Responsive Websites Using Bootstrap
Stop reinventing the wheel: Build Responsive Websites Using Bootstrap
 
Harness jQuery Templates and Data Link
Harness jQuery Templates and Data LinkHarness jQuery Templates and Data Link
Harness jQuery Templates and Data Link
 
Front End Best Practices
Front End Best PracticesFront End Best Practices
Front End Best Practices
 
Responsive design: techniques and tricks to prepare your websites for the mul...
Responsive design: techniques and tricks to prepare your websites for the mul...Responsive design: techniques and tricks to prepare your websites for the mul...
Responsive design: techniques and tricks to prepare your websites for the mul...
 
Decoupling the Front-end with Modular CSS
Decoupling the Front-end with Modular CSSDecoupling the Front-end with Modular CSS
Decoupling the Front-end with Modular CSS
 
Real World Web components
Real World Web componentsReal World Web components
Real World Web components
 
jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009jQuery For Beginners - jQuery Conference 2009
jQuery For Beginners - jQuery Conference 2009
 
Accessibility - A feature you can build
Accessibility - A feature you can buildAccessibility - A feature you can build
Accessibility - A feature you can build
 
HTTP 2.0 - Web Unleashed 2015
HTTP 2.0 - Web Unleashed 2015HTTP 2.0 - Web Unleashed 2015
HTTP 2.0 - Web Unleashed 2015
 
Responsive & Responsible Web Design in DNN
Responsive & Responsible Web Design in DNNResponsive & Responsible Web Design in DNN
Responsive & Responsible Web Design in DNN
 
Modern Front-End Development
Modern Front-End DevelopmentModern Front-End Development
Modern Front-End Development
 
Web Design Primer Sample - HTML CSS JS
Web Design Primer Sample - HTML CSS JSWeb Design Primer Sample - HTML CSS JS
Web Design Primer Sample - HTML CSS JS
 
State of jQuery June 2013 - Portland
State of jQuery June 2013 - PortlandState of jQuery June 2013 - Portland
State of jQuery June 2013 - Portland
 
PrairieDevCon 2014 - Web Doesn't Mean Slow
PrairieDevCon 2014 -  Web Doesn't Mean SlowPrairieDevCon 2014 -  Web Doesn't Mean Slow
PrairieDevCon 2014 - Web Doesn't Mean Slow
 
Fundamental JQuery
Fundamental JQueryFundamental JQuery
Fundamental JQuery
 
Whirlwind Tour of SVG (plus RaphaelJS)
Whirlwind Tour of SVG (plus RaphaelJS)Whirlwind Tour of SVG (plus RaphaelJS)
Whirlwind Tour of SVG (plus RaphaelJS)
 
Front-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewFront-End Frameworks: a quick overview
Front-End Frameworks: a quick overview
 
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
 
jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013jQueryTO: State of jQuery March 2013
jQueryTO: State of jQuery March 2013
 

Andere mochten auch

Тестирование требований
Тестирование требованийТестирование требований
Тестирование требований
ISsoft
 
Images and Tables in HTML
Images and Tables in HTMLImages and Tables in HTML
Images and Tables in HTML
Aarti P
 
Сергей Бережной "Про шаблонизаторы вообще и BEMHTML в частности"
Сергей Бережной "Про шаблонизаторы вообще и BEMHTML в частности"Сергей Бережной "Про шаблонизаторы вообще и BEMHTML в частности"
Сергей Бережной "Про шаблонизаторы вообще и BEMHTML в частности"
Yandex
 
Bdd and dsl как способ построения коммуникации на проекте
Bdd and dsl как способ построения коммуникации на проектеBdd and dsl как способ построения коммуникации на проекте
Bdd and dsl как способ построения коммуникации на проекте
ISsoft
 
Верстка_Лекция1
Верстка_Лекция1Верстка_Лекция1
Верстка_Лекция1
itc73
 
решение основной проблемы Agile (scrum) проектов в контексте ba
решение основной проблемы Agile (scrum) проектов в контексте baрешение основной проблемы Agile (scrum) проектов в контексте ba
решение основной проблемы Agile (scrum) проектов в контексте ba
ISsoft
 

Andere mochten auch (20)

How Joomla Works
How Joomla WorksHow Joomla Works
How Joomla Works
 
17. основы css (cascading style sheets)
17. основы css (cascading style sheets)17. основы css (cascading style sheets)
17. основы css (cascading style sheets)
 
Php Security
Php SecurityPhp Security
Php Security
 
Тестирование требований
Тестирование требованийТестирование требований
Тестирование требований
 
Таблицы Html
Таблицы HtmlТаблицы Html
Таблицы Html
 
Organisation and navigation
Organisation and navigationOrganisation and navigation
Organisation and navigation
 
Custom Post Type and Taxonomies in WordPress 3.x
Custom Post Type and Taxonomies in WordPress 3.xCustom Post Type and Taxonomies in WordPress 3.x
Custom Post Type and Taxonomies in WordPress 3.x
 
FL Blog Con 2015: How To Find The Best WordPress Plugins For You
FL Blog Con 2015: How To Find The Best WordPress Plugins For YouFL Blog Con 2015: How To Find The Best WordPress Plugins For You
FL Blog Con 2015: How To Find The Best WordPress Plugins For You
 
Joomla Request To Response
Joomla Request To ResponseJoomla Request To Response
Joomla Request To Response
 
Images and Tables in HTML
Images and Tables in HTMLImages and Tables in HTML
Images and Tables in HTML
 
WordPress as Rapid Prototyping Tool
WordPress as Rapid Prototyping ToolWordPress as Rapid Prototyping Tool
WordPress as Rapid Prototyping Tool
 
Сергей Бережной "Про шаблонизаторы вообще и BEMHTML в частности"
Сергей Бережной "Про шаблонизаторы вообще и BEMHTML в частности"Сергей Бережной "Про шаблонизаторы вообще и BEMHTML в частности"
Сергей Бережной "Про шаблонизаторы вообще и BEMHTML в частности"
 
Введение в веб-проектирование
Введение в веб-проектированиеВведение в веб-проектирование
Введение в веб-проектирование
 
Пингвины из калининграда
Пингвины из калининградаПингвины из калининграда
Пингвины из калининграда
 
Bdd and dsl как способ построения коммуникации на проекте
Bdd and dsl как способ построения коммуникации на проектеBdd and dsl как способ построения коммуникации на проекте
Bdd and dsl как способ построения коммуникации на проекте
 
Getting Started With Php Frameworks @BCP5
Getting Started With Php Frameworks @BCP5Getting Started With Php Frameworks @BCP5
Getting Started With Php Frameworks @BCP5
 
CSS Lessons Learned the Hard Way (ConvergeSE)
CSS Lessons Learned the Hard Way (ConvergeSE)CSS Lessons Learned the Hard Way (ConvergeSE)
CSS Lessons Learned the Hard Way (ConvergeSE)
 
6. таблицы и другие теги html
6. таблицы и другие теги html6. таблицы и другие теги html
6. таблицы и другие теги html
 
Верстка_Лекция1
Верстка_Лекция1Верстка_Лекция1
Верстка_Лекция1
 
решение основной проблемы Agile (scrum) проектов в контексте ba
решение основной проблемы Agile (scrum) проектов в контексте baрешение основной проблемы Agile (scrum) проектов в контексте ba
решение основной проблемы Agile (scrum) проектов в контексте ba
 

Ähnlich wie CSS Lessons Learned the Hard Way (Generate Conf)

Ähnlich wie CSS Lessons Learned the Hard Way (Generate Conf) (20)

CSS Lessons Learned the Hard Way (Beyond Tellerand)
CSS Lessons Learned the Hard Way (Beyond Tellerand)CSS Lessons Learned the Hard Way (Beyond Tellerand)
CSS Lessons Learned the Hard Way (Beyond Tellerand)
 
CSS Lessons Learned The Hard Way – Zoe Gillenwater
CSS Lessons Learned The Hard Way – Zoe GillenwaterCSS Lessons Learned The Hard Way – Zoe Gillenwater
CSS Lessons Learned The Hard Way – Zoe Gillenwater
 
Leveling Up With Flexbox (Smart Web Conference)
Leveling Up With Flexbox (Smart Web Conference)Leveling Up With Flexbox (Smart Web Conference)
Leveling Up With Flexbox (Smart Web Conference)
 
the 5 layers of web accessibility - Open Web Camp II
the 5 layers of web accessibility - Open Web Camp IIthe 5 layers of web accessibility - Open Web Camp II
the 5 layers of web accessibility - Open Web Camp II
 
Web Zurich - Make your animations perform well
Web Zurich - Make your animations perform wellWeb Zurich - Make your animations perform well
Web Zurich - Make your animations perform well
 
Techniques For A Modern Web UI (With Notes)
Techniques For A Modern Web UI (With Notes)Techniques For A Modern Web UI (With Notes)
Techniques For A Modern Web UI (With Notes)
 
Using Flexbox Today (CSS Summit 2016)
Using Flexbox Today (CSS Summit 2016)Using Flexbox Today (CSS Summit 2016)
Using Flexbox Today (CSS Summit 2016)
 
Look ma! No images!
Look ma! No images!Look ma! No images!
Look ma! No images!
 
Just One (CSS Dev Conference keynote)
Just One (CSS Dev Conference keynote)Just One (CSS Dev Conference keynote)
Just One (CSS Dev Conference keynote)
 
Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)Leveling Up with Flexbox (Smashing Conference)
Leveling Up with Flexbox (Smashing Conference)
 
Professional web development with libraries
Professional web development with librariesProfessional web development with libraries
Professional web development with libraries
 
Fewd week7 slides
Fewd week7 slidesFewd week7 slides
Fewd week7 slides
 
Introduction to Responsive Design v.2
Introduction to Responsive Design v.2Introduction to Responsive Design v.2
Introduction to Responsive Design v.2
 
Mobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web DesignMobile Monday Presentation: Responsive Web Design
Mobile Monday Presentation: Responsive Web Design
 
Real solutions, no tricks
Real solutions, no tricksReal solutions, no tricks
Real solutions, no tricks
 
Business of Front-end Web Development
Business of Front-end Web DevelopmentBusiness of Front-end Web Development
Business of Front-end Web Development
 
Responsive Web Design - Drupal Camp CPH
Responsive Web Design - Drupal Camp CPHResponsive Web Design - Drupal Camp CPH
Responsive Web Design - Drupal Camp CPH
 
Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)Putting Flexbox into Practice (Fronteers)
Putting Flexbox into Practice (Fronteers)
 
RWD in the Wild
RWD in the WildRWD in the Wild
RWD in the Wild
 
Eye candy for your iPhone
Eye candy for your iPhoneEye candy for your iPhone
Eye candy for your iPhone
 

Mehr von Zoe Gillenwater

Designing with CSS3 Effectively & Efficiently
Designing with CSS3 Effectively & EfficientlyDesigning with CSS3 Effectively & Efficiently
Designing with CSS3 Effectively & Efficiently
Zoe Gillenwater
 
Effective and Efficient Design with CSS3
Effective and Efficient Design with CSS3Effective and Efficient Design with CSS3
Effective and Efficient Design with CSS3
Zoe Gillenwater
 

Mehr von Zoe Gillenwater (20)

Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)Using Flexbox Today (Frontier Conf 2016)
Using Flexbox Today (Frontier Conf 2016)
 
Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)Using Flexbox Today (Generate Sydney 2016)
Using Flexbox Today (Generate Sydney 2016)
 
Using Flexbox Today (Frontend United 2016)
Using Flexbox Today (Frontend United 2016)Using Flexbox Today (Frontend United 2016)
Using Flexbox Today (Frontend United 2016)
 
Show vs. Tell in UX Design (Front in Amsterdam)
Show vs. Tell in UX Design (Front in Amsterdam)Show vs. Tell in UX Design (Front in Amsterdam)
Show vs. Tell in UX Design (Front in Amsterdam)
 
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)
Enhancing Responsiveness with Flexbox (CSS Conf EU 2015)
 
Responsive Flexbox Inspiration (Responsive Day Out)
Responsive Flexbox Inspiration (Responsive Day Out)Responsive Flexbox Inspiration (Responsive Day Out)
Responsive Flexbox Inspiration (Responsive Day Out)
 
Enhancing Responsiveness With Flexbox (CSS Day)
Enhancing Responsiveness With Flexbox (CSS Day)Enhancing Responsiveness With Flexbox (CSS Day)
Enhancing Responsiveness With Flexbox (CSS Day)
 
Enhancing Responsiveness With Flexbox (Smashing Conference)
Enhancing Responsiveness With Flexbox (Smashing Conference)Enhancing Responsiveness With Flexbox (Smashing Conference)
Enhancing Responsiveness With Flexbox (Smashing Conference)
 
Enhancing Responsiveness with Flexbox (RWD Summit)
Enhancing Responsiveness with Flexbox (RWD Summit)Enhancing Responsiveness with Flexbox (RWD Summit)
Enhancing Responsiveness with Flexbox (RWD Summit)
 
Putting Flexbox into Practice
Putting Flexbox into PracticePutting Flexbox into Practice
Putting Flexbox into Practice
 
CSS3 Layout
CSS3 LayoutCSS3 Layout
CSS3 Layout
 
Building Responsive Layouts
Building Responsive LayoutsBuilding Responsive Layouts
Building Responsive Layouts
 
The Future of CSS Layout
The Future of CSS LayoutThe Future of CSS Layout
The Future of CSS Layout
 
Building Responsive Layouts
Building Responsive LayoutsBuilding Responsive Layouts
Building Responsive Layouts
 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design
 
CSS3: Using media queries to improve the web site experience
CSS3: Using media queries to improve the web site experienceCSS3: Using media queries to improve the web site experience
CSS3: Using media queries to improve the web site experience
 
Web Accessibility
Web AccessibilityWeb Accessibility
Web Accessibility
 
Real-world CSS3
Real-world CSS3Real-world CSS3
Real-world CSS3
 
Designing with CSS3 Effectively & Efficiently
Designing with CSS3 Effectively & EfficientlyDesigning with CSS3 Effectively & Efficiently
Designing with CSS3 Effectively & Efficiently
 
Effective and Efficient Design with CSS3
Effective and Efficient Design with CSS3Effective and Efficient Design with CSS3
Effective and Efficient Design with CSS3
 

Kürzlich hochgeladen

Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
kumaririma588
 
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
amitlee9823
 
infant assessment fdbbdbdddinal ppt.pptx
infant assessment fdbbdbdddinal ppt.pptxinfant assessment fdbbdbdddinal ppt.pptx
infant assessment fdbbdbdddinal ppt.pptx
suhanimunjal27
 
DESIGN THINKING in architecture- Introduction
DESIGN THINKING in architecture- IntroductionDESIGN THINKING in architecture- Introduction
DESIGN THINKING in architecture- Introduction
sivagami49
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
amitlee9823
 
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard ...
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard  ...Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard  ...
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard ...
nirzagarg
 
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
nirzagarg
 
Design Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptxDesign Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptx
TusharBahuguna2
 
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
amitlee9823
 

Kürzlich hochgeladen (20)

Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
 
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...
 
infant assessment fdbbdbdddinal ppt.pptx
infant assessment fdbbdbdddinal ppt.pptxinfant assessment fdbbdbdddinal ppt.pptx
infant assessment fdbbdbdddinal ppt.pptx
 
DESIGN THINKING in architecture- Introduction
DESIGN THINKING in architecture- IntroductionDESIGN THINKING in architecture- Introduction
DESIGN THINKING in architecture- Introduction
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard ...
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard  ...Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard  ...
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard ...
 
Case Study of Hotel Taj Vivanta, Pune
Case Study of Hotel Taj Vivanta, PuneCase Study of Hotel Taj Vivanta, Pune
Case Study of Hotel Taj Vivanta, Pune
 
Top Rated Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...
Top Rated  Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...Top Rated  Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...
Top Rated Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...
 
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
Nisha Yadav Escorts Service Ernakulam ❣️ 7014168258 ❣️ High Cost Unlimited Ha...
 
Design Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptxDesign Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptx
 
Q4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentationQ4-W4-SCIENCE-5 power point presentation
Q4-W4-SCIENCE-5 power point presentation
 
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
 
Sweety Planet Packaging Design Process Book.pptx
Sweety Planet Packaging Design Process Book.pptxSweety Planet Packaging Design Process Book.pptx
Sweety Planet Packaging Design Process Book.pptx
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Gi...
 
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
 
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
 
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
 

CSS Lessons Learned the Hard Way (Generate Conf)

  • 1. CSS Lessons Learned the Hard Way Zoe Mickley Gillenwater @zomigi Generate Conference London 26 September 2014
  • 3. …some of which come out nicely…
  • 5. Books Stunning CSS3: A Project-based Guide to the Latest in CSS www.stunningcss3.com Flexible Web Design: Creating Liquid and Elastic Layouts with CSS www.flexiblewebbook.com
  • 8. …but sometimes I make mistakes…
  • 11.
  • 12. “I can’t start until I know enough to do it perfectly.”
  • 13. You don’t need everything http://www.flickr.com/photos/montage_man/4713541238/
  • 14. Start using Sass in four easy steps.
  • 15. Install Prepros from http://alphapixels.com/prepros/ Step 1
  • 16. Drag your web site’s folder into Prepros. Step 2
  • 17. In this folder, create a file named styles.scss. Step 3
  • 18. Write in it this: Step 4 $green: #4F9F1A; $blue: #1D6783; $lightgray: #D6D6D6; body { background: $lightgray; color: $green; } a { color: $blue; } button { background: $blue; color: $lightgray; }
  • 19. Never compare your inside with somebody else’s outside.
  • 20. If you walk around with the idea that there are some people who are so gifted—they have these wonderful things in their head, but you’re not one of them, you’re just sort of a normal person, you could never do anything like that— then you live a different kind of life. Brian Eno
  • 21. Innovation requires a mindset that rejects the fear of failure and replaces that fear of failure with the joy of exploration and experimental learning. Dr. Edward D. Hess
  • 22. We also need to accept and embrace the concept of failure, not because failure is a good thing but because it’s a natural part of the path of progress. If you’re failing, at least that means you’re trying — not remaining on the outside of the arena, looking in. Helen Walters
  • 23. Creative people experiment a lot more, therefore succeed a lot more, therefore fail a lot more.
  • 24. Some of my recent CSS mistakes
  • 25. Flexbox demo www.smoresday.us Use Chrome, Opera, Safari 7, Firefox 28+, or IE 10+ for full effect
  • 27. HTML without flexbox <form class="builder"> <div class="wrap"> <section class="component"> <section class="component"> <section class="component"> <section class="component"> </div> <section class="action"> </form>
  • 28. HTML for flexbox version <form class="builder"> <section class="component"> <section class="component"> <section class="component"> <section class="component"> <section class="action"> </form>
  • 29. Allow boxes to wrap .builder { display: flex; flex-wrap: wrap; justify-content: space-between; margin: 0 0 40px -20px; }
  • 30. Using flex to control width/height .flex-item { flex: 1 0 100px; } flex-grow flex-shrink flex-basis
  • 31. Defining the flex property flex-grow how much flex item will grow relative to other items if extra space is available (proportion of extra space that it gets) flex-shrink how much item will shrink relative to others if there is not enough space (proportion of overflow that gets shaved off) flex-basis the initial starting size before free space is distributed (any standard width/height value, including auto)
  • 32. My first attempt .component { flex: 1; } .action { flex: 1 1 100%; } Zoe’s Brain Said: “Since .action starts out at 100%, it won’t have space to sit on the first line with the content preceding it, and will wrap to a second line.”
  • 34. This fixed it .component { flex: 1; margin-right: 1px; }
  • 35. /* this is needed to make .action wrap to second line. why??? */ My comment on the 1px margin
  • 36. The hidden flex-basis value .component { flex: 1 1 0px; } .action { flex: 1 1 100%; } Reality: Since it’s fine for each .component to shrink to only 0px wide, a 100% wide element can and will sit on the same line as all the components.
  • 37. That’s why margin “fixed” it .component { flex: 1; margin-right: 1px; } .action { flex: 1 1 100%; } What’s happening: Now each .component starts out taking up 1px of space, so a 100% wide element can’t and won’t sit on the same line with any of the components.
  • 38. Fixing flex-basis to force the wrap .component { flex: 1 1 200px; } .action { flex: 1 1 100%; } Fixed: .action will always wrap to new line, and .component boxes will wrap to additional lines when there’s less space than their combined flex-basis values (plus margin, etc.).
  • 39. This was not just a case of succeeding despite a mistake. It was a case of succeeding because of a mistake.
  • 41. flex can be proportional Setting flex-grow/flex-shrink to different values can make flex items size themselves relative to each other flex: 1; flex: 1; flex: 2;
  • 42. Trying to make one twice as wide .gallery-item { flex: 1 0 200px; } .feature { flex: 2 0 200px; }
  • 45. What I figured out Having widths be in multiples of each other only works if flex-basis is 0 flex: 1 0 0px; flex: 1 0 0px; flex: 2 0 0px;
  • 46. If flex-basis isn’t 0px… …the widths may not end up as you expect The third box gets twice as much of the extra, but that doesn’t make it twice as wide overall flex: 1 0 10px; flex: 1 0 10px; flex: 2 0 10px; 10px + 5px extra = 15px 10px + 5px extra = 15px 10px + 10px extra = 20px if 50px available
  • 48. I really get flex-basis now
  • 49. Takeaway: don’t use CSS shorthand without understanding all the pieces
  • 50. Let’s talk about another mistake
  • 51. Shadow style inspiration http://sliderpro.net/examples/minimal-slider/
  • 52. The plan: create shadow with generated content, skew it with CSS perspective
  • 53.
  • 54.
  • 55. My first attempt .lightbox:before { content: ""; position: absolute; z-index: -2; left: 2%; bottom: 0; width: 96%; height: 1px; box-shadow: 0 25px 30px 15px hsla(0,0%,0%,.4); transform: perspective(20em); }
  • 57.
  • 58. What does rotateX actually do?
  • 59. The 3 axes X horizontal, left-right Y vertical, up-down Z away-towards you A helpful diagram: your hand. Photo: http://www.smashingmagazine.com/2012/01/06/adventures-in-the-third-dimension-css-3-d-transforms/
  • 60. Or, if your hand is effed up: http://architecture.gtu.ge/MPL/Multimodal%20Explorer/Acad_11/14control_workplane0/control_workplane.htm
  • 61. Rotate around the axis not in the direction of the axis As explained well by Peter Gasston in http://www.smashingmagazine.com/2012/01/06/adventures- in-the-third-dimension-css-3-d-transforms/
  • 63. Adding rotateX with perspective .lightbox:before { content: ""; position: absolute; z-index: -2; left: 6%; bottom: 0; width: 88%; height: 1px; box-shadow: 0 25px 30px 15px hsla(0,0%,0%,.4); transform: perspective(20em) rotateX(50deg); }
  • 65. Takeaway: sometimes pen and paper can make a new concept real to you
  • 66. A more public mistake
  • 67. Sometimes you need to add special content for screen reader users…
  • 68.
  • 69. …and occasionally you need to hide content from screen reader users.
  • 70.
  • 71. I needed CSS classes to: 1.Hide content visually and aurally 2.Hide just the text of an element, not whole element, but keep text spoken 3.Hide whole element visually but keep its text spoken by screen readers
  • 72. Hide content visually and aurally .hidden-silent { display: none; visibility: hidden; }
  • 73. Hide text only but keep it spoken .hidden-text-spoken { text-indent: -999em; overflow: hidden; display: inline-block; }
  • 74. Hide element but keep it spoken Yahoo! Accessibility blog said to use: .hidden-spoken { position: absolute !important; clip: rect(1px 1px 1px 1px); /* IE 6-7 */ clip: rect(1px, 1px, 1px, 1px); padding: 0 !important; border: 0 !important; height: 1px !important; width: 1px !important; overflow: hidden; } Article now online at https://developer.yahoo.com/blogs/ydn/clip-hidden-content-better-accessibility-53456.html
  • 75. Problem: NVDA in Firefox wouldn’t read <label> with this class
  • 76. Delete half the code, see if bug goes away, repeat
  • 77. I narrowed it down to overflow: hidden Removing this part caused labels to be read correctly in Firefox by NVDA
  • 78. But removing it still kept the content hidden. So why was it there to begin with?
  • 79.
  • 80.
  • 81.
  • 82. This scrollbar is what overflow fixes
  • 83. Now that I understood what overflow did, I could decide if I needed it.
  • 84. How I fixed my mistake •Removed overflow:hidden from new instances going forward (but sadly not fixed in existing style sheets) •Updated documentation to advise adding it on as-needed basis
  • 85. (By the way, this FF/NVDA bug seems to be gone now.)
  • 86. Takeaway: one-size-fits-all isn’t always best for your needs
  • 87. Takeaway: you can get help when you share your confusion publicly
  • 88. Be willing to fail…
  • 89. …and then tell us about it.
  • 90. Vulnerability is not weakness. And that myth is profoundly dangerous. Dr. Brené Brown
  • 91. Vulnerability is the birthplace of innovation, creativity, and change. To create is to make something that has never existed before. There's nothing more vulnerable than that. Dr. Brené Brown
  • 92. We all do imperfect work
  • 93. /* this is needed to make .action wrap to second line. why??? */
  • 94. The evidence in the comments // Dear future me. Please forgive me. // I can't even begin to express how sorry I am. // I am not sure if we need this, but too scared to delete. // Magic. Do not touch.
  • 95. Revisiting comments // TODO: Fix this. Fix what? // somedev1 - 6/7/02 Adding temporary tracking of Login screen // somedev2 - 5/22/07 Temporary my ass
  • 96.
  • 99. Hiding mistakes seems to be human nature
  • 100. But sharing mistakes has benefits
  • 101. Try to shift “Who can I blame?” to “Who can I teach?”
  • 103. 99% of the population of the world doesn’t know CSS. Zoe’s made-up statistic
  • 104. You are awesome, but and you make mistakes.
  • 105. Let’s use our confidence in our skills to build others up and bravely admit our own shortcomings.
  • 106. Thank you Zoe Mickley Gillenwater @zomigi Generate Conference London 26 September 2014