Laying out Elements with CSS

Slides:



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

Working with Web Tables
15 LAYOUT Controlling the position of elements Creating site layouts Designing for different sized screens.
1 Cascading Style Sheets Continued Different kinds of selectors in a style sheet –Simple- Pseudo-Class –Contextual- Pseudo-Element –Class Image Styles.
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.
Week 9 Using the Box Properties. 9-2 The CSS Visual Formatting Model Describes how the element content boxes should be displayed by the browser –Based.
Tutorial 6 Creating Fixed-Width Layouts
TUTORIAL 4: CREATING PAGE LAYOUT WITH CSS Session 4.3.
MORE Cascading Style Sheets (The Positioning Model)
Using HTML to Create Tables in Web pages Connie Lindsey November 2005.
XHTML1 Tables N100 Creating a Simple Web Page. XHTML2 Creating Basic Tables Tables are collections of rows and columns that you use to organize and display.
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.
Web Development & Design Foundations with XHTML Chapter 6 Key Concepts.
Working with Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of a document.
Tutorial 5 Working with Web Tables. XP Objectives Explore the structure of a Web table Create headings and cells in a table Create cells that span multiple.
Tutorial 5 Working with Tables and Columns
Tutorial 5 Working with Tables and Columns
Tutorial 5 Working with Web Tables. XP Objectives Explore the structure of a Web table Create headings and cells in a table Create cells that span multiple.
Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.
CSS Fun damentals The Document Hierarchy Element Relationships The Box Model.
CSS Positioning & Layout Creating layouts and controlling elements.
CONTROLLING Page layout
Tutorial 4 Creating Page Layouts with CSS
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring 2016 CSS Positioning 1.
Understanding CSS Cascading Style Sheets control the presentation of content in HTML pages Style Sheets separate formatting from the content –Styles defined.
Tutorial 5 Working with Web Tables. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Learn and Apply the structure of.
CHAPTER 15 Floating and Positioning. FLOAT VS. POSITION  Floating an element moves it to the left or right, allowing the following text to wrap around.
Cascading Style Sheets Layout
CSS Box Model.
Getting Started with CSS
CSS Box Model.
The Box Model in CSS Web Design – Sec 4-8
Cascading Style Sheets Boxes
Formatting Text with CSS
Implementing Responsive Design
The Box Model in CSS Web Design – Sec 4-8
CSS Layouts: Grouping Elements
Webpage layout using CSS
Cao Yuewen SEEM4570 Tutorial 03: CSS Cao Yuewen
Positioning Objects with CSS and Tables
Floating & Positioning
Tutorial 5 Working with Tables and Columns
The Box Model in CSS Web Design – Sec 4-8
The Internet 10/25/11 XHTML Tables
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Objectives Create a reset style sheet Explore page layout designs
Web Development & Design Foundations with HTML5 7th Edition
6 Layout.
Creating Layouts Using CSS
Controlling Layout with Style Sheets
CSS Borders and Margins.
MORE Cascading Style Sheets (The Positioning Model)
Box model, spacing, borders, backgrounds
CSS Box Model.
Web Development & Design Foundations with H T M L 5
Web Development & Design Foundations with H T M L 5
Cascading Style Sheets™ (CSS)
More CSS Page layout Boriana Koleva Room: C54
SEEM4570 Tutorial 3: CSS + CSS3.0
How to use the CSS box model for spacing, borders, and backgrounds
Floating and Positioning
CSS Box Model.
Laying out Elements with CSS
CSS Boxes CS 1150 Fall 2016.
Positioning Objects with CSS and Tables
CSc 337 Lecture 5: Grid layout.
Positioning Boxes Using CSS
CGS 3066: Web Programming and Design Fall 2019 CSS Part 2
Presentation transcript:

Laying out Elements with CSS

Objectives Assess the CSS box model Set element width and borders Set margins and padding Align elements with float Control page flow with clear HTML5 and CSS3 – Illustrated, 2nd Edition

Objectives (continued) Implement fixed positioning Implement relative positioning Control stacking order Implement absolute positioning HTML5 and CSS3 – Illustrated, 2nd Edition

Assess the CSS Box Model Box model: used by CSS to represent characteristics of every web page element Treats element as rectangular box border: border surrounding element margin: space from border to neighboring/parent element padding: space between border and element content HTML5 and CSS3 – Illustrated, 2nd Edition

Assess the CSS Box Model (continued) HTML5 and CSS3 – Illustrated, 2nd Edition

Assess the CSS Box Model (continued) Box model properties HTML5 and CSS3 – Illustrated, 2nd Edition

Assess the CSS Box Model (continued) CSS units of measure Relative units: ems, percent, rems Absolute units: pixels Commonly used CSS units of measure HTML5 and CSS3 – Illustrated, 2nd Edition

Assess the CSS Box Model (continued) Size of padding, margin, and border increase the amount of space occupied by an element Dimensions of these properties not included in specified width / height Specified width and height refer only to the content of an element To calculate add the total space, add the width value to the padding, margin, and border values HTML5 and CSS3 – Illustrated, 2nd Edition

Assess the CSS Box Model (continued) Calculating web page space occupied by an element HTML5 and CSS3 – Illustrated, 2nd Edition

