Building a Website: Cascading Style Sheets (CSS) Fall 2013.

Slides:



Advertisements
Similar presentations
Dr. Alexandra I. Cristea CSS Dr. Alexandra I. Cristea Source:
Advertisements

CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
CSS. CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to solve a problem External Style.
Web Engineering 1 Ishaq Khan Shinwari MCS City University Peshawar.
Computer Applications II.  A Style Sheet is a web page development tool that allows the developer to make global changes to a web page (or web site)
Cascading Style Sheets
Cascading Style Sheets
Cascading Style Sheets
Today CSS HTML A project.
CSS CSS stands for Cascading Style Sheets Styles define how to display HTML elements External Style Sheets can save a lot of work External Style Sheets.
Introduction to CSS.
Cascading Style Sheets. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
Cascading Style Sheets By: Valerie Kuna. What are Cascading Style Sheets? Cascading Style Sheets (CSS) are a standard for specifying the presentation.
1 Web Developer & Design Foundations with XHTML Chapter 9 Key Concepts.
Client-Side Internet and Web Programming
1 Pengantar Teknologi Internet W03: CSS Cascading Style Sheets.
CSS(Cascading Style Sheets )
1 Dreamweaver CS5 intermediate class by Cookie Setton Build a CSS website WITHOUT TABLES Just when you thought you were starting to understand HTML coding,
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
Part 3 Introduction to CSS. CSS Text Text Styles h1 {color: green} // rgb(0,255,0), #00ff00 h2{letter-spacing: 0.5cm} // 2px h3 {text-align: right} //
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
Measurement Many CSS properties (values within the declaration) require that you specify a unit of measurement, such as spacing between elements, border.
Chapter 8 Creating Style Sheets.
CSS normally control the html elements. Three Ways to Insert CSS There are three ways of inserting a style sheet: External style sheet Internal style.
CSS Cascading Style Sheets Brief Introduction
Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design.
4.01 Cascading Style Sheets
Review HTML  What is HTML?  HTML is a language for describing web pages.  HTML stands for Hyper Text Markup Language  HTML is not a programming language,
1Computer Sciences Department. And use
Tutorial #3 Cascading Style Sheets. Review: Last Class Image sizing Pathnames Project Default Path Relative Path Absolute Path Blackboard Homework Submission.
1 What is CSS?  CSS stands for Cascading Style Sheets  Styles define how to display HTML elements  Styles are normally stored in Style Sheets  Styles.
(CSS) More Details Instructor: Mr. Ahmed Al Astal ITGD4104 Department Requirement for senior student University of Palestine Faculty of IT.
To Proudly supported by ferrycake.com. We will be printing Cash for your Community tokens every week in the Carmarthen Journal and Llanelli Star. The.
ITCS373: Internet Technology Week 3: Introduction to CSS Dr. Faisal Al-Qaed.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
Tutorial #3 Cascading Style Sheets. Tutorial #2 Review - Anchors Links to Site DMACC Internal Links Go to Top Mail To me Local.
CSS Basic (cascading style sheets)
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
Cascade Style Sheet Introduction. What is CSS?  CSS stands for Cascading Style Sheets  Styles define how to display HTML elements  Styles were added.
Web Design and Development for Business Lecture 4 Cascading Style Sheet (CSS)
CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles.
DIV, Span, CSS.
3. Cascading Style Sheets (CSS) M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer.
Cascading Style Sheets CSS. Source W3Schools
How to… Cascading Style Sheets. How to Insert a Style Sheet When a browser reads a style sheet, it will format the document according to it. There are.
1 CSS محمد احمدی نیا 2 Of 21 What is CSS?  CSS stands for Cascading Style Sheets  Styles define how to display HTML elements 
Blended HTML and CSS Fundamentals 3 rd EDITION Tutorial 3 Introducing Cascading Style Sheets.
CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to solve a problem External.
1 Cascading Style Sheets
WebD Introduction to CSS By Manik Rastogi.
CSS.
Cascading Style Sheet.
HTML WITH CSS.
CSS: Cascading Style Sheets
4.01 Cascading Style Sheets
( Cascading style sheet )
Introduction to the Internet
Cascading Style Sheets (Formatting)
Cascading Style Sheet (CSS)
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Website Design 3
CSS Style Sheets: Intro
Cascading Style Sheets Color and Font Properties
محمد احمدی نیا CSS محمد احمدی نیا
What are Cascading Stylesheets (CSS)?
Tutorial 3 Working with Cascading Style Sheets
Cascading Style sheet. What is CSS?  CSS stands for Cascading Style Sheets  Cascading: refers to the procedure that determines which style will apply.
Cascading Style Sheets
4.01 Cascading Style Sheets
Introduction to Cascading Style Sheets (CSS)
Presentation transcript:

Building a Website: Cascading Style Sheets (CSS) Fall 2013

Cascading Style Sheets CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to solve a problem External Style Sheets can save a lot of work External Style Sheets are stored in CSS files Allows much greater control over the layout and design of Web pages. – Add margins to paragraphs – Colorful and stylish borders to images – Dynamic rollover effects to text links Difficult design concepts to grasp

