Positioning.

Slides:



Advertisements
Similar presentations
Week 10 Creating Positioned Layouts
Advertisements

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.
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.
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 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.
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.
Technologies for web publishing Ing. Václav Freylich Lecture 7.
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.
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.
Cascading Style Sheets Positioning Controls Visibility.
CSS Positioning & Layout Creating layouts and controlling elements.
Tutorial 4 Creating Page Layouts with CSS
IN THE DOCUMENT OBJECT MODEL, EACH LINE OF HTML IS AN ELEMENT (AN OBJECT), ABLE TO HAVE ATTRIBUTES, PROPERTIES AND VALUES. CSS TELLS THE BROWSER HOW TO.
CIS67 Foundations for Creating Web Pages Professor Al Fichera Rev. September 22, 2010—All HTML code brought to XHTML standards. Reference for CIS127 and.
- WE’LL LOOK AT THE POSITION PROPERTY AND HOW CSS RESOLVES CONFLICTS BETWEEN STYLING INSTRUCTIONS The position property; CSS specificity hierarchy.
Today’s objectives  Announcements  Positioning  Measurement units.
Cascading Styles Sheets Positioning HTML elements.
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.
Laying out Elements with CSS
Cascading Style Sheets Layout
CSS Box Model.
CSS Box Model.
The Box Model in CSS Web Design – Sec 4-8
Cascading Style Sheets™ (CSS)
Nesting and Floating.
The Box Model in CSS Web Design – Sec 4-8
CSS Layouts: Grouping Elements
Webpage layout using CSS
Nesting and Floating.
Cascading Style Sheets
Floating & Positioning
Putting Things Where We Want Them
The Box Model in CSS Web Design – Sec 4-8
CS3220 Web and Internet Programming Page Layout with CSS
CS3220 Web and Internet Programming Page Layout with CSS
PAGE LAYOUT - 2.  The div tag equipped with CSS rules produces good looking pages.  With CSS, the div tag can easily be positioned anywhere on the page.
Creating Layouts Using CSS
Controlling Layout with Style Sheets
MORE Cascading Style Sheets (The Positioning Model)
Cascading Style Sheets
CSS Box Model.
Float Property Elements that seem to “float" on the right or left side of either the browser window or another element are often configured using.
HTML – Organizing Page Content
HTML – Organizing Page Content
Cascading Style Sheets
Floating and Positioning
CS3220 Web and Internet Programming Page Layout with CSS
Positioning.
CSS Box Model.
Positioning.
Nesting and Floating.
Laying out Elements with CSS
The div Element and CSS for layout
CSc 337 Lecture 5: Grid layout.
Cascading Style Sheets
Cascading Style Sheets™ (CSS)
Positioning Boxes Using CSS
CGS 3066: Web Programming and Design Fall 2019 CSS Extra
CGS 3066: Web Programming and Design Fall 2019 CSS Part 2
Presentation transcript:

Positioning

Positioning Elements with CSS With the exception of floating elements right or left, we have thus far allowed our page elements to appear one after another down the screen. Using CSS, we can depart from this normal flow in order to: force an element to stay fixed in the same place in the browser window, even while the user continues to scroll further down the page. move elements up, down, right, or left relative to their normal position on the page. remove elements from their normal position and place them in a precise location within the page content. allow elements to overlap and to specify which appears in front and which appears in back.

Positioning Properties and Values The CSS position property has four different values we will use: static - places the element in its usual location in the normal document flow. This is the default value. fixed - removes the element from the normal document flow and fixes it to a specific location in the browser window. Even when the page is scrolled, its location will remain the same. relative - keeps the element in the normal document flow but allows us to move it around relative to its normal location. absolute - removes the element from the normal document flow and allows us to place it in a specific location. It will scroll along with the surrounding page content. The position property is used in conjunction with the top, bottom, right, and left CSS properties. Let's see some examples how these work together.

Fixed Position Let's use the position property to fix an element to a specific location in the browser window: .box1 { height: 100px; width: 100px; background-color: green; position: fixed; top: 50px; right: 75px; } ... <div class="box1"></div> <p>Paragraph 1</p> <p>Paragraph 2</p> We have pinned this element to a fixed location, 50px from the top edge and 75px from the right edge of the browser window. Even as we scroll the page content, the element remains in the same place.

Relative Position Now let's move an element relative to its normal position: .box1 { height: 100px; width: 100px; background-color: green; } .box2 { background-color: blue; position: relative; top: 25px; left: 150px; .box3 { background-color: orange; ... <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> Using relative position, we can nudge elements or even move them to the other side of the page. Remember that relative positioning keeps the element in the normal document flow. No matter where we move the element, its original location will be reserved on the screen.

Absolute Position Here we will change the element to have an absolute position: .box1 { height: 100px; width: 100px; background-color: green; } .box2 { background-color: blue; position: absolute; top: 25px; left: 150px; .box3 { background-color: orange; ... <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> Absolute positioning places the element not relative to its normal position but from the top left corner of the page. Like fixed positioning, absolute positioning removes the element from the normal document flow. Other elements will appear on the page the same as if this element did not exist.

Overlapping Elements Positioning elements can cause them to overlap on the page: .box1 { height: 100px; width: 100px; background-color: green; } .box2 { background-color: blue; position: relative; top: -25px; left: 50px; .box3 { background-color: orange; position: absolute; top: 125px; left: 25px; ... By default, the element last added to the page will appear on top of all others and the first element will appear below all others. Note that we can set position values to be negative numbers. This can even be used to pull elements partially off the visible page.

Controlling the Overlap We can override the default precedence by setting the z-index property: .box1 { height: 100px; width: 100px; background-color: green; position: relative; z-index: 3; } .box2 { ... top: -25px; left: 50px; z-index: 2; .box3 { position: absolute; top: 125px; left: 25px; z-index: 1; Higher z-index values will always appear on top of lower ones, so we can precisely control how elements stack on the page. For the z-index to work, an element must be positioned as relative, absolute, or static.