EECS1012. Net-centric Introduction to Computing. Lecture 5: Yet more CSS (Float and Positioning)

Similar documents
CSE 154 LECTURE 5: FLOATING AND POSITIONING

Web Programming Step by Step

Page Layout. 4.1 Styling Page Sections 4.2 Introduction to Layout 4.3 Floating Elements 4.4 Sizing and Positioning

What is the box model?

EECS1012. Net-centric Introduction to Computing. Lecture 3: CSS for Styling

CSS for Page Layout Robert K. Moniot 1

Unit 20 - Client Side Customisation of Web Pages. Week 2 Lesson 4 The Box Model

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

The CSS Box Model. Motivation. CSS Box Model. CSE 190 M (Web Programming), Spring 2008 University of Washington

COMS 359: Interactive Media

Client-Side Web Technologies. CSS Part II

The Importance of the CSS Box Model

Thinking inside the box

Unit 20 - Client Side Customisation of Web Pages. Week 2 Lesson 4 The Box Model

First Diploma Unit 10 Client Side Web. Week 4 -The CSS Box model

Web Engineering CSS. By Assistant Prof Malik M Ali

2005 WebGUI Users Conference

FLOATING AND POSITIONING

TAG STYLE SELECTORS. div Think of this as a box that contains things, such as text or images. It can also just be a

CSS3 Basics. From & CSS Visual Dictionary Learning Curve Books, LLC

CSS Selectors. element selectors. .class selectors. #id selectors

Building Page Layouts

Web Design and Implementation

Using CSS for page layout

Styles, Style Sheets, the Box Model and Liquid Layout

ITNP43: HTML Lecture 5

IDM 221. Web Design I. IDM 221: Web Authoring I 1

HTML and CSS a further introduction

CSS. Shan-Hung Wu CS, NTHU

BIM222 Internet Programming

CSS: Layout, Floats, and More

Chapter 3 CSS for Layout

Web Site Design and Development Lecture 9. CS 0134 Fall 2018 Tues and Thurs 1:00 2:15PM

More CSS. <link href="filename" type="text/css" rel="stylesheet" /> CS380

Positioning in CSS: There are 5 different ways we can set our position:

First Diploma Unit 10 Client Side Web. Week 4 CSS and Images

<style type="text/css"> <!-- body {font-family: Verdana, Arial, sans-serif} ***set font family for entire Web page***

Assignments (4) Assessment as per Schedule (2)

HTML Organizing Page Content

Unit 20 - Client Side Customisation of Web Pages WEEK 5 LESSON 6 DESIGNING A WEB-SITE

COMM 2555: Interactive Digital Communication / Spring 2018 Lab 9: Basic layout techniques with CSS

Wanted! Introduction. Step 1: Styling your poster. Activity Checklist. In this project, you ll learn how to make your own poster.

Fundamentals of Web Technologies. Agenda: CSS Layout (Box Model) CSS Layout: Box Model. All HTML elements can be considered as a box or a container

CS193X: Web Programming Fundamentals

IDM 221. Web Design I. IDM 221: Web Authoring I 1

Introduction to Computer Science Web Development

Let's take a look at what CSS looks like in Dreamweaver using the "Embedded" coding which is the styles are within the html code and not separate.

CLASSES are a way to select custom elements without using a tag name

Creating Layouts Using CSS. Lesson 9

What is the Box Model?

CSA Website Ad Specifications

AR0051 content/style. Michelle Bettman Henry Kiksen. Challenge the future

12/9/2012. CSS Layout

subject to an additional IP rights grant found at polymer.github.io/patents.txt -->

Parashar Technologies HTML Lecture Notes-4

Perfect Student Midterm Exam March 20, 2007 Student ID: 9999 Exam: 7434 CS-081/Vickery Page 1 of 5

mpdf Example 6. Tables nested <?php

Creating and Building Websites

CSS Box Model. Cascading Style Sheets

COMSC-031 Web Site Development- Part 2

CSC309 Winter Lecture 2. Larry Zhang

To place an element at a specific position on a page use:

Creating a Navigation Bar with a Rollover Effect

CSS: Lists, Tables and the Box Model

Creating a CSS driven menu system Part 1

Week 5 jquery and the DOM

Tutorial 4: Creating Special Effects with CSS

