Cascading Style Sheets (Part II)

Similar documents
Appendix D CSS Properties and Values

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

Cascading Style Sheet Quick Reference

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

12/9/2012. CSS Layout

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

BIM222 Internet Programming

Parashar Technologies HTML Lecture Notes-4

Cascading Style Sheets CSCI 311

Client-Side Web Technologies. CSS Part II

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


Adding CSS to your HTML

INTERNATIONAL UNIVERSITY OF JAPAN Public Management and Policy Analysis Program Graduate School of International Relations

COSC 2206 Internet Tools. CSS Cascading Style Sheets

CASCADING STYLESHEETS

CSS مفاهیم ساختار و اصول استفاده و به کارگیری

CMPT 165: More CSS Basics

Web Design and Implementation

Internet Programming 1 ITG 212 / A

Web Engineering CSS. By Assistant Prof Malik M Ali

IMY 110 Theme 6 Cascading Style Sheets

CSS Box Model. Cascading Style Sheets

Creating Layouts Using CSS. Lesson 9

Web Design and Development Tutorial 03

Assignments (4) Assessment as per Schedule (2)

UNIVERSITI TEKNOLOGI MALAYSIA TEST 1 SEMESTER II 2012/2013

COMS 359: Interactive Media

Cascade Stylesheets (CSS)

Introduction to Web Design CSS Reference

Introduction to Web Design CSS Reference

CSS: Lists, Tables and the Box Model

Module 2 (VII): CSS [Part 4]

Introduction to Multimedia. MMP100 Spring 2016 thiserichagan.com/mmp100

HTML & CSS. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Building Page Layouts

FLOATING AND POSITIONING

ITNP43: HTML Lecture 5

INTERNATIONAL UNIVERSITY OF JAPAN Public Management and Policy Analysis Program Graduate School of International Relations

Make a Website. A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1

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

Page Layout Using Tables

1 of 7 11/12/2009 9:29 AM

escuela técnica superior de ingeniería informática

Styles, Style Sheets, the Box Model and Liquid Layout

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

Learning Objectives. Review html Learn to write a basic webpage in html Understand what the basic building blocks of html are

Table Basics. The structure of an table

CSS stands for Cascading Style Sheets Styles define how to display HTML elements

Programmazione Web a.a. 2017/2018 HTML5

ID1354 Internet Applications

A HTML document has two sections 1) HEAD section and 2) BODY section A HTML file is saved with.html or.htm extension

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

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

Web Authoring and Design. Benjamin Kenwright

Chapter 3 CSS for Layout

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

COMSC-031 Web Site Development- Part 2

Hyper Text Markup Language HTML: A Tutorial

Downloads: Google Chrome Browser (Free) - Adobe Brackets (Free) -

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

CSS Cascading Style Sheets

Chapter 1 Getting Started with HTML 5 1. Chapter 2 Introduction to New Elements in HTML 5 21

HTML and CSS COURSE SYLLABUS

3.1 Introduction. 3.2 Levels of Style Sheets. - The CSS1 specification was developed in There are three levels of style sheets

- The CSS1 specification was developed in CSS2 was released in CSS2.1 reflects browser implementations

B3: A first introduction to CSS 17/02/2006

Networks and Web for Health Informatics (HINF 6220) Tutorial 8 : CSS. 8 Oct 2015

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

Tutorial 3: Working with Cascading Style Sheets

HTML and CSS: An Introduction

2005 WebGUI Users Conference

Module 2 (VI): CSS [Part 3]

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

CS 350 COMPUTER/HUMAN INTERACTION. Lecture 6

CSS. Lecture 16 COMPSCI 111/111G SS 2018

Introduction to WEB PROGRAMMING

CSC309 Programming on the Web week 3: css, rwd

Produced by. Web Development. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology

Chapter 3 Style Sheets: CSS

Using CSS for page layout

CSS Lecture 16 COMPSCI 111/111G SS 2018

- The CSS1 specification was developed in CSSs provide the means to control and change presentation of HTML documents

CSCB20 Week 7. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Reading 2.2 Cascading Style Sheets

Using Microsoft Word. Working With Objects

