1. Trang chủ
  2. » Công Nghệ Thông Tin

Mastering CSS Layouts: UI CSS Masterclass short guide

142 115 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Mastering CSS Layouts
Tác giả Jina Bolton
Chuyên ngành Interaction Design
Thể loại essay
Năm xuất bản 2009
Định dạng
Số trang 142
Dung lượng 8,59 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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 2

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

Buongiorno!

Trang 3

Mastering C S S

Layouts Once &

for All?

Trang 5

It’s about mastering

your workflow.

Trang 7

A Consistent

Workflow

Trang 8

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

Create a development

starter toolkit.

Trang 9

An organized directory structure

for all projects.

Trang 11

js/

css/

i/

Trang 12

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

Barebones

Trang 13

A Simple, Usable,

& Clean C S S

Framework

Trang 14

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

@import 'reset.css';

@import 'foundation.css';

Trang 15

Optional: Your

Chosen JavaScript

Framework

Trang 16

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

Design from the

content out or from

outside in?

Trang 17

Begin with

meaningful markup.

Trang 18

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

Write it clean;

keep it clean.

Trang 19

Clarity is beautiful.

Trang 21

Organization

Trang 23

Element Types DOM Hierarchy Style Types

Trang 24

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

Declarations

Alphabetical Style Types

Trang 25

Comments are

your friend.

Trang 26

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

/* Company Name Typography CSS

*/

Trang 29

/* RESET

GLOBAL TYPOGRAPHY STRUCTURE FORMS

TABLES WIDGETS */

Trang 31

Balance readability

& optimization.

Trang 32

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

Debugging

Trang 33

Validate 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 35

Documentation

Trang 37

Techniques

Trang 38

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

The Box Model

Trang 39

Image by Andy Clarke, adapted from the original image created by Jon Hicks

http://www.hicksdesign.co.uk/boxmodel/

Trang 40

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

Normal Flow

Elements flow naturally on the page, in the order that

they appear in the source.

Trang 41

Floats

Trang 42

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

Floats were not

intended for layout.

Trang 43

Avoid using floats as a

fallback bug fix.

Trang 44

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

Positioning

Trang 45

Relative Positioning

Moves the element by coordinates relative to where it

lives within “normal flow”.

Trang 46

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

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 47

Fixed 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 49

Rounded Corners

Trang 51

C 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 53

Fixed width, varied height

Trang 54

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

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 55

Fixed width, varied height

Trang 56

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

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 57

Varied width, varied height

Trang 58

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 59

A K A

“Navigation Matrix”

Trang 60

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

<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 61

ul#menu { list-style: none; }

ul#menu li { display: inline; }

Trang 62

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

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 63

ul#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 64

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

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 65

Negative Margins

Trang 66

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 67

Conditional

comments vs hacks

Trang 68

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

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 69

Master your text editor.

Trang 70

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

Use version control.

Trang 72

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

CSS 3

Trang 73

— Alex Russell

serving of FAIL.”

Trang 75

1996

Trang 76

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

1997

Trang 77

Candidate Recommendation

Trang 78

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 79

C S S 3

Sele%ors Backgrounds & Borders Multi-column Layout

Advanced Layout Grid Positioning Media Queries

Trang 80

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

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 85

repeat-x, no-repeat, no-repeat;

background-position:

0 0, 100% 0,

0 100%;

Trang 88

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 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 90

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 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 92

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 93

<div class="vcard" >…</div>

.vcard {

border-image:

url("border.png")

30 30 30 30 stretch;

border:

double green 1em;

}

Trang 94

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

Multi-column Layout

Making it simpler to create column layouts without

additional markup by using column widths, counts,

gaps and rules.

Trang 96

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 100

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 102

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

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 104

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 106

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 108

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 110

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 116

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

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 119

a a c d

Trang 120

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 123

Refined sele%ors to target an element based on an

attribute or position in the document flow plus new

pseudo-classes and pseudo-elements.

Trang 124

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

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 125

matches elements on the basis of their positions

within a parent element’s list of child elements (from

beginning to end)

Trang 126

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 128

}

Trang 129

tr:nth-child(odd) td {

background: #ecffd9;

}

Trang 130

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 133

matches elements on the basis of their positions

within a parent element’s list of child elements (from

end to beginning)

Trang 134

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 137

matches elements on the basis of their positions

within a parent element’s list of child elements of the

same type

Trang 138

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

Ngày đăng: 11/07/2014, 14:21