CSc 337 LECTURE 5: GRID LAYOUT AND JAVASCRIPT

Welcome Please sit on alternating rows. powered by lucid & no.dots.nl/student

HTML Organizing Page Content

CSS. M hiwa ahamad aziz Raparin univercity. 1 Web Design: Lecturer ( m hiwa ahmad aziz)

CSS. MPRI : Web Data Management. Antoine Amarilli Friday, December 7th 1/43

Internet Programming 1 ITG 212 / A

CSS Layout Part I. Web Development

New Features in mpdf v5.7

Getting Started with Eric Meyer's CSS Sculptor 1.0

mpdf Version 4.2 New Features mpdf Version Anystreet Your City GD12 4LP th June 2018


Web Site Design and Development Lecture 7. CS 0134 Fall 2018 Tues and Thurs 1:00 2:15PM

HTML and CSS COURSE SYLLABUS

Cascading Style Sheets for layout II CS7026

Introduction to HTML & CSS. Instructor: Beck Johnson Week 5

Media Types & Media Features

Website Development with HTML5, CSS and Bootstrap

CSC 337. Cascading Style Sheets. Marty Stepp, Rick Mercer

Create a three column layout using CSS, divs and floating

RML Example 48: Paragraph flow controls

Cascading Style Sheet Quick Reference

There are 3 places you can write CSS.

This is an H1 Header. This is an H2 Header. This is an H3 Header

CSCU9B2: Web Tech Lecture 3

MichPA Content Guide. Table of Contents. Website Section Overview. Global Banner & Navigation. Content Area Client editable

How to lay out a web page with CSS

What do we mean by layouts?

Cascading Style Sheets (Part II)