HTML/XML. HTML Continued Introduction to CSS

ICT IGCSE Practical Revision Presentation Web Authoring

GIMP WEB 2.0 MENUS WEB 2.0 MENUS: HORIZONTAL NAVIGATION BAR CREATING AN HTML LIST

What do we mean by layouts?

CSS means Cascading Style Sheets. It is used to style HTML documents.

HTML and CSS a further introduction

By Ryan Stevenson. Guidebook #3 CSS

LBS Polytechnic. Hey! Make With The Style Sheet Already, Bub!

Cascading Style Sheets

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

Web Design and Development ACS Chapter 12. Using Tables 11/23/2017 1

Session 3.1 Objectives Review the history and concepts of CSS Explore inline styles, embedded styles, and external style sheets Understand style

SEEM4570 System Design and Implementation. Lecture 1 Cordova + HTML + CSS

Transcription:

Cascading Style Sheets (CSSs) (Part II) Page Layout with Styles...1 Offsetting Elements...1 Positioning Elements Absolutely...3 Positioning Elements in 3D...4 Displaying and Hiding Elements...5 Setting an Element s Height and Width...6 Setting an Element s Border...7 Adding Padding around an Element...8 Setting the Margins around an Element...10 Aligning Elements Vertically...12 Wrapping Text around Elements...13 Stopping Text Wrapping...15 Changing the Foreground Colour...16 Changing the Background...17 Determining where Overflow Should Go...19 Clipping an Element...20 Setting List Properties...21 Specifying Page Breaks...23

Cascading Style Sheets (CSSs) (Part II) Page Layout with Styles Every item that is created using CSSs is enclosed in an invisible box - the size, colour, spacing and the way it flows can be controlled with respect to other objects on the page. An element s box may be block-level or inline; whilst the first generates a new paragraph, the second does not. There are three special areas of the box, which can be controlled the padding, border and margin. Surrounding the contents of the box is the padding; around the padding is the border, and around the border is the margin (a transparent space). The margin s width and height can be changed in order to control the position of the elements on your page. Some elements may contain other elements on the page; they are referred to as parents. Offsetting Elements Each of the elements on a page has a natural location in the flow of the page. Relative positioning refers to the movement of an element with respect to its original location. Relative positioning does not affect the positioning of any surrounding elements at all. In order to offset an element within the natural flow: 1. Type position: relative; in the element s definition in the <style> section of the HTML document (or in the relevant section of the external.css file). 2. Type top, right, bottom or left 3. Type : d; where d is the desired distance that you want to offset the element from its natural location; either as an absolute or relative value. 1

Example <title>offsetting Elements within the Natural Flow</title> img {position:relative; top: 0px; left:0px;} img.test {position:relative; top:-20px; left:25px;} <br /> <img src="logo.gif" alt="html4.co.uk s logo" /> <img src="logo.gif" alt="html4.co.uk s logo" class="test" /> The relative positioning refers to the element s original position, not the surrounding elements. You cannot move elements with respect to other elements, just with respect to where they used to be. The other elements are not affected by the offsets they flow with the original containing box of the element. 2

Positioning Elements Absolutely The elements in your web page would flow in the order in which they appear. If the <ol> tag for example appears before the <table> tag, then the ordered list would appear before the table. This is known as the normal flow. In addition to being able to offset individual elements, styles also allow you to take elements out of the normal flow, and position them absolutely by specifying their precise position with respect to their parent element. In order to absolutely position elements: 1. Type position: absolute; in the element s definition in the <style> section of the HTML document (or in the relevant section of the external.css file). 2. Type top, right, bottom or left 3. Type : d; where d is the desired distance that you want to offset the element from its natural location; either as an absolute or relative value. Example <title>positioning Elements Absolutely</title> img {position:absolute; top:10px; left:10px;} <br /> <img src = "logo.gif" alt="html4.co.uk s logo" /> <img src = "minilogo.gif" alt="html4.co.uk s mini logo" /> 3

