7. css layout - web front-end

33
CSS Layout Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training http://nakov.com http://html5course.telerik.com

Upload: telerik-software-academy

Post on 14-Dec-2014

912 views

Category:

Technology


4 download

DESCRIPTION

Advanced CSS topics - positioning, floating, aligning, display Telerik Software Academy: http://html5course.telerik.com The website and all video materials are in Bulgarian Table of contents: Positioning, Positioning inline elements Floating, Left and right Floating, Clearing Floating Opacity, Visibility, Display

TRANSCRIPT

Page 1: 7. CSS Layout - Web Front-End

CSS Layout

Svetlin Nakov

Telerik Software Academyacademy.telerik.com

Manager Technical Traininghttp://nakov.com

http://html5course.telerik.com

Page 2: 7. CSS Layout - Web Front-End

Table of Contents Positioning

Positioning inline elements Floating

Left and right Clearing

Opacity Visibility Display

2

Page 3: 7. CSS Layout - Web Front-End

Positioning

Page 4: 7. CSS Layout - Web Front-End

Positioning position: defines the positioning of the element in the page content flow

The value is one of: static (default)

relative – relative position according to where the element would appear with static position

absolute – position according to the innermost positioned parent element

fixed – same as absolute, but ignores page scrolling

4

Page 5: 7. CSS Layout - Web Front-End

Positioning (2) Margin VS relative positioning Fixed and absolutely positioned elements do not influence the page normal flow and usually stay on top of other elements Their position and size is ignored

when calculating the size of parent element or position of surrounding elements

Overlaid according to their z-index Inline fixed or absolutely positioned

elements can apply height like block-level elements

5

Page 6: 7. CSS Layout - Web Front-End

Positioning (3) top, left, bottom, right: specifies offset of absolute/fixed/relative positioned element as numerical values

z-index : specifies the stack level of positioned elements Understanding stacking context

6

Each positioned element creates a stacking context.Elements in different stacking contexts are overlapped according to the stacking order of their containers. For example, there is no way for #A1 and #A2 (children of #A) to be placed over #B without increasing the z-index of #A.

Page 7: 7. CSS Layout - Web Front-End

PositioningLive Demo

positioning-rules.html

Page 8: 7. CSS Layout - Web Front-End

Inline element positioning

vertical-align: sets the vertical-alignment of an inline element, according to the line height Values: baseline, sub, super, top, text-top, middle, bottom, text-bottom or numeric

Also used for content of table cells (which apply middle alignment by default)

8

Page 9: 7. CSS Layout - Web Front-End

Alignment and Z-IndexLive Demo

alignments-and-z-index-rules.html

Page 10: 7. CSS Layout - Web Front-End

Floating

Page 11: 7. CSS Layout - Web Front-End

Float float: the element “floats” to one side left: places the element on the left

and following content on the right right: places the element on the

right and following content on the left

floated elements should come before the content that will wrap around them in the code

margins of floated elements do not collapse

floated inline elements can apply height

11

Page 12: 7. CSS Layout - Web Front-End

Float (2) How floated elements are positioned

12

Page 13: 7. CSS Layout - Web Front-End

Clear clear

Sets the sides of the element where other floating elements are NOT allowed

Used to "drop" elements below floated ones or expand a container, which contains only floated children

Possible values: left, right, both Clearing floats

additional element (<div>) with a clear style 13

Page 14: 7. CSS Layout - Web Front-End

Clear (2) Clearing floats (continued)

:after { content: ""; display: block; clear: both; height: 0; }

Triggering hasLayout in IE expands a container of floated elements display: inline-block;

zoom: 1;

14

Page 15: 7. CSS Layout - Web Front-End

Floating ElementsLive Demo

float-rules.html

Page 16: 7. CSS Layout - Web Front-End

Opacity

Page 17: 7. CSS Layout - Web Front-End

Opacity opacity: specifies the opacity of the element Floating point number from 0 to 1 For old Mozilla browsers use –moz-opacity

