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

Similar documents
CSS Styles Quick Reference Guide

Appendix D CSS Properties and Values

BIM222 Internet Programming

CSS Cascading Style Sheets

CSS: The Basics CISC 282 September 20, 2014

CSS.

Parashar Technologies HTML Lecture Notes-4

Cascading Style Sheets CSCI 311

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

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

Introduction to Web Design CSS Reference

Introduction to Web Design CSS Reference

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

Client-Side Web Technologies. CSS Part II

Adding CSS to your HTML

Cascading Style Sheet Quick Reference

Cascading Style Sheets (CSS)

Zen Garden. CSS Zen Garden

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

IMY 110 Theme 6 Cascading Style Sheets

CSS Box Model. Cascading Style Sheets

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

Cascade Stylesheets (CSS)

CASCADING STYLESHEETS

CSC Website Design, Spring CSS Flexible Box

COSC 2206 Internet Tools. CSS Cascading Style Sheets

CSC309 Programming on the Web week 3: css, rwd

<body bgcolor=" " fgcolor=" " link=" " vlink=" " alink=" "> These body attributes have now been deprecated, and should not be used in XHTML.

CSS. Shan-Hung Wu CS, NTHU

UNIVERSITI TEKNOLOGI MALAYSIA TEST 1 SEMESTER II 2012/2013

INFS 2150 Introduction to Web Development

INFS 2150 Introduction to Web Development

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

Chapter 3 Style Sheets: CSS

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

Web Design and Development Tutorial 03

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

CSS: Cascading Style Sheets

8a. Cascading Style Sheet

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

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

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

Web Engineering CSS. By Assistant Prof Malik M Ali

CSS. Selectors & Measurments. Copyright DevelopIntelligence LLC

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

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

Controlling Appearance the Old Way

Creating and Building Websites

Cascading Style Sheets

Cascading Style Sheets. Overview and Basic use of CSS

Table of Contents. MySource Matrix Content Types Manual

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

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

CSS Tutorial Part 1: Introduction: A. Adding Style to a Web Page (3 options):

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

HTML Summary. All of the following are containers. Structure. Italics Bold. Line Break. Horizontal Rule. Non-break (hard) space.

**Method 3** By attaching a style sheet to your web page, and then placing all your styles in that new style sheet.


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

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

Reading 2.2 Cascading Style Sheets

ID1354 Internet Applications

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

Web Design and Implementation

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

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

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

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

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

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

Chapter 4 CSS basics

CMPT 165: More CSS Basics

HTML/XML. HTML Continued Introduction to CSS

Introduction to CSS (CSS2) Cascading Style Sheets. CSS Example. CSS Rules

CSS: Formatting Text. CSS for text processing: font-family. Robert A. Fulkerson

Building Page Layouts

The building block of a CSS stylesheet. A rule consists of a selector and a declaration block (one or more declarations).

Web Site Design and Development Lecture 6

APPLIED COMPUTING 1P01 Fluency with Technology

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

Block & Inline Elements

Cascading Style Sheets Level 2

3. Each of these mark examples contains an error. a. <input name= country value= Your country here. /> b. <checkbox name= color value= teal />

ICT IGCSE Practical Revision Presentation Web Authoring

Creating Layouts Using CSS. Lesson 9

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

Styles, Style Sheets, the Box Model and Liquid Layout

Assignments (4) Assessment as per Schedule (2)

CSS FOUNDATIONS IN-DEPTH. The nitty-gritty of css...

Internet Programming 1 ITG 212 / A

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

Web Site Design and Development Lecture 5

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

CSS Cascading Style Sheets

2005 WebGUI Users Conference

INFORMATICA GENERALE 2014/2015 LINGUAGGI DI MARKUP CSS

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

Tutorial 3: Working with Cascading Style Sheets

Transcription:

CSS Selectors Patterns used to select elements to style. CSS selectors refer either to a class, an id, an HTML element, or some combination thereof, followed by a list of styling declarations. Selectors can override each other going from least to most specific, element < class < id < inline. element selectors Styles elements of a certain type, such as paragraphs or headings. p { background-color : yellow ; < p > Applies to all paragraph elements. < /p >.class selectors Styles elements with a class attribute. Elements can be given multiple classes, and classes can be used throughout the page to style similar elements..intro { color : #00ff00 ; background-color : #e6e6e6 ; < p class ="intro" > paragraph with class of intro < /p > #id selectors Styles the element with the specified id. Ids should be unique with each id only assigned to one element on the page. #firstname { color : rgb(255, 255, 0) ; < div id ="firstname" > Oscar < /div >

Inline Style Elements can also be styled with an inline style attribute My mother has < span style ="color:blue"> blue < /span > eyes. Combining CSS Selectors Elements with Multiple Classes Elements can have multiple classes to apply various properties..center { text-align : center ;.dark { background-color : #1a1a1a ; color : #cccccc ; < div class ="center dark" > The content is centered with a dark background and grey text. < /div > Element and Class Selectors Elements and class selectors can be combined to make a more specific rule..blue { color : #0000ff ; h1.blue { background-color : #0000ff ; color : #ffffff ; < h1 class ="blue" > Background color is blue. < /h1 > < p > Paragraph with a < strong class ="blue" >blue< /strong > word. < /p >

CSS Descendant Selectors The descendant selector matches all elements that are descendants of a specified element. div.container p { background-color : yellow ; < div class ="container" > < div > < h1 > The Title < /h1 > < p > Paragraphs inside div.container have a yellow background. < /p > < /div > < /div > CSS Child Selectors The child selector selects all elements that are the immediate children of a specified element. div > h1 { background-color : yellow ; < div > < h1 > Immediate Child Has a Yellow Background < /h1 > < div > < h1 > Child Selector Doesn t Apply To Further Descendents < /h1 > < /div > < /div > CSS Adjacent Sibling Selectors Adjacent sibling selector selects all elements that are the adjacent sibling of a specified element. h1 + p { background-color : yellow ; < h1 > The Title < /h1 > < p > Paragraphs immediately after an h1 have a yellow background. < /p > < p > But this one isn t yellow because it s not adjacent. < /p >

CSS Grouped Selectors To style several things with the same style, separate each one with a comma. Comma groups can also be used with groups of classes, pseudo classes or other types of combined selectors. h1, h2 { background-color : yellow ; < h1 > Yellow Background < /h1 > < h2 > Also Yellow! < /h2 > CSS Specificity Every selector has its place in the specificity hierarchy. The browser calculates a specificity level or score for each rule. If selectors have equal specificity, the latest rule counts. There are four categories which define the specificity level of a selector: Inline styles Inline styles are more specific than ids or classes. IDs ID selectors have a higher specificity than class or attribute selectors. Classes, attributes and pseudo-classes A class selector beats any number of element selectors. Elements Element selectors are the least specific. Specificity Score Add 1000 for inline style Add 100 for ID Add 10 for class, attribute, or pseudo-class Add 1 for each element

CSS Pseudo Selectors Anchor(link) Pseudo-classes Style links based on their state. :visited Selects links on the page the user has already visited. Most browsers default this to purple. a:visited { color : red ; :link Selects links on the page the user has not visited yet. Most browsers default this to blue. a:link { color : orange ; :active Selects links on the page the user has not visited yet. Apply the a:active, a:hover, a:focus pseudo classes to change links when they are being interacted with. a:link { color : red ; :hover Selects elements when the user is mousing over them. Can be used on many element types. a:hover { background-color : red ; color : white ; :focus Selects elements when they have focus (by keyboard input or other means.) Should be applied to the same elements as :hover for non-mouse users. a:focus { background-color : red ; color : white ;

font-family Specifies the font, can hold several font names as a fallback. The generic font names are sans-serif, serif, fantasy, monospace, and cursive. body { font-family : "Times New Roman", serif ; font-size Sets the font size, in pixels, percentage, or relative sizing. body { font-size : 12px ; h1 { font-size : 2em ; font-weight Sets characters to degrees of thickness. 400 is normal, and 700 is the same as bold. h1 { font-weight : bold ; h2 { font-weight : 700 ; font-style Can be used to sets the font style to italic or normal. p { font-style : italic ;

text-decoration Decoration added to text h3 { text-decoration : underline ; a { text-decoration : none ; text-align Sets the horizontal alignment of text in an element..username { text-align : right ; line-height Sets the height of a line in pixels, percentage, or relative sizing h1 { line-height : 24px ; CSS comments /* this is a comment */.intro { /* comments can contain text or commented out code color: #f0f0f0; */ background-color : rgb(100, 0, 200) ;

width and height Set the width and/or height of an element. Values are a percent or a number followed by a length unit, like 100% or 200px. img { width : 100% ; div { height : 200px ; overflow overflow-x (horizontal) overflow-y (vertical) When content overflows its box, specify whether it should be hidden or to add scrollbars when an element's content is too big to fit. If setting overflow to anything other than it s default value of visible, use auto to only show the scrollbars when the content does actually overflow, and only set overflow in the direction where you expect a user to scroll. Avoid scrollbars within scrollbars. visible hidden scroll auto default, content may flow outside its box content is clipped, no scrolling content is clipped, scrollbars always show clipped with scrollbars only if it overflows p { height : 200px ; overflow-y : auto ;

CSS box model margin margin-top margin-right margin-bottom margin-left Margin is the transparent area around the box that separates the box from other elements. Can also be applied individually to the top, left, bottom, or right margins. border (shorthand) border-width border-style border-color border-top border-right border-bottom border-left Sets the border width, style, and color. Can also be applied individually to border-style, border-width, border-color, or to the top, left, bottom, or right borders. Border style options are none, dotted, dashed, solid, double, groove, ridge, inset, or outset. padding padding-top padding-right padding-bottom padding-left Padding is the space between the border and the content. Can also be applied individually to the top, left, bottom, or right padding. div { margin : 40px ; padding : 20px ; border : 5px solid red ;

background-image Sets a background image for an element. It s a good idea to always set a background-color as well to be used in case the image is unavailable. By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally. Set the background-position, background-size, and background-repeat to tile, stretch, or fit the background image to the element as desired. background-position Sets the starting position of a background image. xpos can be left, right, center, or a CSS unit like 50% or 20px ypos can be top, bottom, center, or a CSS unit like 50% or 20px background-repeat Sets if/how a background image will be repeated. background-repeat: repeat; (default) image is repeated both ways background-repeat: repeat-x; image is repeated horizontally background-repeat: repeat-y; image is repeated vertically background-repeat: no-repeat; background-size image is not repeated Specifies the size of the background images using keywords auto, cover, or contain or with CSS width and height units like 50% or 200px background-size: auto; background-size: cover; background-size: contain; background-size: 50% 50%; background-size: 50px; (default) image is shown in its original size resized, stretched, clipped to cover the container resized to fit the container but not stretched to fill it resized to 50% of the width and height width is 50px and height is auto body { background-image : url('image.gif') ; background-color : #f0f0f0 ; background-position : center ; background-repeat : no-repeat ; background-size : contain ;

position Specifies whether elements should be positioned in the regular document flow or positioned relative to another element or the browser window. position: static; (default) normal position in order of document flow won t be an anchor point for positioned child elements position: relative; position: absolute; place element relative to normal position mostly used to anchor child absolute positioned elements place relative to page or to the first positioned parent put inside relative or absolute positioned parent element position: fixed; place element relative to the browser window doesn t move when the page is scrolled #parent { position : relative ; border : 1px solid blue ; width : 300px ; height : 100px ; #child { position : absolute ; border : 1px solid red ; top : 50% ; right : 10px ; < div id = "parent"> Parent - position: relative < div id = "child"> Child - position: absolute </ div > </ div > z-index Specifies the stack order of an element. Only works on positioned elements. Elements with a higher stack order are placed in front of elements with a lower stack order..menu { position : absolute ; left : 0px ; top : 0px ; z-index : 5 ;

CSS Flexbox display: flex Defines a flex container and enables a flex context for all its direct children or flex items. flex-direction Defines the direction flex items are placed in the flex container. Aside from optional wrapping, Flexbox is a tool for single-direction layouts. Flex items are laid out either in horizontal rows or vertical columns. flex-direction: row; flex-direction: row-reverse; flex-direction: column; flex-direction: column-reverse; (default) items laid out horizontally left to right flex items laid out horizontally right to left flex items laid out vertically top to bottom flex items laid out vertically bottom to top flex-wrap Flex items try to fit in one line by default, but items can wrap to multiple lines with this property. flex-wrap: nowrap; flex-wrap: wrap; (default) flex items will be in one line flex items can wrap to multiple lines top to bottom flex-wrap: wrap-reverse; flex items can wrap to multiple lines bottom to top justify-content Defines how items are laid out along the main axis, which by default is the horizontal axis when the flex-direction is row. justify-content: flex-start; justify-content: flex-end; justify-content: center; (default) flex items are packed towards the start flex items are packed towards the end center flex items in the main axis justify-content: distributed evenly from start to end space-between; justify-content: space-around; distributed with space at the start and end justify-content: space-evenly; like space-around but with equal space at the start and end align-items Defines how items are laid out across the cross axis, which by default is the vertical axis. align-items: flex-start; (default) aligned to start (top by default) of container align-items: flex-end; align-items: center; align-items: baseline; align-items: stretch; flex items aligned to end (bottom by default) or container center flex items in the cross axis (vertical by default) align flex items by their content baseline stretch flex items to fill the container