Becoming a “master” of CSS is more than just memorizing selectors. It’s about mastering your workflow. Create efficient, maintainable, smart (sexy) CSS . An organized directory structure for all projects. Begin with meaningful markup. Keep your selectors declarations organized. Elements flow naturally on the page, in the order that they appear in the source. Moves the element by coordinates relative to where it lives within “normal flow”. emoves the element from normal flow and positions by coordinates to the nearest parent element that hasrelative positioning. By default, the element will position to the viewport if no parent exists that has relative positioning.
Trang 2J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Buongiorno!
Trang 3Mastering C S S
Layouts Once &
for All?
Trang 5It’s about mastering
your workflow.
Trang 7A Consistent
Workflow
Trang 8J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Create a development
starter toolkit.
Trang 9An organized directory structure
for all projects.
Trang 11js/
css/
i/
Trang 12J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Barebones
Trang 13A Simple, Usable,
& Clean C S S
Framework
Trang 14J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
@import 'reset.css';
@import 'foundation.css';
Trang 15Optional: Your
Chosen JavaScript
Framework
Trang 16J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Design from the
content out or from
outside in?
Trang 17Begin with
meaningful markup.
Trang 18J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Write it clean;
keep it clean.
Trang 19Clarity is beautiful.
Trang 21Organization
Trang 23Element Types DOM Hierarchy Style Types
Trang 24J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Declarations
Alphabetical Style Types
Trang 25Comments are
your friend.
Trang 26J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
/* Company Name Typography CSS
*/
Trang 29/* RESET
GLOBAL TYPOGRAPHY STRUCTURE FORMS
TABLES WIDGETS */
Trang 31Balance readability
& optimization.
Trang 32J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Debugging
Trang 33Validate your code.
W 3 C H T M L Validator
http://validator.w3.org/
C S S Validator
http://jigsaw.w3.org/css-validator/
Trang 35Documentation
Trang 37Techniques
Trang 38J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
The Box Model
Trang 39Image by Andy Clarke, adapted from the original image created by Jon Hicks
http://www.hicksdesign.co.uk/boxmodel/
Trang 40J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Normal Flow
Elements flow naturally on the page, in the order that
they appear in the source.
Trang 41Floats
Trang 42J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Floats were not
intended for layout.
Trang 43Avoid using floats as a
fallback bug fix.
Trang 44J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Positioning
Trang 45Relative Positioning
Moves the element by coordinates relative to where it
lives within “normal flow”.
Trang 46J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Absolute Positioning
Removes the element from normal flow and positions
by coordinates to the nearest parent element that has
relative positioning By default, the element will
position to the viewport if no parent exists that has
relative positioning.
Trang 47Fixed Positioning
Removes the element from normal flow and positions
by coordinates to the viewport This element does not
scroll with the rest of the page.
Trang 49Rounded Corners
Trang 51C S S + Images Techniques
Consider which of the several techniques fits best.
Do$ your d$ign have a fixed width?
Wi% that always be the c&e?
How about the height?
Could th' change & the co(e( grows shorter/longer?
Trang 53Fixed width, varied height
Trang 54J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Fixed width, varied height
(long version)
A full-width, short image for the top border.
A full-width, short repeating image for the left
and right borders.
A full-width, short image for the bottom border.
Trang 55Fixed width, varied height
Trang 56J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Varied width, varied height
A very wide, very tall image for the top and left borders.
A skinny, very tall image for the top right corner and right border.
A very wide, short image for the bottom right corner and bottom border.
A skinny, short image for the bottom left corner.
Trang 57Varied width, varied height
Trang 58J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 59A K A
“Navigation Matrix”
Trang 60J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
<ul id="menu">
<li id="m-home"><a href="#">Home</a></li>
<li id="m-about"><a href="#">About</a></li>
<li id="m-news"><a href="#">News</a></li>
<li id="m-events"><a href="#">Events</a></li>
<li id="m-links"><a href="#">Links</a></li>
<li id="m-contacts"><a href="#">Contacts</a></li>
</ul>
Trang 61ul#menu { list-style: none; }
ul#menu li { display: inline; }
Trang 62J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
ul#menu li#m-home a { background-position: 0 0; }
ul#menu li#m-about a { background-position: -100px 0; }
ul#menu li#m-news a { background-position: -200px 0; }
ul#menu li#m-events a { background-position: -300px 0; }
ul#menu li#m-links a { background-position: -400px 0; }
ul#menu li#m-contacts a { background-position: -500px 0; }
Trang 63ul#menu li#m-home a:hover { background-position: 0 -50px; }
ul#menu li#m-about a:hover { background-position: -100px -50px; }
ul#menu li#m-news a:hover { background-position: -200px -50px; }
ul#menu li#m-events a:hover { background-position: -300px -50px; }
ul#menu li#m-links a:hover { background-position: -400px -50px; }
ul#menu li#m-contacts a:hover { background-position: -500px -50px; }
Trang 64J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
ul#menu li#m-home.active a{ background-position: 0 -100px; }
ul#menu li#m-about.active a { background-position: -100px -100px; }
ul#menu li#m-news.active a { background-position: -200px -100px; }
ul#menu li#m-events.active a { background-position: -300px -100px; }
ul#menu li#m-links.active a { background-position: -400px -100px; }
ul#menu li#m-contacts.active a { background-position: -500px -100px; }
Trang 65Negative Margins
Trang 66J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 67Conditional
comments vs hacks
Trang 68J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Avoid hacks if possible.
Work With the Box Model (not against).
Browsers Change.
If hacks are absolutely necessary, it can be helpful to explain what was done in your C S S comments.
Trang 69Master your text editor.
Trang 70J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Use version control.
Trang 72J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
CSS 3
Trang 73— Alex Russell
serving of FAIL.”
“
Trang 751996
Trang 76J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
1997
Trang 77Candidate Recommendation
Trang 78J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
?
Trang 79C S S 3
Sele%ors Backgrounds & Borders Multi-column Layout
Advanced Layout Grid Positioning Media Queries
Trang 80J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Backgrounds
& Borders
Style any box’s borders and background including
attaching multiple background-images to a
single element.
Trang 83.addr-bl {
background:
url(a-bl.gif) 100% 0
no-repeat;
}
Trang 85repeat-x, no-repeat, no-repeat;
background-position:
0 0, 100% 0,
0 100%;
Trang 88J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 90J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 92J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 93<div class="vcard" >…</div>
.vcard {
border-image:
url("border.png")
30 30 30 30 stretch;
border:
double green 1em;
}
Trang 94J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Multi-column Layout
Making it simpler to create column layouts without
additional markup by using column widths, counts,
gaps and rules.
Trang 96J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 100J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 102J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Grid Positioning
Gives the ability to add invisible grid rules to create
grid layouts (like in books and newspapers), and uses
sizing and new float properties for placing content.
Trang 104J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 106J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 108J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 110J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 116J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Advanced Layout
Aims to fully separate visual layout order from a
document’s content by defining “slots” in a grid in
which content can flow or be placed, or that remain
empty — all without additional markup
Trang 119a a c d
Trang 120J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 123Refined sele%ors to target an element based on an
attribute or position in the document flow plus new
pseudo-classes and pseudo-elements.
Trang 124J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Sele%ors
:nth-child(N) :nth-of-type(N) :last-child
:last-of-type :only-of-type :empty
:nth-last-child(N) :nth-last-of-type(N) :first-of-type
:only-child :root
:target
Trang 125matches elements on the basis of their positions
within a parent element’s list of child elements (from
beginning to end)
Trang 126J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 128}
Trang 129tr:nth-child(odd) td {
background: #ecffd9;
}
Trang 130J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 133matches elements on the basis of their positions
within a parent element’s list of child elements (from
end to beginning)
Trang 134J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S
Trang 137matches elements on the basis of their positions
within a parent element’s list of child elements of the
same type
Trang 138J I N A B O LT O N
M A S T E R I N G C S S L AYO U T S