Back in the good old days type was set by hand using printing presses.

Similar documents
Let s start with the document tree

DEEP DIVE INTO LINE-HEIGHT

What is the box model?

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

ICT IGCSE Practical Revision Presentation Web Authoring

VISA/APCO/STAC 2P61 WEBSITE CREATION Fall Term 2012

Cascading Style Sheets Level 2

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

Styles, Style Sheets, the Box Model and Liquid Layout

ACSC 231 Internet Technologies

The Importance of the CSS Box Model

CSS Cascading Style Sheets

Text and Layout. Digital Multimedia, 2nd edition Nigel Chapman & Jenny Chapman Chapter 11. This presentation 2004, MacAvon Media Productions

CSS exercise - Part 1

2005 WebGUI Users Conference

Floats, Grids, and Fonts

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

Unveiling the Basics of CSS and how it relates to the DataFlex Web Framework

CSS 1: Introduction. Chapter 3

Getting Started with Eric Meyer's CSS Sculptor 1.0

CS193X: Web Programming Fundamentals

Web Site Design and Development Lecture 6

The Benefits of CSS. Less work: Change look of the whole site with one edit

CSS.

limelightplatform.com

HTML. Based mostly on

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

To link to an external stylesheet, the link element is placed within the head of the html page:

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2)

ICT IGCSE Practical Revision Presentation Word Processing

Introduction to CSS. Fijihosting.com Introduction to CSS page 1. What are style sheets? Lovely! How do I use them?

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

CSS. Shan-Hung Wu CS, NTHU

Reading 2.2 Cascading Style Sheets

Creating Layouts Using CSS. Lesson 9

CSS: The Basics CISC 282 September 20, 2014

CSC Website Design, Spring CSS Flexible Box

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

Appendix D CSS Properties and Values

Adding CSS to your HTML

READSPEAKER ENTERPRISE HIGHLIGHTING 2.5

Taking Fireworks Template and Applying it to Dreamweaver

CSS Cascading Style Sheets

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

CSS worksheet. JMC 105 Drake University

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

Introduction to WEB PROGRAMMING

Introduction to Computer Science Web Development

Agenda. Combining Rules & Selectors Classes, IDs and DIVs

Chapter 3 Style Sheets: CSS

Cascading Style Sheets (CSS)

Introducing Cascading Style Sheets. Cascading Style Sheet Basics Creating Styles Using Styles Manipulating Styles Text Formatting with CSS

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

Introduction to CSS. Part 1: Simple Text Formatting. Source Files for this Exercise are available on the Course Website DW_CSS intro

Admin & Today s Agenda

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

Zen Garden. CSS Zen Garden

CSS: Cascading Style Sheets

CSS. Lecture 16 COMPSCI 111/111G SS 2018

Review Question 1. Which tag is used to create a link to another page? 1. <p> 2. <li> 3. <a> 4. <em>

Web Design and Development Tutorial 03

HTML TUTORIAL ONE. Understanding What XHTML is Not

Web Design and Implementation

PUBLISHER SPECIFIC CSS RULES

H A-Z of DTP Features

CSS THE M\SS1NG MANUAL. David Sawyer McFarland. POGUE PRESS" O'REILLr Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo

Web design and development ACS Chapter 5. Working with Text

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

Tutorial 3: Working with Cascading Style Sheets

Using Dreamweaver CC. Logo. 4 Creating a Template. Page Heading. Page content in this area. About Us Gallery Ordering Contact Us Links

CSS. Text & Font Properties. Copyright DevelopIntelligence LLC

HTML Organizing Page Content

Cascading Style Sheets for layout II CS7026

COMS 359: Interactive Media

CSS Lecture 16 COMPSCI 111/111G SS 2018

ICT IGCSE Practical Revision Presentation Web Authoring

Class 3 Page 1. Using DW tools to learn CSS. Intro to Web Design using Dreamweaver (VBUS 010) Instructor: Robert Lee

Introduction to Web Design CSS Reference

USER GUIDE MADCAP FLARE Tables

Introduction to Web Design CSS Reference

Using Advanced Cascading Style Sheets

Using CSS for page layout

Text. Text metrics. There are some important metrics that we must consider when working with text. Figure 4-1 shows the basics.

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

Assignments (4) Assessment as per Schedule (2)

Session 4. Style Sheets (CSS) Reading & References. A reference containing tables of CSS properties

CS193X: Web Programming Fundamentals

Using CSS in Web Site Design

To illustrate how to set TAG styles the <body> and <h1> tags (for the BODY and the HEADING 1 styles) will be adjusted.

IMY 110 Theme 11 HTML Frames

What is the Box Model?

