Floating & Positioning

Slides:



Advertisements
Similar presentations
Week 10 Creating Positioned Layouts
Advertisements

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.
Chapter 7 Page Layout Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
Part 5 Introduction to CSS. CSS Display - Block and Inline Elements A block element is an element that takes up the full width available, and has a line.
With CSS, a color is most often specified by: a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red“ Example h1.
Tutorial 4: Creating page layout with css
Tutorial 6 Creating Fixed-Width Layouts
TUTORIAL 4: CREATING PAGE LAYOUT WITH CSS Session 4.3.
Using CSS for Page Layout. Types of HTML Elements Block-Level Element –Creates blocks of content e.g. div, h1..h6, p, ul, ol, li, table, form –They start.
An Introduction to Cascading Style Sheets CSS Layout, and the CSS Box Model Nick Foxall SM5312 week 9: CSS Layout.
MORE Cascading Style Sheets (The Positioning Model)
Web Development & Design Foundations with XHTML Chapter 6 Key Concepts.
Cascading Style Sheets CSS. CSS Positioning Normal Flow Top -> bottom | left -> right Arranged in the order they appear in the code make room for one.
Cascading Style Sheets CSS. div … Used like a container to group content Gives context to the elements in the grouping Give it a descriptive name with.
Cascading Style Sheets. Defines the presentation of one or more web pages Similar to a template Can control the appearance of an entire web site giving.
Copyright © Terry Felke-Morris CSS Flow & Positioning 1 Copyright © Terry Felke-Morris.
Week 8 – Part 2 Page Layout Basics Key Concepts 1.
THE BOX MODEL Putting layouts together with CSS. The Box Model  How would you describe a box?  Container?  Tags or elements are “containers”  puts.
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.
Cascading Style Sheets Positioning Controls Visibility.
INTRODUCTORY Tutorial 5 Using CSS for Layout and Printing.
CSS Layout Cascading Style Sheets. Lesson Overview  In this lesson, you will learn:  float & clear  display & visibility.
Web Foundations MONDAY, OCTOBER 7, 2013 LECTURE 7: CSS LINK COLORS, INTERMEDIATE CSS.
Cascading Style Sheets Positioning Controls Visibility.
Cascading Style Sheets (CSS) Part II IT210: Web-based IT.
CSS Positioning & Layout Creating layouts and controlling elements.
CONTROLLING Page layout
Tutorial 4 Creating Page Layouts with CSS
Chapter 4 and 5. Objectives Introduce markup: elements and attributes How browsers interpret HTML documents Basic structure of HTML document What do style.
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.
CSCI N241: Fundamentals of Web Design Copyright ©2006  Department of Computer & Information Science Using CSS for Absolute Layouts.
Mimi Opkins.  One of the major benefits of using CSS is that you’re not forced to lay your sites out in tables.  The layout possibilities of CSS give.
Cascading Style Sheets for layout
Laying out Elements with CSS
Working with Cascading Style Sheets
Cascading Style Sheets Layout
CSS Layouts: Positioning and Navbars
CSS Layouts: Grouping Elements
Webpage layout using CSS
Cascading Style Sheets
Advanced CSS BIS1523 – Lecture 20.
Cascading Style Sheets for layout
Putting Things Where We Want Them
CS3220 Web and Internet Programming Page Layout with CSS
CS3220 Web and Internet Programming Page Layout with CSS
Chapter 7 Page Layout Basics Key Concepts
The Internet 10/25/11 XHTML Tables
Basics of Web Design Chapter 7 Page Layout Basics Key Concepts
Styles and the Box Model
Controlling Layout with Style Sheets
Second CSS Lecture Applications to XML
Positioning.
MORE Cascading Style Sheets (The Positioning Model)
HTML – Organizing Page Content
HTML – Organizing Page Content
Cascading Style Sheets
More CSS 22-Feb-19.
Floating and Positioning
Tutorial 4 Creating Special Effects with CSS
CS3220 Web and Internet Programming Page Layout with CSS
Positioning.
Positioning.
Laying out Elements with CSS
The Internet 10/20/11 CSS Layout
The div Element and CSS for layout
Cascading Style Sheets™ (CSS)
Positioning Boxes Using CSS
Presentation transcript:

