CSS. Shan-Hung Wu CS, NTHU

Similar documents
CSS.

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

Cascading Style Sheets CSCI 311

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

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

Chapter 3 Style Sheets: CSS

Zen Garden. CSS Zen Garden

Parashar Technologies HTML Lecture Notes-4

CSS: Cascading Style Sheets

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

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

Cascading Style Sheets (CSS)

CSS. Selectors & Measurments. Copyright DevelopIntelligence LLC

Cascading Style Sheets Level 2

CSS Cascading Style Sheets

CSC309 Programming on the Web week 3: css, rwd

Web Engineering CSS. By Assistant Prof Malik M Ali

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

CSS: The Basics CISC 282 September 20, 2014

FLOATING AND POSITIONING

INTRODUCTION TO CSS. Mohammad Jawad Kadhim

Web Information System Design No.4 Put Style to Web Documents. Tatsuya Hagino

Unit 10 - Client Side Customisation of Web Pages. Week 5 Lesson 1 CSS - Selectors

Using CSS for page layout

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

Tutorial 4: Creating Special Effects with CSS

Adding CSS to your HTML

Website Development with HTML5, CSS and Bootstrap

the missing manual0 O'REILLY Third Edition David Sawyer McFarland Beijing Cambridge The book that should have been in the box Farnham

BIM222 Internet Programming

Certified CSS Designer VS-1028

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

ID1354 Internet Applications

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

ITNP43: HTML Lecture 4

PUBLISHER SPECIFIC CSS RULES

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

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

COMS 359: Interactive Media

Cascading Style Sheets (CSS)

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

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

Cascading Style Sheets

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

CSC309 Winter Lecture 2. Larry Zhang

CSS: Cascading Style Sheets

CS193X: Web Programming Fundamentals

To Ponder. Which one wins? .draft div.warning li { }.draft div #main li {!important; } div #main ul li { }.draft.warning ul li { }

Module 2 (VII): CSS [Part 4]

Chapter 4 CSS basics

Introduction to WEB PROGRAMMING

CSS Cont'd: Cascading Style Sheets

READSPEAKER ENTERPRISE HIGHLIGHTING 2.5

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

Creating a CSS driven menu system Part 1

Cascading Style Sheet

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

Let s start with the document tree

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

Block & Inline Elements

INFS 2150 Introduction to Web Development

12/9/2012. CSS Layout

INFS 2150 Introduction to Web Development

