css for basic learner

34
Oriented by: Vibol YOEUNG Tell: 077 377 067 [email protected]

Upload: yoeung-vibol

Post on 06-Aug-2015

130 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: CSS for basic learner

Oriented by: Vibol YOEUNG

Tell: 077 377 067

[email protected]

Page 2: CSS for basic learner

Import style sheet•In style sheet, we can import other

style sheet by use

•@import “style.css”;

Page 3: CSS for basic learner

CSS Selectors

Tag, Class, ID, Compound

Use CSS Selectors to define properties for the structure and presentation of your site.

This is the key to defining specific properties for specific parts of your design.

Page 4: CSS for basic learner

CSS Selectors

Tag: properties defined for an HTML tag.

Class: properties defined for an HTML tag using a class or a <span> tag.

ID: properties defined for an element or div using an id.

Compound: properties defined using multiple selector types.

Page 5: CSS for basic learner

CSS Selectors

body {margin: 10px 0;}

Selector Property Value

Declaration

Page 6: CSS for basic learner

CSS Selectors

body {margin: 10px 0;}

Tag*: properties defined for an HTML tag.

(*Also referred to as Type, Element)

Page 7: CSS for basic learner

CSS Selectors

body {margin: 10px 0;}

<body>Everything within the body will start out with this property. </body>

Tag

Page 8: CSS for basic learner

CSS Selectors

.red {margin: 15px; color: red;}

Class: properties defined for an HTML tag using a class or a <span> tag.

Page 9: CSS for basic learner

CSS Selectors

.red {margin: 15px; color: red;}

<p class=”red”>This is a paragraph of text in red.</p>

These are <span class=”red”>words in red.</span>

Class

Page 10: CSS for basic learner

CSS Selectors

#wrapper {margin :0 auto;}

ID: properties defined for an element or div using an id.

Page 11: CSS for basic learner

CSS Selectors

#wrapper {margin :0 auto;}

<div id=”wrapper”></div>

ID

Page 12: CSS for basic learner

CSS Selectors

#content p {margin :0;}

Compound: properties defined using multiple selector types.

Page 13: CSS for basic learner

CSS Selectors

#content p {margin :0;}

<div id=”content”><p>This is a paragraph of text in the content div.</p></div>

Compound

Page 14: CSS for basic learner

CSS Box Model

How do you position content?

You position content in your page by using a combination of margins, padding and floats.

But, in order to get your positioning and layout correct, you must know how the CSS Box Model works.

Page 15: CSS for basic learner

CSS Box Model

content

Page 16: CSS for basic learner

CSS Box Model

40 px

10 px

100 px

450 px

content

Page 17: CSS for basic learner

CSS Box Model

10 px

1 px

50 px

??? px

500 px

content

Page 18: CSS for basic learner

CSS Box Model

total box width =

content area width + left padding + right padding + left border + right border + left margin + right margin

Page 19: CSS for basic learner

CSS Box Model

#content {width: 200px;border: 1px solid #900;padding: 10px;margin: 0;background: #fee;}

What is the total box width?

Page 20: CSS for basic learner

CSS Box Model

#content {width: ???px;border: 1px solid #000;padding: 20px;margin: 10;}

If the total box width is 400px, what is the width of the content area?

Page 21: CSS for basic learner

Pseudo-Selectors••General Purpose Pseudo-Selector:

•–:hover Element with mouse over

•Specific to hyperlinks (and/or buttons)

•–a:active A link or button that is currently being clicked on.

•–a:link A link that has NOT been visited yet.

•–a:visited A link that HAS been visited.

Page 22: CSS for basic learner

Background Image Properties

•background-image:url(../location/of/image.jpg)

••background-repeat:tile image in background

••background-position:vertical(top, center, bottom, or size) horizontal(left, center, right, or size)

••background-attachment: (scrollor fixed)

Page 23: CSS for basic learner

Text Properties•text-indent:indents first line of a

paragraph according to size

•text-align:right;or left;or center;or justify;

•text-decoration: none; orunderline;

•text-transform:Capitalize;

•Line-height:added vertical space to each line of text according to size

Page 24: CSS for basic learner

Text shadows•h3 {text-shadow: 1px 1px 2px #00}

•x (horizontal) offset casts shadow to the right of the text. Negative cast to the left.

•y (vertical) offset casts shadow below the text. Negative value casts above

•Blue radius: blurs the shadow, with higher values making the shadow wider or lighter.

•Color: make color for shadow text

Page 25: CSS for basic learner

Attribute selector- CSS [attribute]: use to select element with

specified attribute

Ex. a[target] {color: red}

- CSS [attribute=value]: use to select element with specified attribute and value

Ex. Input[type=“submit”] {color: #fff}

Page 26: CSS for basic learner

Attribute selector(con)- CSS [attribute~=value]: use to select

element with an attribute with containing a specified word

- Ex. [title~=“shop”] {color: #000}

- CSS [attribute|=value]: select elements with the specified attribute starting with the specified value.

- Ex. [class|=“top”] {background: blue}

Page 27: CSS for basic learner

Attribute selector(con)- CSS [attribute^=value]: used to select

elements whose attribute value begins with a specified value

Ex. [class^=“top”] {background: blue}

- CSS [attribute$=value]: used to select elements whose attribute value ends with a specified value.

Ex. [class$=“top”] {background: blue}

Page 28: CSS for basic learner

List Properties <ul>•list-style-type:none, disc, circle, square,

(other types available)

•list-style-position: inside oroutside

•list-style-image:url(../path/to/image.jpg)

•…or shorthand

•list-style:type position image

Page 29: CSS for basic learner

Position•Static position: is a default position and

element is always positioned according to the normal flow of the page.

Page 30: CSS for basic learner

Position fixed•An element with fixed position is

positioned relative the browser window. It will not move even if window is scrolled:

Page 31: CSS for basic learner

Position fixed(con)•Ex.

•.box {

position: fixed;

width: 400px;

height: 400px;

}

Page 32: CSS for basic learner

Position relative•element is positioned relative to its

normal position.

•Ex. Box2 {

position: relative;

left: -10px;

}

Page 33: CSS for basic learner

Position absolute•An absolute position element is positioned

relative to the first parent element that has a position other than static.

•Ex. Box2 {

position: absolute;

left: 10px;

top: 20px;

}

Page 34: CSS for basic learner

Z-index•property specifies the stack order of an

element (which element should be placed in front of, or behind, the others).

•Ex. .box2 {

z-index: 1;

Position: absolute;

}