Floating & Positioning ART340

Floating and Positioning CSS Methods for breaking out of the normal flow and arranging elements on a page. Floating moves an element to the left or right, and the following elements wrap around it. Positioning is a way to specify the exact location of an element on page. From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins

Normal Flow Text elements appear on page in the same order as your markup. Block elements (p, div, h1) fill up the entire width of either the browser window, or containing element. Inline elements (img, strong, em, span) line up next to one another to fill up the block elements. Example: http://htmlandcssbook.com/code-samples/chapter-15/normal-flow.html From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins Block Inline

Block-Level Inline Inline Block-Level The normal flow (above) can be changed or organized in different ways using floating and positioning.

Floating Moves an element to the far left or right of the element that contains it. Elements after the floated element wrap around it. Used to create multicolumn layouts, navigations from list items, and floated images. Example 1:http://htmlandcssbook.com/code-samples/chapter-15/float.html Example 2:http://htmlandcssbook.com/code-samples/chapter-15/using-float.html From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins

Points to Remember Always provide a width for floated elements. Elements do not float higher in the markup than where you wrote them. From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins

Floating Multiple Elements float: left; float: left; float: left; Elements floated to the same side line-up. If one cannot fit, it moves to the next line.

Clearing To turn off the subsequent floating, and return the layout to “business as usual,” clearing is used. The clear property forces an element to ignore the float and start on the next available line. clear: left; clear: right; clear: both; Example: http://htmlandcssbook.com/code-samples/chapter-15/clear.html From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins

Positioning Elements can also be positioned: Relative to where they would normally appear. Or removed from the flow and placed at an exact, absolute location. Note: Not all methods are well supported, and browser issues can occur. Possible values for the position property include “static, relative, absolute, fixed, inherit” From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins

Position Values static: normal positioning relative: moves relative to normal position. The space the element would have occupied is preserved. absolute: removed from normal flow and positioned relative to the containing element. fixed: removed from normal flow and stays in one position even when the document scrolls From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins

Position Properties Offset properties: top, right, bottom, left Defines the distance the element should be moved away from the respective edge. Negative values are also used to move the element in the opposite direction. From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins

Relative Positioning lower Moves relative to normal position. The original space is preserved. Overlap happens. em { position: relative; top: 15px; color: blue;} <p>I want one word a little <em>lower</em> than the rest.</p> I want one word a little than the rest. From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins lower Example: http://htmlandcssbook.com/code-samples/chapter-15/position-relative.html

Absolute Positioning lower Removed from normal flow and positioned relative to the containing element. No influence on surrounding elements. em { position: absolute; top: 25px; color: blue} <p>I want one word a little <em>lower</em> than the rest.</p> I want one word a little than the rest. From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins lower Example: http://htmlandcssbook.com/code-samples/chapter-15/position-absolute.html

The “Containing Box” The box the element is being positioned to. If the positioned element is contained in another positioned element it will use that as the container. Otherwise, it places the items relative to the initial contained block, the html element. From: Learning Web Design: A Beginner’s Guide to (X)HTML, Style Sheets, and Web Graphics by Jennifer Niederst Robbins

Z-Index Because absolutely positioned elements can overlap one another, z-index in needed. Items stack in the order they appear in the markup. The z-index is a number you can use to bring an item to the front. The higher the number, the higher the element will appear.

Fixed Positioning Works similar to absolute positioning. The main difference is that the offset values are always relative to the browser window. What this means it that the positioned element will always stay in one position even when the page scrolls. ***Not supported by IE6 and earlier*** Example: http://htmlandcssbook.com/code-samples/chapter-15/position-fixed.html

Parents of Floated Elements One issue to be aware of when using floats, is that borders and background colors on parent containers, won’t expand to fill the entire parent container. Example: http://htmlandcssbook.com/code-samples/chapter-15/float-problem.html To fix this issue, “overflow: auto;” or “overflow: hidden;” can be placed on the parent containing element to stretch it. Example: http://htmlandcssbook.com/code-samples/chapter-15/float-solution.html More information: http://www.quirksmode.org/css/clearing.html