Assess the CSS Box Model (continued) Collapse: When bottom margin of one element is adjacent to top margin of another, the margins combine to the size of the larger of the two Affects element size planning Separate property for each side of padding and margin, e.g. padding-top: 2px; margin-right: 1em; HTML5 and CSS3 – Illustrated, 2nd Edition

Set Element Width and Borders Margin, padding, and border are shorthand properties Assign values to multiple CSS properties Assign values to all four sides of an element Assign these values using a single declaration Can set width, style, or color of any or all sides of an element HTML5 and CSS3 – Illustrated, 2nd Edition

Set Element Width and Borders (continued) Specific properties for the box model Reset rule: resets one or more common properties to a common baseline, e.g. border: 0 HTML5 and CSS3 – Illustrated, 2nd Edition

Set Element Width and Borders (continued) Code with width and border declarations HTML5 and CSS3 – Illustrated, 2nd Edition

Set Element Width and Borders (continued) width and border declarations rendered in a browser and developer tools opened to show box model HTML5 and CSS3 – Illustrated, 2nd Edition

Set Margins and Padding Use the shorthand property to assign multiple values Separate each value with a space Meaning of different number of values Assign auto to left and right margins to center the element horizontally HTML5 and CSS3 – Illustrated, 2nd Edition

Set Margins and Padding (continued) Example of padding using three values and margin using two values Example of margin set to auto HTML5 and CSS3 – Illustrated, 2nd Edition

Align Elements with float Page flow: the order of elements in the HTML document User agents render HTML top to bottom Easy to create layouts with elements stacked vertically Use float, clear, and width properties to create columns of text and graphics parallel to each other Use width property to assign width to each of the columns HTML5 and CSS3 – Illustrated, 2nd Edition

Align Elements with float (continued) Example of float applied to element Use float to create multicolumn layouts HTML5 and CSS3 – Illustrated, 2nd Edition

Align Elements with float (continued) Code with float and result in browser HTML5 and CSS3 – Illustrated, 2nd Edition

Control Page Flow with clear float gives basic control over layout clear gives more precise control Prevents floated elements from being displayed to the left, right, or on the side of another element clear property values HTML5 and CSS3 – Illustrated, 2nd Edition

Control Page Flow with clear (continued) Example of clear property HTML5 and CSS3 – Illustrated, 2nd Edition

Control Page Flow with clear (continued) Code including clear property and how it is rendered in a browser HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Fixed Positioning fixed positioning keeps an element in the same location, even when the page is scrolled Use the position property with the value of fixed Then specify Horizontal position using left or right Vertical positing using top or bottom HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Fixed Positioning (continued) Commonly used position properties Properties and values for fixed positioning HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Fixed Positioning (continued) Example showing fixed positioning HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Fixed Positioning (continued) Code including fixed value and how it is rendered in a browser HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Relative Positioning Relative positioning: adjusting default position of an element Preserves space allotted to element in default page flow Set position property to relative Style exact location using the properties left and right for horizontal positioning top and bottom for vertical positioning HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Relative Positioning (continued) CSS properties and values for relative positioning HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Relative Positioning (continued) Implementing relative positioning and page flow HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Relative Positioning (continued) Code using relative positioning and how it is rendered in a browser HTML5 and CSS3 – Illustrated, 2nd Edition

Control stacking order Stacking elements: positioning elements so that they can overlap Additional possibilities for layouts Applies only to positioned element Elements placed in new layer Requires careful planning Stacking order controlled by values assigned to z-index property HTML5 and CSS3 – Illustrated, 2nd Edition

Control Stacking Order (continued) Stacking positioned elements HTML5 and CSS3 – Illustrated, 2nd Edition

Control Stacking Order (continued) Code to stack and how it is rendered in a browser HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Absolute Positioning Absolute positioning: takes element out of page flow entirely Allows other elements to flow into space element would have occupied Set position property to absolute Style exact location using left, right, top, and bottom properties Location is calculated relative to closest ancestor element that has position applied to it HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Absolute Positioning (continued) Absolute positioning and page flow Properties and values HTML5 and CSS3 – Illustrated, 2nd Edition

Implement Absolute Positioning (continued) Code to absolutely position an element and the result in a browser HTML5 and CSS3 – Illustrated, 2nd Edition

Summary Box model: used by CSS to represent characteristics of elements Treats element as rectangular box Defines border, margin and padding Margins of adjacent elements can collapse into one margin Specify border width, style, and/or color of any or all sides HTML5 and CSS3 – Illustrated, 2nd Edition

Summary (continued) Use multiple values to assign margin and padding values to different sides Use float to change the default page flow Use clear to create a more precise layout Use float, clear and width to create multicolumn layouts HTML5 and CSS3 – Illustrated, 2nd Edition

Summary (continued) Fixed positioning: keeps an element in the same position, even when the page is scrolled Relative positioning: adjusting location of element relative to its page flow location using position property Space preserved HTML5 and CSS3 – Illustrated, 2nd Edition

Summary (continued) Use z-index to create a stacking order for elements Stacked elements are placed in new layers Absolute positioning: takes elements out of page flow entirely Other elements reflow into empty space HTML5 and CSS3 – Illustrated, 2nd Edition