For IE use filter:alpha(opacity=value) where value is from 0 to 100; also, "binary and script behaviors" must be enabled and hasLayout must be triggered, e.g. with zoom:1

17

Page 18: 7. CSS Layout - Web Front-End

OpacityLive Demo

opacity-rule.html

Page 19: 7. CSS Layout - Web Front-End

Visibility

Page 20: 7. CSS Layout - Web Front-End

Visibility visibility

Determines whether the element is visible

hidden: element is not rendered, but still occupies place on the page (similar to opacity:0)

visible: element is rendered normally

20

Page 21: 7. CSS Layout - Web Front-End

VisibilityLive Demo

visibility-rule.html

Page 22: 7. CSS Layout - Web Front-End

Display

Page 23: 7. CSS Layout - Web Front-End

Display display: controls the display of the element and the way it is rendered and if breaks should be placed before and after the element inline: no breaks are placed before

and after (<span> is an inline element)

block: breaks are placed before AND after the element (<div> is a block element)

23

Page 24: 7. CSS Layout - Web Front-End

Display (2) display: controls the display of the element and the way it is rendered and if breaks should be placed before and after the element none: element is hidden and its

dimensions are not used to calculate the surrounding elements rendering (differs from visibility: hidden!)

There are some more possible values, but not all browsers support them Specific displays like table-cell and table-row

24

Page 25: 7. CSS Layout - Web Front-End

DisplayLive Demo

display-rule.html

Page 26: 7. CSS Layout - Web Front-End

форум програмиране, форум уеб дизайнкурсове и уроци по програмиране, уеб дизайн – безплатно

програмиране за деца – безплатни курсове и уроцибезплатен SEO курс - оптимизация за търсачки

уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop

уроци по програмиране и уеб дизайн за ученициASP.NET MVC курс – HTML, SQL, C#, .NET, ASP.NET MVC

безплатен курс "Разработка на софтуер в cloud среда"

BG Coder - онлайн състезателна система - online judge

курсове и уроци по програмиране, книги – безплатно от Наков

безплатен курс "Качествен програмен код"

алго академия – състезателно програмиране, състезания

ASP.NET курс - уеб програмиране, бази данни, C#, .NET, ASP.NETкурсове и уроци по програмиране – Телерик академия

курс мобилни приложения с iPhone, Android, WP7, PhoneGap

free C# book, безплатна книга C#, книга Java, книга C#Дончо Минков - сайт за програмиранеНиколай Костов - блог за програмиранеC# курс, програмиране, безплатно

?

? ? ??

?? ?

?

?

?

??

?

?

? ?

Questions?

?

CSS Layout

http://academy.telerik.com

Page 27: 7. CSS Layout - Web Front-End

Homework

27

1. Create the following Web page using HTML and external CSS. Using tables, inline styles and deprecated tags is not allowed.

Page 28: 7. CSS Layout - Web Front-End

Homework (2)

28

2. Create the following Web page using external CSS styles. Buttons should consist of PNG images with text over them.

Page 29: 7. CSS Layout - Web Front-End

Homework (3)

29

3. Create the following Web page using HTML with external CSS file. Note that the images should be PNG with transparent background.

Page 30: 7. CSS Layout - Web Front-End

Homework (4)

4. Given the picture below create the Web site

Use CSS and HTML 5

30

Page 31: 7. CSS Layout - Web Front-End

Homework (5)5. Create the following HTML 5 Page

Do it without tables

31

Page 32: 7. CSS Layout - Web Front-End

Homework (6) Create the following mini-web site

You can use different pictures and text

32

Page 33: 7. CSS Layout - Web Front-End

Free Trainings @ Telerik Academy

"Web Design with HTML 5, CSS 3 and JavaScript" course @ Telerik Academy html5course.telerik.com

Telerik Software Academy academy.telerik.com

Telerik Academy @ Facebook facebook.com/TelerikAcademy

Telerik Software Academy Forums forums.academy.telerik.com