Styles Solved a Big Problem HTML was never intended to contain tags for formatting a document. – HTML was intended to define the content of a document, like: This is a heading This is a paragraph. Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process. To solve this problem, the World Wide Web Consortium (W3C) created CSS. In HTML 4.0, all formatting could be removed from the HTML document, and stored in a separate CSS file. All browsers support CSS today.

CSS Basics A style is a rule describing how to format a particular piece of HTML A style sheet is a set of these canned styles Create style to format text with the font Arial, colored red, with a left margin 50 pixels Create a style to work with images – Align an image along the right edge of a Web page, surround the image with a colorful border, and place a 50 pixel margin between the image and the surrounding text Can apply a style to text, images, or other elements on a page

CSS Help Dreamweaver’s built-in Reference window

CSS Example body { background-color:#d0e4fe; } h1 { color:orange; text-align:center; } p { font-family:"Times New Roman"; font-size:20px; }

CSS Syntax A CSS rule has two main parts: a selector, and one or more declarations: The selector is normally the HTML element you want to style. Each declaration consists of a property and a value. The property is the style attribute you want to change. Each property has a value. See cssExample.html

CSS Comments Comments are used to explain your code, and may help you when you edit the source code at a later date. Comments are ignored by browsers. A CSS comment begins with "/*", and ends with "*/", like this: /*This is a comment*/ p { text-align:center; /*This is another comment*/ color:black; font-family:arial; }

CSS Id and Class In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called "id" and "class". – The id selector is used to specify a style for a single, unique element. – The id selector uses the id attribute of the HTML element, and is defined with a "#". – The style rule below will be applied to the element with id="para1": #para1 { text-align:center; color:red; }

CSS Id and Class The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements. – This allows you to set a particular style for many HTML elements with the same class. – The class selector uses the HTML class attribute, and is defined with a "." – In the example below, all HTML elements with class="center" will be center-aligned:.center {text-align:center;}

Inserting Style Sheets Three ways 1. External style sheet Used to apply style to many pages Change look of entire web site by just changing one CSS Can be written using any text editor File should not contain any html tags Save file with.css extension Example style sheet file hr {color:sienna;} p {margin-left:20px;} body {background-image:url("images/back40.gif");}

Inserting Style Sheets Three ways 2. Internal style sheet Used when single document has a unique style Define internal styles in the head section of an HTML page by using tab, like this: hr {color:sienna;} p {margin-left:20px;} body {background-image:url("images/back40.gif");}

Inserting Style Sheets Three ways 3. Inline style Looses many advantages of style sheets Mixes content with presentation Used sparingly Use the style attribute in the relevant tag. The style attribute can contain any CSS property, for example: This is a paragraph.

Multiple Style Sheets If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet. h3 { color:red; text-align:left; font-size:8pt; } h3 { text-align:right; font-size:20pt; } color:red; text-align:right; font-size:20pt External InternalActual Properties for h3 The color is inherited from the external style sheet and the text-alignment and the font-size is replaced by the internal style sheet.

Multiple Style Sheets Cascading order – What style will be used when there is more than one style specified for an HTML element? – Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number four has the highest priority: 1.Browser default 2.External style sheet 3.Internal style sheet (in the head section) 4.Inline style (inside an HTML element) So, an inline style (inside an HTML element) has the highest priority, which means that it will override a style defined inside the tag, or in an external style sheet, or in a browser (a default value).

CSS Background CSS background properties are used to define the background effects of an element. CSS properties used for background effects: – background-color – background-image – background-repeat – background-attachment – background-position

Background Color The background-color property specifies the background color of an element. The background color of a page is defined in the body selector: – body {background-color:#b0c4de;} With CSS, a color is most often specified by: – a HEX value - like "#ff0000" – an RGB value - like "rgb(255,0,0)" – a color name - like "red“ Example, h1, p and div elements have different background colors h1 {background-color:#6495ed;} p {background-color:#e0ffff;} div {background-color:#b0c4de;}

Background Image The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element. The background image for a page can be set like this: – body {background-image:url('paper.gif');} Be careful using background images – May make text hard to read

Background Images When using the shorthand property the order of the property values is: – background-color – background-image – background-repeat – background-attachment – background-position

Text Formatting Text Color – Used to set color of text – Specify color with a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red“ Text Alignment – Set horizontal alignment of text Centered, left, right, justified – Example h1 {text-align:center;} p.date {text-align:right;} p.main {text-align:justify;}

Text Formatting (cont.) Text Decoration – Set or remove decorations from text – Used to remove underlines from links – Example a {text-decoration:none;} – Used to decorate text – Examples h1 {text-decoration:overline;} h2 {text-decoration:line-through;} h3 {text-decoration:underline;} h4 {text-decoration:blink;} Text Transformation – Used to specify uppercase and lowercase letters in a text – Used to turn everything into uppercase or lowercase, or capitalize first letter of each word – Examples p.uppercase {text-transform:uppercase;} p.lowercase {text-transform:lowercase;} p.capitalize {text-transform:capitalize;}

Text Formatting (cont.) Text Indention – Used to specify the indention of the first line of a text – Example p {text-indent:50px;} Specify space before characters – Example h1 {letter-spacing:2px;} h2 {letter-spacing:-3px;} Specify space between lines – Example p.small {line-height:70%;} p.big {line-height:200%;} Set text direction – Example div.ex1 {direction:rtl;} Increase white space between words – Example P {word-spacing:30px;}

Text Formatting (cont.) Disable Text Wrapping – Example p {white-space:nowrap;} Vertical Alignment of an image – Example img.top {vertical-align:text-top;} img.bottom {vertical-align:text-bottom;}

Font Families Font Family – Set the font-family property – Should hold several font names as a “fallback” system. – Start with font you want, than second choice, etc – If name is more than one word it must be in quotes – Example p{font-family:"Times New Roman", Times, serif;}

Font Style – Used to specify italic text – Three values for property Normal – text is shown normally Italic – text is shown in italics Oblique – text is leaning (oblique is very similar to italic, but less supported – Example p.normal {font-style:normal;} p.italic {font-style:italic;} p.oblique {font-style:oblique;}

Font Size – Font size with pixels – Examples h1 {font-size:40px;} h2 {font-size:30px;} p {font-size:14px;} – Font size with EM Used to avoid resizing problems with older versions of IE Recommended by W3C 1 em equal to current font size. Default text size ii browsers is 16 px Formula for pixels to em: em = pixels/16 – Examples h1 {font-size:2.5em;} /* 40px/16=2.5em */ h2 {font-size:1.875em;} /* 30px/16=1.875em */ p {font-size:0.875em;} /* 14px/16=0.875em */

Font Size (cont.) Font Size – Sets size of font – Should not use size to make paragraphs look like header and headers look like paragraphs – Always use proper tags, like - for headers and for paragraphs – Font size can absolute or relative Absolute size – Sets the text to a specified size – Does not allow a user to change the text size in all browsers (bad for accessibility reasons) – Absolute size is useful when the physical size of the output is known Relative size – Sets the size relative to surrounding elements – Allows a user to change the text size in browsers

Links Styling Links – Set color, font-family, background, etc – Can be styled depending on sites visited – Four link states a:link - a normal, unvisited link a:visited - a link the user has visited a:hover - a link when the user mouses over it a:active - a link the moment it is clicke – Examples a:link {color:#FF0000;} /* unvisited link */ a:visited {color:#00FF00;} /* visited link */ a:hover {color:#FF00FF;} /* mouse over link */ a:active {color:#0000FF;} /* selected link */ – Order rules a:hover MUST come after a:link and a:visited a:active MUST come after a:hover

Links (cont.) Text Decoration – Remove undelines – Examples a:link {text-decoration:none;} a:visited {text-decoration:none;} a:hover {text-decoration:underline;} a:active {text-decoration:underline;} Background Color – Background color for links – Examples a:link {background-color:#B2FF99;} a:visited {background-color:#FFFF85;} a:hover {background-color:#FF704D;} a:active {background-color:#FF704D;} See example linksStyle.html

Lists CSS list properties allow you to – Set different list item markers for ordered lists – Set different list item markers for unordered lists – Set an image as the list item marker Two types of lists – Unordered lists – marked with bullets – Ordered lists – marked with numbers or letters – Examples ul.a {list-style-type: circle;} ul.b {list-style-type: square;} ol.c {list-style-type: upper-roman;} ol.d {list-style-type: lower-alpha;}

Lists (cont.) Images as List Item Marker – Use list-style-image property – Example ul { list-style-image: url('sqpurple.gif'); }

Lists (cont.) Crossbrowser Solutions – Display image-marker equally in all browsers – Example ul { list-style-type: none; padding: 0px; margin: 0px; } ul li { background-image: url(sqpurple.gif); background-repeat: no-repeat; background-position: 0px 5px; padding-left: 14px; } Example Explained – For ul: Set the list-style-type to none to remove the list item marker Set both padding and margin to 0px (for cross-browser compatibility) – For all li in ul: Set the URL of the image, and show it only once (no-repeat) Position the image where you want it (left 0px and down 5px) Position the text in the list with padding-left

CSS Tables The look of an HTML table can be greatly improved with CSS Table Borders – Use border properties – Example (black border for th and td elements table, th, td { border: 1px solid black; } – This produces two borders, one for th and one for td Use Collapse Borders to remove one of the borders – table { border-collapse:collapse; } table,th, td { border: 1px solid black; }

CSS Tables (cont.) Table Width and Height table { width:100%; } th { height:50px; } Table Horizontal Text Alignment td { text-align:right; } Table Vertical Text Alignment td { height:50px; vertical-align:bottom; }

CSS Tables (cont.) Table Padding – Spaces between border and content td { padding:15px; } Table Color – Color of borders, and the text and background color of th elements table, td, th { border:1px solid green; } th { background-color:green; color:white; }