/* ========================================================================== PROJECT STYLES

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

NAVIGATION INSTRUCTIONS

Web Design and Development Tutorial 03

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

Creating Layouts Using CSS. Lesson 9

KillTest *KIJGT 3WCNKV[ $GVVGT 5GTXKEG Q&A NZZV ]]] QORRZKYZ IUS =K ULLKX LXKK [VJGZK YKX\OIK LUX UTK _KGX

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

Introduction to Web Design CSS Reference

APPLIED COMPUTING 1P01 Fluency with Technology

Introduction to Web Design CSS Reference

Creating and Building Websites

Building Page Layouts

Taking Fireworks Template and Applying it to Dreamweaver

Client-Side Web Technologies. CSS Part I

Client-Side Web Technologies. CSS Part II

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

Cascading Style Sheet Quick Reference

Deccansoft Software Services

CSS Cascading Style Sheets

Using Dreamweaver to Create Page Layouts

HTML and CSS a further introduction

CMPT 165 Advanced XHTML & CSS Part 3

Introduction to Computer Science Web Development

HTML and CSS COURSE SYLLABUS

CSS: Layout Part 2. clear. CSS for layout and formatting: clear

CSS 1: Introduction. Chapter 3

2005 WebGUI Users Conference

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

HTML + CSS. ScottyLabs WDW. Overview HTML Tags CSS Properties Resources

Web Site Design and Development Lecture 5

Study Guide 2 - HTML and CSS - Chap. 6,8,10,11,12 Name - Alexia Bernardo

Appendix D CSS Properties and Values

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

INTRODUCTION TO CSS. Topics MODULE 5

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

Transcription:

CSS Shan-Hung Wu CS, NTHU

CSS Zen Garden 2

Outline The Basics Selectors Layout Stacking Order 3

Outline The Basics Selectors Layout Stacking Order 4

Grammar selector { property: value; 5

Example /* for all h1's */ h1 { color: red; font-size: 56px; /* for all img's */ img { border-color: blue; border-width: 3px; 6

Color & Background h1 { color: #4b0082; background: #95a5a6; color: #fff; /* same as #ffffff */ /* alpha specifies opacity */ color: rgba(11, 99, 150, 0.3); 7

More Background Properties body { background: #000 /* color */ url("img.png") /* image */ no-repeat /* repeat */ fixed /*attachment */ right top; /*position */ CSS3 body { background-size: cover; 8

CSS Properties Background: E.g., background-color, background-image, etc. Text: E.g., color, text-align, text-decoration, etc. Font: E.g., font-family, font-size, font-style, font-weight, etc. List & table: E.g., list-style-type, list-style-image, vertical-align, etc. Layout: E.g., width, height, border, padding, margin, display, visibility, float, position, etc. See a list here 9

Native Font Stack body { font-family: /* Safari for OS X and ios */ -apple-system, /* Chrome >= 56 for OS X, Windows, Linux and Android */ system-ui, /* Chrome < 56 for OS X */ BlinkMacSystemFont, /* Windows */ "Segoe UI", /* Android */ "Roboto", /* Basic web fallback */ "Helvetica Neue", Arial, sans-serif; 10

Google Fonts 11

Outline The Basics Selectors Layout Stacking Order 12

Selectors <ul id="todo-list"> <li class="done">todo 1</li> <li>todo 2</li> <li class="done">todo 3</li> </ul> li { /* element/tag selector */ font-weight: bold; #todo-list { /* ID selector */ background-color: gray;.done { /* class selector */ text-decoration: line-through; 13

Chrome Inspector 14

More Selectors /* composition */ #todo-list, li.done {... /* descendant selector */ li a {... /* adjacent selector */ li.done + li {... /* attribute selector */ a[href="http://www.example.com"] {... 15

Pseudo Classes & Elements /* pseudo class selector */ a:hover, a:visited {... li:nth-of-type(3) {... /* pseudo element selector */ p::first-latter { font-size: 200%; h1::before { content: url(image.gif); More selector examples 16

Inheritance Most style properties of an element will be inherited by its descendants E.g., font, color, text-align, etc. Common exceptions are those related to the box model E.g., height, width, border-width, etc. Check this reference to see if a property is inheritable 17

Cascading Final properties gotten by an element are cascaded from all applicable rules <body> <ul id="todo-list"> <li>...</li> <li class="done"> TODO </li> </ul> </body> body { color: gray; #todo-list { font-weight: bold; #todo-list li { color: red; li.done { text-decoration: line-through; 18

How to Resolve Conflicts? 1. By importance 2. By specificity body { color: gray!important; Example # ID Selectors # Class Selectors # Type Selectors ul 0 0 1 ul li.done 0 1 2 #sec-2 ul li (wins) 1 0 2 3. By source order Rules written later win More about cascade and inheritance 19

Outline The Basics Selectors Layout Stacking Order 20

HTML Rendering The content are rendered following the normal flow Block elements are laid out vertically Inline elements are laid out horizontally 21

Box Model Each element is rendered as a box: CSS3 Box Sizing 'width' 22

Inline and Block Elements If an inline box wraps into multiple lines, you cannot set its width Not the case for <input> and <img> Inline boxes reserve space for descender chars, e.g., g <img> is an inline element by default There is (unwanted) space between its bottom border and container 23

Hiding Elements Method 1: visibility:hidden Still occupies space in normal flow Method 2: display:none Removed from normal flow 24

Centering Text/Elements How to center text/inline elements inside a block element? Add text-align:center to the block How to center text in an inline element? There is no such an issue How to center a block element inside another? 1. Give inner block a width (otherwise we don t have this issue) 2. Add margin-left:auto and marginright:auto to inner block 25

Margin Collapsing Adjacent margins collapse between Sibling elements Parent and first/last child 26

Relative Widths and Heights div { width: 70%; max-width: 640px; font-size: 16px; It's a good practice to use em and rem html{ font-size: 16px; div { width: 70%; max-width: 40rem; font-size: 1rem; 27

CSS3 Box Sizing div { width: 50%; padding: 1rem; border: 0.25rem solid blue; Box sizing in CSS 3: * { /* border & padding count into width & height */ box-sizing: border-box; 28

Positioning Not positioned: static (in normal flow) div { position: relative; /* in normal flow */ top: 8px; /* offset from static position */ left: 8px; div { position: absolute; /* removed from normal flow */ top: 8px; /* offset from positioned ancestor */ div { position: fixed; /* removed from normal flow */ top: 8px; /* offset from browser window */ 29

Floats.elem { float: left;.container::after { content: ''; display: block; clear: both; Removed from normal flow and stick to the left/right-most side of its container Unless specified, width and height shrink to fit the content 30

Demo: Photo Gallery 31

Outline The Basics Selectors Layout Stacking Order 32

Overlapping Elements Elements may overlap <div id="1">...</div> <div id="2">...</div> <div id="3">...</div> <div id="4">...</div> <div id="5">...</div> Which one shows on top? 33

Stacking Order (Bottom to Top) 1. Background and borders of <html> 2. Descendant blocks in normal flow (in HTML order) 3. Floating blocks 4. Inline descendants in the normal flow 5. Descendant positioned elements (in HTML order) 34

Z-Index Default: 0 Stacking order applies to each layer Elements need to be positioned to take effect 35

How about the order of descendants? 36

Stacking Context <html>, positioned, and non-full opacity elements creates stacking contexts Z-index is local to a stacking context <div id="1"> <div id="2"> <div id="3"> <div id="4"> <div id="5"> <div id="6"> 37

Assigned Readings CSS tutorial 38

Exercise 39