CSS often uses hyphens in CSS property names but JavaScript uses camel case, e.g. color: blue; p { <!DOCTYPE html> <meta charset="utf-8" /> <head>

The default style for an unordered (bulleted) list is the bullet, or dot. You can change the style to either a square or a circle as follows:

Web Authoring and Design. Benjamin Kenwright

Introduction to HTML & CSS. Instructor: Beck Johnson Week 2

Transcription:

EECS 1012 EECS1012 Net-centric Introduction to Computing Lecture 5: Yet more CSS (Float and Positioning) Acknowledgements Contents are adapted from web lectures for Web Programming Step by Step, by M. Stepp, J. Miller, and V. Kirst. Slides have been ported to PPT by Dr. Xenia Mountrouidou. These slides have been edited for EECS1012, York University. The contents of these slides may be modified and redistributed, please give appropriate credit. M.S. Brown, EECS York University 1 (Creative Commons) Michael S. Brown, 2017.

2 Floating Elements

Elements flow 3 h1 p text img text text Many times the default flow of content in HTML is a bit ugly. p p The default flow of block elements is to take up all the horizontal space.

Modifying flow 4 h1 p text text img Image is aligned to the right. text p p Two columns for paragraphs.

Alignment might not work 5 Let s try to generate two side by side <p>.left {text-align: left; width: 280px; border: solid 1px;}.right {text-align: right; width: 280px; border: solid 1px;} CSS <p class="left"> <!-- align left --> Lorem ipsum dolor sit amet, sagittis mauris, tellus quo erat ante vel diam eu, sed lacus. Nulla eleifend ullamcorper </p> <p class="right"> <!-- align right --> Lorem ipsum dolor sit amet, sagittis mauris, tellus quo erat ante vel diam eu, sed lacus. Nulla eleifend ullamcorper sagittis arcu, </p> html

Alignment might not work 6 output Text-align only affects the content inside the block elements, the block elements is still take up the entire horizontal space. EECS 1012

Float - layout property 7.left { float: left; width: 280px; border: solid 1px; }.right { float: right; width: 280px; border: solid 1px; } CSS <p class="left"> Lorem ipsum dolor sit amet, sagittis mauris, tellus quo erat ante vel diam eu, sed lacus. Nulla eleifend ullamcorper </p> <p class="right"> Lorem ipsum dolor sit amet, sagittis mauris, tellus quo erat ante vel diam eu, sed lacus. Nulla eleifend ullamcorper sagittis arcu, </p> html CS

Floating elements 8 output EECS 1012 The float property removes an element from the normal flow. In this case, the first paragraph floats to the left and the second floats to the right. As long as there is sufficient screen space that they don t overlay, they will share the horizontal space. Note that is generally necessary to specify the width of the elements.

Float property values 9 img.right { float: right; width: 130px; } CSS property float description side to hover on; can be left, right, or none (default) EECS 1012

Another example 10 img.right { float: right; width: 130px; } <p style="border: solid;"> <img class="right" src="https://tinyurl.com/ybafqu2h"> Cute cat. </p> CSS <p style="border: solid;"> Lorem ipsum dolor sit amet, sagittis mauris, tellus quo erat ante vel diam eu, sed lacus. Nulla eleifend ullamcorper sagittis arcu, </p> html EECS 1012

Floating has disadvantages 11 In this case, the floating <img> element is inside a <p> element, but its content extends beyond the containing <p> element. In this case, it floats into the next paragraph and affects the flow of the next element!

Floating has disadvantages 12 p p text text img text Floating elements can invade other elements

Clear layout property 13 img.right { float: right; width: 130px; } p.avoidfloat { clear: both; } <p style="border: solid;"> <img class="right" src="https://tinyurl.com/ybafqu2h"> Cute cat. </p> CSS <p class="avoidfloat" style="border: solid;"> Lorem ipsum dolor sit amet, sagittis mauris, tellus quo erat ante vel diam eu, sed lacus. Nulla eleifend ullamcorper sagittis arcu, </p> html EECS 1012

Clear property example 14 EECS CS 1012 The second paragraph has its clear property set to both, which means clear both left and right floating elements.

The clear property (cont.) 15 property clear description disallows floating elements from overlapping this element; can be left, right, both, or none (default) Try it out here: https://www.w3schools.com/cssref/pr_class_clear.asp EECS CS 1012

Floating multiple elements 16 p { float: right; width: 25%; margin: 0.5em; border: 2px solid black; } div { border: 3px dotted green; overflow: hidden; } CSS <div> </div> <p>first paragraph</p> <p>second paragraph</p> <p>third paragraph</p> Some other text that is important. HTML Some other text that is important third paragraph second paragraph first paragraph And this one too! Since there is still horizontal space, this floats to the right too output Float to the right and uses 25% of the width

Floating multiple elements 17 p { float: right; width: 25%; margin: 0.5em; border: 2px solid black; clear: right;} div { border: 3px dotted green; overflow: hidden; } CSS <div> </div> <p>first paragraph</p> <p>second paragraph</p> <p>third paragraph</p> Some other text that is important HTML Some other text that is important third paragraph second paragraph first paragraph Q: What would happen if we add a clear property? output

18 Sizing and Positioning

Instead of float.. give the position 19 We can try to give the position of the element directly on the page. p text div #menu p text text Specify element to appear at this position. Often used with div sections. EECS 1012

An example demo layout 20 #left, #right, #top { border: solid 1px; background-color: #eee;} #top {clear: both; width: 590px; height:100px; } #left {float: left; width: 280px; height: 300px; } #right {float: right; width: 280px; height: 300px;}.pos { position: static; width : 110px; height: 110px; margin:0; background-color: red; } CSS <div id="top"> </div> <div id="left"> <img class="pos" src="https://tinyurl.com/ybafqu2h"> </div> <div id="right"> </div> HTML

Layout example from previous slide 21 div id= top img element we are positioning. It is contained within div id= left. div id= left div id= right EECS CS 1012

Position: relative 22.pos { position: relative; left: 10px; top: 10px; } div id= top element we are positioning. Relative modifies the position relative to its original position in the flow. You can use negative values! Since this is relative to its original position, setting: left: -10px is the same as right: 10px; bottom: 10px is the same as top: -10px; div id= left div id= right

Position: fixed 23.pos { position: fixed; left: 0px; top: 0px; } div id= top This modifies the position of the element with respect to the web browser s screen. It will not move, even if you scroll the webpage! element we are positioning. div id= left div id= right

Position: absolute 24.pos { position: absolute; bottom: 0px; right: 0px; } element we are positioning. div id= top absolute position is the most confusing. This positions the element with respect to the last containing element (called an ancestor) that also has a position style that was not static. In this case, our original HTML and CSS did not set the position for div id= left (container for the img element) so, the image is positioned with respect to the <body>. Unlike fixed position, the image will scroll with the browser s content. div id= left div id= right Image is now positioned with respect to the body (that has a width and height of the screen)

No change. Modify the CSS 25 #left, #right, #top { border: solid 1px; background-color: #eee;} #top {clear: both; width: 590px; height:100px; } #left {float: left; width: 280px; height: 300px; position: relative;} #right {float: right; width: 280px; height: 300px; } CSS div id= left position style is no longer static. By setting the position to relative in #left, we have activated its position not to be static. Since we didn t modify the position (we didn t change the left, top, etc), the div position didn t move. However, this will affect the behavior of any contained element that issues an absolute position later.

Example position: absolute 26.pos { position: absolute; bottom: 0px; right: 0px; } element we are positioning. div id= top absolute position for the image element is now performed with respect to the div id=left container - since the #left container has a position that is not set to static. The div #left defines its height and width, our image is positioned at the bottom of the #left div. div id= left div id= right Image is now positioned with respect to id

Position property values 27 property value description position top, bottom, left, right static relative absolute fixed positions of box's corners default position offset from its normal static position a fixed position within its containing element (that has an active position) a fixed position within the browser window EECS 1012

When content overflows.. 28 <div id="top"> <p class="pos"> <img class="pos" src="https://tinyurl.com/ybafqu2h"> </p> </div> <div id="left"> </div> <div id="right"> </div> HTML.pos { position: relative; left: 10px; top: 10px; } In this example, I moved the image to be in the div id= top container. The image overflows its container region since the height is fixed for this div section. Now the image overflow into the next section. How can we avoid it? Note that this is not the same as clearing an alignment. The image was not floated, it was positioned! EECS 1012

Overflow property 29 #top { clear: both; width: 590px; height:100px; overflow: hidden; CSS We can set the overflow property for the #top style. This specifies how this element should handle any overflowing content. This example is hidden (i.e. cut any overflow) #top { clear: both; width: 590px; height:100px; overflow: auto; CSS auto property adds in a scrollbar to see the overflow content!

Overflow property 30 Value visible hidden scroll auto Description The overflow is not clipped. It renders outside the element's box. This is default The overflow is clipped, and the rest of the content will be invisible The overflow is clipped, but a scroll-bar is added to see the rest of the content If overflow is clipped, a scroll-bar should be added to see the rest of the content EECS 1012

Alignment vs. float vs. position 31 1. If possible, lay out an element by aligning its content horizontal alignment: text-align set this on a block element; it aligns the content within it (not the block element itself) vertical alignment: vertical-align set this on an inline element, and it aligns it vertically within its containing element 2. If alignment won't work, try floating the element 3. If floating won't work, try positioning the element absolute/fixed positioning are a last resort and should not be overused

Details about inline boxes 32 Size properties (width, height, min-width, etc.) are ignored for inline boxes margin-top and margin-bottom are ignored, but margin-left and margin-right are not ignored EECS CS 1012

Details about inline boxes 33 the containing block box's text-align property controls horizontal position of inline boxes within it text-align does not align block boxes within the page This is the demonstrated on slide 6 each inline box's vertical-align property aligns it vertically within its block box EECS CS 1012

The display property 34 h2 { display: inline; background-color: yellow; } CSS output property display description sets the type of CSS box model an element is displayed with We can force items to act like inline or block! values: none, inline, block, run-in, compact,... use sparingly, because it can radically alter the page layout

The display property (cont.) 35 p.secret { visibility: hidden; } CSS output hidden elements will still take up space onscreen, but will not be shown to make it not take up any space, set display to none instead can be used to show/hide dynamic HTML content on the page in response to events (we will see this when we do JavaScript) EECS CS 1012

Example: display property 36 <ul id="topmenu"> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul> HTML #topmenu li { display: inline; border: 2px solid gray; margin-right: 1em; } CSS output lists and other block elements can be displayed inline The <li> elements above now flow left-to-right on same line width is determined by content

Recap 37 We are now done with CSS and HTML There is a lot of information to absorb Keep a bookmark to w3schools.com Practice and experience helps, CSS can be very frustrating We will not do very complex HTML and CSS in this module EECS 1012

There is more to HTML and CSS 38 You have seen a fairly comprehensive overview of the most common items in HTML and CSS There is (much) more.. E.g. frames - allow you to divide your browser into multiple independent views Many more tags, e.g. <marquee> Try it </marquee> HTML5 semantic sections more... EECS 1012