Because absolutely positioned elements are taken out of the natural flow, they can overlap each other. Positioning Elements in 3D Having tried out both relative and absolute positioning, you may want to choose, which element should be on top. In order to position elements in 3D: Type z-index: n in the element s definition in the <style> section of the HTML document (or in the relevant section of the external.css file), where n is a number, which indicates the position of the element in the stack of objects. Example <title>positioning Elements in 3D</title> img {position:absolute; top:10px; left:10px} img.test {position:absolute; top:10px; left:10px; z-index:-1} <img src = "logo.gif" alt="html4.co.uk s logo" /> <img src = "minilogo.gif" alt="html4.co.uk s mini logo" class="test" /> 4

Displaying and Hiding Elements The display property is useful for hiding or revealing particular elements on your web page depending on the visitor s browser, language preference, or other criteria. You can also choose, whether you want to display an element as block-level or inline. In order to specify how your page s elements should be displayed: 1. Type display: 2. Type none in order to hide elements block in order to display the element as a block-level (which would start a new paragraph) inline in order to display the element as inline (which would not start a new paragraph) list-item in order to display the element as if though it was a list element. Example <title>displaying and Hiding Elements with Styles</title> img {position:absolute; top:10px; left:10px;} img.test {display:none} 5

<img src= "logo.gif" alt="html4.co.uk s logo" /> <img src= "minilogo.gif" alt="html4.co.uk s mini logo" class="test" /> In contrast to the previous example, the image, which was positioned behind the logo above, has not appeared, as the display: none property was used in the style s definition. Setting an Element s Height and Width Styles are also used to set the height and width for most elements on your page, including images, form elements and even blocks of text. In order to set the height and width for an element: 1. Type width: w where w is the width of the element, and can be expressed either as an absolute value or as a percentage of the window width. 2. Type height: h where h is the height of the element, and can be expressed only as an absolute value. You cannot set the width property for most text tags (such as P and H1). 6

Example <title>setting an Element s Height and Width</title> img {position:absolute; top:10px; left:10px; width: 30%; height: 200px} <img src="logo.gif" alt="html4.co.uk s logo" /> Setting an Element s Border Styles allow you to create a border around an element and then set its thickness, style and colour. In order to set the border: 1. Type border 2. If wanted, type top, -bottom, -left or right with no space after border in order to limit where the border should go. 3. If wanted, type :thin, medium, thick or an absolute value to specify the thickness of the border. 7