ENGINEERING DATA HUB VISUAL DESIGN SPECIFICATIONS VERSION 3. Created: 2/10/2017

Using Dreamweaver to Create Page Layouts

Chapter 7 Typography, Style Sheets, and Color. Mrs. Johnson

HTML and CSS a further introduction

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

INTRODUCTION TO CSS. Mohammad Jawad Kadhim

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

2. Write style rules for how you d like certain elements to look.

Transcription:

CSS LINE-HEIGHT

What is leading?

Back in the good old days type was set by hand using printing presses.

Printed material was created by setting out letters in rows. Each letter was created on an individual block.

Leading, or lead strips were added between the lines of letters when additional vertical space was required.

In CSS, line-height is used to control the vertical space between lines.

However,the terms leading and half-leading are still used in association with CSS line-height.

So how do you apply line-height?

By default, browsers use between 1.0-1.2 line-height. This is referred to as an initial value.

You can override this default lineheight using the CSS line-height property. p { } line-height: 140%;

Line-height can be specified with five different types of unit.

1. Line-height can be specified as normal. body { line-height: normal; }

2. Line-height can be specified as inherit. p { } line-height: inherit;

3. Line-height can be specified using a percentage value. p { } line-height: 120%;

4. Line-height can be specified using a length value (using px, em etc). p { } line-height: 20px;

5. Line-height can also be specified using a number value (a unit-less value). p { } line-height: 1.2;

Shorthand line-height

These five line-height values can also be specified using the font shorthand property.

The line-height value is written in conjunction with the font-size value. The values are separated by a slash: <font-size>/<line-height> For example

Normal value body { font: 100%/normal arial, helvetica, sans-serif; }

Percentage value body { font: 100%/120% arial, helvetica, sans-serif; }

Length value body { font: 100%/20px arial, helvetica, sans-serif; }

Number value body { font: 100%/1.2 arial, helvetica, sans-serif; }

Calculating line-height

Some CSS properties are inherited (passed down to descendant elements).

This is designed to make it easier for authors - so they do not have to specify properties for all descendants.

EG. the color property is inherited. If a color is applied to the body element, it will be passed down to all other elements on the page.

For line-height, inheritance is a little more complicated...

To see the various line-height options in action, we will use the following HTML code: <h1> consect etuer adipi scing eli </h1> <p> Lorem ipsum dolor sit amet co </p> <div id="footer"> Duis autem vel eum iriure dol </div>

This produces the following document tree: body Parent element h1 p div#footer Descendant elements

We will also use the following CSS (pixels used for font-size to simplify - though not recommended!): body { } font-size: 16px; line-height: XXX; h1 { font-size: 32px; } p { font-size: 16px; } #footer { font-size: 12px; }

Example 1 The percentage value

The line-height has been set to a percentage value (120%). body { } font-size: 16px; line-height: 120%; h1 { font-size: 32px; } p { font-size: 16px; } #footer { font-size: 12px; }

The percentage value (120%) and the body element s font size (16px) are used to create a calculated value (16px x 120% = 19.2px). This calculated value is inherited by descendant elements.

All descendants, regardless of their size, receive the same calculated value line-height. element font-size line height calculated line-height body 16px 120% 16px x 120% = 19.2px h1 32px inherits calculated value - 19.2px 19.2px p 16px inherits calculated value - 19.2px 19.2px #footer 12px inherits calculated value - 19.2px 19.2px

The line-heights do not scale with the relevant font size. Too tight OK Too loose

Example 2 the length value

The line-height has been set using a length value (20px). body { } font-size: 16px; line-height: 20px; h1 { font-size: 32px; } p { font-size: 16px; } #footer { font-size: 12px; }

The length value (20px) is inherited by descendant elements.

All elements, regardless of their font-size, receive the same lineheight. element font-size line height calculated line-height body 16px 20px 20px h1 32px inherits 20px 20px p 16px inherits 20px 20px #footer 12px inherits 20px 20px

Again, the line-heights do not scale with the relevant font size. Too tight OK Too loose

Example 3 the normal value

The line-height has been set to normal (which is approx 1.2). body { } font-size: 16px; line-height: normal; h1 { font-size: 32px; } p { font-size: 16px; } #footer { font-size: 12px; }

In this case, the normal value rather than a calculated value is inherited by descendant elements. Browsers may interpret the actual normal value in slightly different ways.

All elements now have line-heights that are relative to their font-size. element font-size line height calculated line-height body 16px normal 16px x approx 1.2 = approx 19.2px h1 32px normal 32px x aprox 1.2 = approx 38.4px p 16px normal 16px x approx 1.2 = approx 19.2px #footer 12px normal 11.2px x approx 1.2 = approx 13.44px

