CSS Layout Arrangement and Positioning of the HTML Elements SoftUni Team Technical Trainers Software University

Slides:



Advertisements
Similar presentations
LIS650 lecture 4 Thomas Krichel today Advice CSS Properties –Box properties-- List properties –Table properties-- Classification properties.
Advertisements

LIS650 lecture 4 Thomas Krichel today CSS Properties –Box properties-- List properties –Table properties-- Classification properties –(Audio.
CSS Layout Crash Course An Advance CSS Tutorial. Inline vs. Block Many HTML elements have a default display setting of Block. Block elements take up the.
CIS 1310 – HTML & CSS 6 Layout. CIS 1310 – HTML & CSS Learning Outcomes  Describe & Apply the CSS Box Model  Configure Float with CSS  Designate Positioning.
Floating Elements CS380.
Tutorial 6 Creating Fixed-Width Layouts
CSS, cont. October 12, Unit 4. Creating a Sidebar We know how to create a sidebar –Use the float property div#sidebar{ float: left; } Item1 Item2 Item3.
An Introduction to Cascading Style Sheets CSS Layout, and the CSS Box Model Nick Foxall SM5312 week 9: CSS Layout.
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
MORE Cascading Style Sheets (The Positioning Model)
LEARN THE QUICK AND EASY WAY! VISUAL QUICKSTART GUIDE HTML and CSS 8th Edition Chapter 11: Layout with Styles.
CSS to Know And this is just the beginning. What to What?  Tags = regular HTML  Ids = #id, only one hashtag per page  Class =.class, many as you want.
CSS (Cascading Style Sheets): How the web is styled Create Rules that specify how the content of an HTML Element should appear. CSS controls how your web.
Svetlin Nakov Telerik Web Design Course html5course.telerik.com Manager Technical Training
1 The Structure of a Web Table beginning of the table structure first row of three in the table end of the table structure table cells You do not need.
Slide 1 of 83 Table Borders To specify table borders in CSS, use the border property. The example below specifies a black border for table, th, and td.
Web Development & Design Foundations with XHTML Chapter 6 Key Concepts.
The Missing Manual MARGINS, PADDING, & BORDERS—CHAPTER 7.
1 Cascading Style Sheets (CSS) Part 2. 2 The Sources of Style Sheets.
Copyright © Terry Felke-Morris CSS Flow & Positioning 1 Copyright © Terry Felke-Morris.
 Website development process  CSS  Javascript.
CSS = Cascading Style Sheet CSS consists of rules to display, style and decorate HTML elements Why CSS ? – Separate decoration from HTML markup (Ex :,,…)
Doncho Minkov Telerik Web Design Course html5course.telerik.com Technical Trainer
Floating Elements CS The CSS float property (reference) 2 img.headericon { float: right; width: 130px; } CSS  removed from normal document flow;
COMP 135 Web Site Design Intermediate
CSS WORKSHOP Design Principles for Web Standards.
CSS Layout Arrangement and Positioning of the HTML Elements Svetlin Nakov Technical Trainer Software University
Svetlin Nakov Telerik Corporation
SASS & LESS Syntactically Awesome StyleSheets Dynamic StyleSheet Language Svetlin Nakov Technical Trainer Software University
THE BOX MODEL Putting layouts together with CSS. The Box Model  How would you describe a box?  Container?  Tags or elements are “containers”  puts.
Cascading Style Sheets Positioning Controls Visibility.
Jekyll Static Site Generator Template-Based Site Generation Svetlin Nakov Technical Trainer Software University
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Web Development Tools Tools for Front-End Developers Writing HTML and CSS Code SoftUni Team Technical Trainers Software University
3.2 Cascading Style Sheets. 2 Positioning Elements Normally, elements are laid out on the page in the order that they are defined in the XHTML document.
Web Fundamentals (HTML and CSS)
Responsive Design Design that Adapts to Different Devices SoftUni Team Technical Trainers Software University
Cascading Style Sheets Positioning Controls Visibility.
Cascading Style Sheets (CSS) Part II IT210: Web-based IT.
Tables, Rows, Columns, Cells, Header, Footer, Colspan, Rowspan
CSS Transitions and Animations Animated HTML Elements SoftUni Team Technical Trainers Software University
CSS Positioning & Layout Creating layouts and controlling elements.
CONTROLLING Page layout
Tutorial 4 Creating Page Layouts with CSS
CSS - Quiz #3 Lecture Code:
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring 2016 CSS Positioning 1.
Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
HTML and Dreamweaver November 11th. Agenda Box Model Displaying and positioning elements – Padding – Margin – Float – Display – Position HTML Demo.
CS 120: Introduction to Web Programming Lecture 10: Extra Features and Website Design Part 1 Tarik Booker CS 120 California State University, Los Angeles.
Doctrine The PHP ORM SoftUni Team Technical Trainers Software University
Agenda The User Interface The CSS Box Model The Flexbox Box Model Grid Layouts.
Laying out Elements with CSS
Cascading Style Sheets Layout
Cascading Style Sheets Boxes
CSS Layouts: Grouping Elements
Cascading Style Sheets
Floating & Positioning
CSS Transitions and Animations
Objectives Create a media query Work with the browser viewport
The Internet 10/25/11 XHTML Tables
Objectives Create a reset style sheet Explore page layout designs
MORE Cascading Style Sheets (The Positioning Model)
Cascading Style Sheets
Floating and Positioning
Laying out Elements with CSS
CSS Boxes CS 1150 Fall 2016.
CSS Layout: Flexbox.
CSc 337 Lecture 5: Grid layout.
Positioning Boxes Using CSS
CGS 3066: Web Programming and Design Fall 2019 CSS Part 2
Presentation transcript:

CSS Layout Arrangement and Positioning of the HTML Elements SoftUni Team Technical Trainers Software University

Table of Contents  Width and Height  Margins and Paddings  Overflow (Scroll, Hidden)  Display (Block, Inline-Block, …)  Visibility (Visible, Hidden)  The Box Model  Positioning (Absolute, Relative, Static)  Floating Elements and Float Clearing 2

Width and Height

Width  width – defines a value for the width of element, e.g. 200px  width applies only for block elements  Their with is 100% by default (the width of their parent)  The width of inline elements is the width of their content  min-width – defines the minimal width  min-width overrides width if ( width < min-width )  max-width – defines the maximal width  max-width overrides width if ( width > max-width ) 4

5  The values of the width / height properties are numerical:  Pixels ( px )  Centimeters ( cm )  Or percentages (%)  A percent of the available width (of the parent container)  Set the max-width to 100% to scale-down images (for tablets) Width Values img { max-width: 100%; }

Width Live Demo 6

7  height – defines the height of element, e.g. 100px  height applies only on block elements  The height of inline elements is the height of their content  min-height – defines the minimal height  min-height overrides height  max-height – defines the maximal height  max-height overrides height Height

8 Live Demo

Margins and Paddings

Margin and Padding  margin and padding define the spacing around the element  margin is the spacing outside of the border  padding is the spacing between the border and the content  Numerical value, e.g. 10px or -5px  Can be defined for each of the four sides separately:  margin-top, padding-left, …  Sometimes vertical margins of adjacent elements may collapse  E.g. adjacent paragraphs / parent-child elements / empty blocks 10

11  margin: 5px;  Sets all four sides to have margin of 5 px;  margin: 10px 20px;  top and bottom to 10px, left and right to 20px ;  margin: 5px 3px 8px;  top 5px, left/right 3px, bottom 8px  margin: 1px 3px 5px 7px;  top, right, bottom, left (clockwise from top)  Same for padding Margin and Padding: Short Rules

12 Margin and Padding Live Demo

Overflow 13

 Defines the behavior of element when content needs more space than the available  overflow values:  visible (default) – content spills out of the element  auto – show scrollbars if needed  scroll – always show scrollbars  hidden – any content that cannot fit is clipped Overflow 14

Overflow Live Demo

Display

 Controls the display of the element  Defines the way it is rendered and if breaks should be placed before and after the element  inline : no breaks are placed before and after  Like typical is element  The element's height and width depend on the size of the content  block : breaks are placed before AND after the element  Like typical is a block element  Height and width may not depend on the size of the content 17

Display  inline-block  No breaks are placed before and after (like inline)  Height and width can be applied (like in block elements)  table, table-row, table-cell  The elements are arranged in a table-like layout  none  The element is hidden and its dimensions are not used to calculate the surrounding elements rendering  Differs from visibility: hidden 18

Display 19 Live Demo

Flexbox The Magic of display:flex

 Flexbox (Flexible layout) - efficient way to lay out, align and distribute space among items in a container  Gives the container ability to alter its items' width/height/order to best fill the available space  main axis - primary axis along which flex items are laid out  Horizontal or vertical - depends on flex-direction property  main size - flex items' width or height, whichever is in the main dimension  main-start / main-end - flex items are placed within the container starting from main-start and going to main-end Flexbox Basics

22  cross axis - perpendicular to the main axis  cross size - the width or height of a flex item, whichever is in the cross dimension  cross-start / cross-end - Flex lines are filled with items and placed into the container starting on the cross-start side of the flex container and going toward the cross-end side. Flexbox Basics (2)

23  display: flex - defines a flex container  flex-direction - primarily laying out either in horizontal rows or vertical columns  row : left to right ( ltr ) right to left ( rtl )  row-reverse : right to left ( ltr ) left to right ( rtl )  column : same as row, but top to bottom  column-reverse : same as row-reverse but bottom to top  flex-wrap - wrap as needed with this property  Nowrap : single-line / left to right ( ltr ) right to left ( rtl )  Wrap : multi-line / left to right ( ltr ) right to left ( rtl )  Wrap-reverse : multi-line / right to left ( ltr ) left to right ( rtl )  flex-flow - shorthand for ( flex-direction ) & ( flex-wrap ) properties Flex - container properties

24  justify-content – alignment along the main axis  align-content – alignment along the cross axis  justify-content and align-content property values  flex-start : lines packed to the start of the container  flex-end : lines packed to the end of the container  center : lines packed to the center of the container  space-between : first-to the start & last-to the end of the section  space-around : equal space between them  align-items – how flex items are laid along the cross axis on the current line  flex-start | flex-end | center | baseline | stretch Flex - container properties (2)

25  order - order in which flex items appear in the flex container  // default 0  flex-grow - defines the ability of a flex item to grow if necessary  // default 0  flex-shrink - defines the ability of a flex item to shrink if necessary  // default 1  flex-basis - defines the default size of an element before the remaining space is distributed  // default auto  flex – shorthand for (flex-grow) & (flex-shrink) & (flex-basis)  align-self – default alignment to be overridden for individual flex item Flex – item properties default alignment (or the one specified by align-items ) to be overridden for individual flex items.

Flexbox Live Demo

Visibility

28  Determines whether the element is visible  Visibility values:  visible  The element is rendered normally  hidden  The element is not rendered, but still occupies place on the page (similar to opacity:0)  collapse  hides rows or columns of a table Visibility

Live Demo

30 The Box Model

31  When using quirks mode (pages with no DOCTYPE or with a HTML 4 Transitional DOCTYPE)  Internet Explorer violates the box model! IE Quirks Mode

The Box Model

33 CSS3 Box-Sizing  Determine whether you want an element to render it's borders and padding within its specified width, or outside of it.  Possible values:  box-sizing: content-box (default) box width: 288 pixels + 10 pixels padding and 1 pixel border on each side = 300 pixels  box-sizing: border-box box width: 300 pixels, including padding and borders

CSS3 Box-Sizing (Example)  Example: Box with a total width of 300px (including paddings and borders) width: 300px; border: 1px solid black; padding: 5px; /* Firefox */ -moz-box-sizing: border-box; /* WebKit */ -webkit-box-sizing: border-box; /* Opera 9.5+, Google Chrome */ box-sizing: border-box;

Box Model Live Demo

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 37

Positioning  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 38

Positioning  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 39 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.

Positioning Live Demo

41  What it actually does?  vertical-align only applies to inline or inline-block elements  Affects the alignment of the element itself, not its contents  For table cells, the alignment affects the cell contents, not the cell  Sets the vertical-alignment of an inline element, according to the line height  What it does NOT do?  All the elements inside the vertically aligned element change their vertical position  Values: baseline, sub, super, top, text-top, middle, bottom, text-bottom or numeric  Vertical Align

Alignment and Z-Index Live Demo

43 Floating

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 44

How Floated Elements are Positioned ?

46  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  Clear using pseudo-class :after  Additional element ( ) with a clear style  Deprecated – semantically unused Clear

 Clearing floats (continued)  :after { content: ""; display: block; clear: both; height: 0; }  Triggering hasLayout in IE expands a container of floated elements  zoom: 1 47.clearfix { zoom:1;}.clearfix:after { content: ""; display: block; clear: both; height: 0; }

Floating Elements Live Demo

49  Width and Height - max/min width and height in numerical values  Margin and Padding  Overflow - visible, auto, scroll, hidden  Display - block, inline, inline-block, table, none  Flexbox – layout module  Visibility - visible, hidden  Box model – content-box, border-box  Positioning – absolute, relative, fixed  Float - left, right, clear  Z-Index Summary

? ? ? ? ? ? ? ? ? CSS Layout

License  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" licenseCreative Commons Attribution- NonCommercial-ShareAlike 4.0 International 51  Attribution: this work may contain portions from  "HTML Basics" course by Telerik Academy under CC-BY-NC-SA licenseHTML BasicsCC-BY-NC-SA  "CSS Styling" course by Telerik Academy under CC-BY-NC-SA licenseCSS StylingCC-BY-NC-SA

SoftUni Diamond Partners

Free Software University  Software University Foundation – softuni.orgsoftuni.org  Software University – High-Quality Education, Profession and Job for Software Developers  softuni.bg softuni.bg  Software Facebook  facebook.com/SoftwareUniversity facebook.com/SoftwareUniversity  Software YouTube  youtube.com/SoftwareUniversity youtube.com/SoftwareUniversity  Software University Forums – forum.softuni.bgforum.softuni.bg