4. If wanted, type none, dotted, dashed, solid, double, groove, ridge, inset or outset to specify the border style. 5. If desired, type color where color can be either one of the sixteen pre-defined colours or a hexidecimal colour code. Example <title> Setting an element s border</title> img {position:absolute; top: 10px; left: 10px; border-left: thick double #ff00ff;} <img src="logo.gif" alt="html4.co.uk s logo" /> Adding Padding around an Element Styles allow you to add padding (extra space) around the contents of an element but inside the border. You can change the padding s thickness, but not its colour or texture. 8

In order to add padding around an element: 1. Type padding 2. If wanted, type top, -bottom, -left or right with no space after padding in order to limit the padding only around one side of the object. 3. Type : x where x is the amount of desired space to be added, expressed in units or as a percentage of the parent element. When adding padding with styles, several shortcuts are available to allow us to set the padding values. Here are some of them: In order to set the top, right, bottom and left values in that order at once, type padding: t r b l In order to set the top and bottom values equally and the left and right values equally, type padding: v h In order to set the value for all sides, type padding: a Example <title>adding Padding around an Element</title> h1{padding:50px; border: thick double black;} <h1>welcome to my web-site</h1> <img src="logo.gif" alt="html4.co.uk s logo" /> 9

Setting the Margins around an Element The margin is the amount of transparent space between one element and the next, in addition to and outside of any padding or border around the element. In order to set an element s margin: 1. Type margin 2. If wanted, type top, -bottom, -left or right with no space after margin in order to limit where space should be added. 3. Type : x where x is the amount of desired space to be added, expressed in units or as a percentage of the width parent element. When setting the margins with styles, several shortcuts are available to allow us to set the margin values. Here are some of them: In order to set the top, right, bottom and left values in that order at once, type margin: t r b l In order to set the top and bottom values equally and the left and right values equally, type margin: v h In order to set the value for all sides, type margin: a 10

Example <title>setting the Margins around an Element</title> h1{padding:50px; margin-bottom: 50px; border: thick double black;} <h1>welcome to my web-site</h1> <img src="logo.gif" alt="html4.co.uk s logo" /> In contrast with the previous example there is an additional margin of 50 units added after the Welcome to my web-site element of the above web page. 11

Aligning Elements Vertically The elements of a Web page can be aligned vertically in the same way, like for example images on a web page. In order to align elements vertically: 1. Type vertical-align: 2. Type baseline to align the element s baseline with the parent s baseline middle to align the middle of the element with the middle of the parent sub to position the element as a subscript of the parent super to position the element as a superscript of the parent text-top to align the top of the element with the top of the parent text-bottom to align the bottom of the element with the bottom of the parent top to align the top of the element with the top of the tallest element on the line bottom to align the bottom of the element with the bottom of the tallest element on the line percentage of the line height of the element (positive or negative) Example <title>aligning elements vertically</title> img {vertical-align:top} 12

<br /> <img src="logo.gif" alt="html4.co.uk s logo" /> <img src="minilogo.gif" alt="html4.co.uk s mini logo" /> Wrapping Text around Elements Styles can be used to wrap text around elements. In order to wrap text around elements: 1. Type float: 2. Type left if you want the text to flow to the right of the element. or right if you want the text to flow to the left of the element. 13

Example <title>wrapping text around elements using styles</title> img.left {float:left} img.right{float:right} ol{text-indent:2em} <br /> <img src = "logo.gif" alt="html4.co.uk s logo" class="left" /> Welcome to html4.co.uk! <p>the topics covered on the course are as follows:</p> <ol> <li>html Basics</li> <li>text Formatting</li> <li>..</li> </ol> <p>today's teaching session is aimed to show you how to construct a web page using HTML.</p> <p>before we start constructing HTML pages however, I would like to introduce you briefly to the HTML language and some basic HTML concepts.</p> <p> <img src="logo.gif" alt="html4.co.uk s logo" class="right" /></p> <p>html stands for Hyper Text Markup Language and was developed in Switzerland by the programmers at the CERN research laboratory.</p> <p>the father of HTML is considered to be Tim Berners Lee, who was the driving force behind the development of the World Wide Web. </p> 14

Stopping Text Wrapping In addition to allowing you to wrap text around elements, styles also allow you to stop the text from wrapping around an element. In order to do that: 1. Type clear: 2. Type left to stop the flow until the left side is clear of all elements right to stop the flow until the right side is clear of all elements both to stop the flow until both sides are clear of all elements none to continue the flow 15

Changing the Foreground Colour Styles allow you to change the colour of any element, including horizontal lines, form elements, and tables. In order to change the foreground colour: 1. Type color: 2. Type colorname where colorname is either one of the 16 predefined colours, a colour s hexidecimal value (#rrggbb), or is denoted by specifying the amount of red, green and blue (either using integers from 0-255 rgb (r,g,b) or percentages rgb (r%, g%, b%) Example <title>changing the foreground using styles</title> img.left {float:left} ol{text-indent:2em} hr {color:blue; height:20px;) <br /> <img src="logo.gif" alt="html4.co.uk s logo" class="left" /> Welcome to html4.co.uk! <hr></hr> <p>the topics covered on the course are as follows:</p> <ol> <li>html Basics</li> <li>text Formatting</li> <li>..</li> </ol> 16

Changing the Background The background in this context refers not to the background of the entire page, but to the background of a particular tag. In order to change the background of a tag: 1. Type background: 2. Type transparent or colorname where colorname is either one of the 16 pre-defined colours or the colour s hexidecimal value (#rrggbb). 3. If wanted, type url(image.gif), to use an image for the background; if wanted, you can also type: repeat repeat-x repeat-y fixed or scrolled or type x y to tile the image both horizontally and vertically to tile the image only horizontally to tile the image only vertically to specify whether the background should scroll with the canvas where x and y can be expressed as a percentage or as an absolute distance, or can be the values of top, center and bottom for x and left, right and center for y. 17

Example <title>changing the background using styles</title> img.left {float:left} ol{text-indent:2em} body{background: url(minilogo.gif)} p.intro {background: white; padding:5px) <br /> <img src = "logo.gif" alt="html4.co.uk s logo" class="left" /> Welcome to html4.co.uk! <p>the topics covered on the course are as follows:</p> <ol> <li>html Basics</li> <li>text Formatting</li> <li>..</li> </ol> <p class="intro">today's teaching session is aimed to show you how to construct a web page using HTML. Before we start constructing HTML pages however, I would like to introduce you briefly to the HTML language and some basic HTML concepts.</p> 18

Determining where Overflow Should Go As explained at the beginning of this handout, every element is enclosed in a box (container) on the web page. If the element s box height and weight are changed in such a way that the contents of the element are in excess of the box s dimensions then an overflow occurs. In order to deal with this overflow, you should follow these instructions: 1. Type overflow: 2. Type visible to expand the element s box so that its contents can fit in it. Example or type hidden to hide any contents that don t fit the element s box or type scroll to add scroll bars allowing the visitor to access the overflow, which has occurred. <title>dealing with Overflow using styles</title> body{background: url(minilogo.gif)} p.intro {background: white; padding:5px;} <div style="position:relative; width:100px; height:100px; overflow:scroll"> <p class="intro">today's teaching session is aimed to show you how to construct a web page using HTML. Before we start constructing HTML pages however, I would like to introduce you briefly to the HTML language and some basic HTML concepts.</p> </div> 19

Clipping an Element Styles allow you to reveal only a particular section of an element by clipping the element. In order to clip an element: 1. Type clip:rect ( 2. Type t r b l where t r b l is top is right is bottom is left coordinates of the rectangular portion of the element that you want to display. 3. Type the final ) With the current style sheets specification, an element has to be positioned absolutely before it can be clipped. <title>clipping an Element using styles</title> body{background: url(minilogo.gif)} p.intro {background: white; padding:5px;} 20

<div style="position:relative; width:100px; height:100px; overflow:scroll"> <p class="intro">today's teaching session is aimed to show you how to construct a web page using HTML. Before we start constructing HTML pages however, I would like to introduce you briefly to the HTML language and some basic HTML concepts.</p> </div> <img src="logo.gif" style="position:absolute;top:150px; clip:rect(0 180 130 40)" alt="logo"/> Setting List Properties Styles allow you to set up list properties. In order to set the properties of a list: 1. Type list-style: 2. Choose one of the following: disc to set the list item marker to a solid, round circle circle to set the list item marker to an empty round circle square to set the list item marker to a solid square decimal to set the list item marker to use arabic numerals lower-alpha to set the list item marker to use lowercase letters upper-alpha to set the list item marker to use uppercase letters 21

lower-roman to set the list item marker to use lower-case Roman numerals upper-roman to set the list item marker to use upper-case Roman numerals url(image) where image is the URL of the image you want to use as a list marker 3. If wanted, type outside to hang the marker to the left of the list items or inside to align the marker flush left together with the list items. Example <title>setting List Properties using styles</title> body{background:white} li{list-style:url(minilogo.gif) inside} <ol> <li>today's teaching session is aimed to show you how to construct a web page using HTML.</li> <li>before we start constructing HTML pages however, I would like to introduce you briefly to the HTML language and some basic HTML concepts.</li> </ol> 22

Specifying Page Breaks If your visitors want to print out your Web page, the browsers would automatically adjust the contents on the page in order to best fit the paper size the visitor has chosen in the Page Setup dialog window. Cascading Style Sheets (version 2) allows you to specify where you want the page to break when your visitor prints out the web page. In order to specify a page break after a tag just type: page-break-after:always In order to specify a page break before a tag just type: page-break-before:always In order to remove page breaks just type: page-break-before:auto or page-break-after:auto Example <title>specifying page breaks using styles</title> body{background:white} p.first,p.second{page-break-before:always} <p class="first" style="page-break-before:auto"> Today's teaching session is aimed to show you how to construct a web page using HTML. </p> <p class="second">before we start constructing HTML pages however, I would like to introduce you briefly to the HTML language and some basic HTML concepts. </p> 23

24