Now, the line-heights scale with the relevant font size. OK OK OK

But what if you want the flexibility of the normal value, but to be able to specify the factor used? This is where number values come in.

Example 4 the number value

The line-height has been set to a number value (1.5). body { } font-size: 16px; line-height: 1.5; h1 { font-size: 32px; } p { font-size: 16px; } #footer { font-size: 12px; }

In this case, the factor (1.5) rather than a calculated value is inherited by descendant elements.

All elements now have line-heights that are relative to their font-size. element font-size line height calculated line-height body 16px 1.5 16px x 1.5 = 24px h1 32px factor of 1.5 32px x 1.5 = 48px p 16px factor of 1.5 16px x 1.5 = 24px #footer 12px factor of 1.5 12px x 1.5 = 18px

Again, the line-heights scale with the relevant font size. Too loose? OK OK

So, which is the best method?

Generally, a number value is the best method for setting line-height as line-heights will then always scale with the relevant font-size.

It is hard to determine a perfect line-height as each situation is different. However, it is safe to assume that headings can have less relative line-height than paragraphs of text.

For example, all content could be set to 1.5, and then headings redefined to 1.2. body { line-height: 1.5; } h1, h2, h3, h4, h5, h6 { line-height: 1.2; }

The Web Content Accessibility Guidelines (WCAG) 2.0 state: line spacing is at least spaceand-a-half within paragraphs. This means that to be AAA compliant, paragraph line-height should be set to 1.5 http://www.w3.org/tr/wcag20/ - 1.4.8 Visual Presentation

Looking deeper into line-height

In order to understand line-height more fully, we need to look at various types of CSS boxes.

Let s start with a simple piece of HTML code. <p> The <em>emphasis</em> element is defined as inline. </p>

The code should be rendered like this in most browsers. The emphasis element is defined as inline.

There are four types of boxes that are relevant in this sample.

Box type 1: containing boxes

The paragraph is referred to as a containing box in this case - as it contains other boxes. The emphasis element is defined as inline.

Box type 2: inline boxes

Inside the paragraph are a series of inline boxes. The emphasis element is defined as inline.

Inline boxes do not form new blocks of content; the content is distributed in lines.

The emphasis element is a type of inline box. The emphasis element is defined as inline.

Other boxes without specific markup are referred to as anonymous inline boxes. The emphasis element is defined as inline.

Box type 3: line boxes

Inline boxes sit side-by-side within the containing box, forming line boxes. Line boxes The emphasis element is defined as inline.

Box type 4: content area

The content area is the invisible box that surrounds the text. Its height is determined by the fontsize. Content area

Inline boxes and line-height

Line height is applied to inline boxes using a simple formula

1. Find the difference between the font-size and line-height. This will determine the leading. For example: Font-size: 16px Line-height: 20px Difference: 4px (leading)

2. Divide the leading in half to create a half-leading value. 4px leading / 2 = 2px half-leading

3. Apply this half-leading value to the top and bottom of the content area. 2px half-leading Content area 2px half-leading

But things sometimes become a little more complicated...

The inline box generally wraps around the content box. Halfleading sits above and below the content box. Inline box

However, the inline box can sometimes be smaller than the content area!

For example, if the line-height is smaller than the font size. In this case, the inline box will honor the line height. For example: Font-size: 16px Line-height: 12px Inline box size: 12px

The content area then pokes out the top and bottom of the inline box. The half-leading collapses together to form the inline box height. Inline box Content area Top half-leading Bottom half-leading

Some notes on line box height

The height of line boxes is determined by the tallest inline box (or replaced element) inside.

The tallest inline box could be an anonymous inline box. Line box

It could be an inline box with increased line-height. Line box Increased line-height

Or an inline box with a larger font-size. Line box Larger font

Or the presence of a superscript or subscript. Line box Superscript

Or even the presence of a replaced element, such as an image. Line box An inline image aligned to the baseline

Line boxes then stack on top of each other within the width of the containing box. Containing box Line box Line box

Some final notes

Superscript and subscript

The superscript and subscript elements can sometimes force the line box to be taller than normal. Line box Superscript

You can fix this by setting these elements to a line-height of 0 which will remove all half-leading from the element. sup, sub { line-height: 0; } Hat tip: www.velvetblues.com/

IE6, line-height and inline images

IE5/6 incorrectly removes the top half-leading when an inline image is present. Line box Top half-leading removed An inline image

This is a hard one to fix, but if needed, margin can be added to the top of the image to fake the half-leading. This additional margin should only be shown to IE5/6 (using conditional comments)

We re done!