Cascading Style Sheet: Nazia Hameed Comsats Institute of Information Technology Islamabad
Cascading Style Sheet: Nazia Hameed Comsats Institute of Information Technology Islamabad
Cascading Style Sheet: Nazia Hameed Comsats Institute of Information Technology Islamabad
Goals
Understand basic syntax of Cascading Style Sheets (CSS) Understand the differences among inline, internal and external style sheets Understand how to declare a style Understand how to attach specify values
Problem
When tags like <font>, and color attributes were added to the HTML, it started a nightmare for web developers. Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process. Solution??????????
CSS SYNTAX
Rule Structure
Example
<html> <head> <title> CSS Example </title> <style type="text/css"> p { color:red; text-align:center; } </style> </head> <body> <p>Hello World!</p> <p>This paragraph is styled with CSS.</p> </body> </html>
OUTPUT
CSS Properties
CSS styles are created with two parts separated by a colon: the property, which refers to a specific CSS style, and the value assigned to it, which determines the styles visual characteristics Together, a CSS property and the value assigned to it are referred to as a declaration or style declaration
CSS Properties
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; }
The id Selector
Output
<html> <head> <style type="text/css"> #para1 { text-align:center; color:red; } </style> </head> <body> <p id="para1">Hello World!</p> <p>This paragraph is not affected by the style.</p> </body> </html>
Class Selector
<html> <head> <style type="text/css"> .center { text-align:center; } </style> </head> <body> <h1 class="center">Center-aligned heading</h1> <p class="center">Center-aligned paragraph.</p> </body> </html> Output
Class Selector
You can also specify that only specific HTML elements should be affected by a class.
Inline Styles
The most basic method of applying styles is to use inline styles, which allow you to add style information to a single element in a document An inline style (inside an HTML element) has the highest priority, which means that it will override a style defined inside the <head> tag, or in an external style sheet.
Inline Styles
<html> <head> <title>Inline Styles</title> </head> <body> <p style="color:blue; font-weight:bold; fontsize:12pt">Common Greetings</p> <ul style="margin-top:-20px; font-size:10pt"> <li style="list-style-type:square">Hello</li> <li style="list-style-type:circle">Hi</li> <li style="list-style-type:disc">Howdy</li> </ul> </body> </html>
Make a separate css file. Two ways to connect your HTML documents to your CSS stylesheet Linking Importing. Linking <link> is a simple <link> to the stylesheet; the browser knows to get styles from the links target and apply them to each HTML page as it is loaded Importing By @import you can also import one or more CSS files into another
CSS Properties
The properties are grouped into the following categories:
Color and background properties Font properties Text properties Box properties Table properties
Assignment
Make your profile using HTML and use External styles sheet to make it appealing .
CSS Values
The values you can assign to a CSS property depend on what type of property it is Some properties can be assigned a range of values
CSS Values
For instance, you can assign any font name that is available on a users system to the font-family property For other properties, you must assign a value from a specific set of values
Length Units
Length units refer to the units of measure that you can use in a style declaration to determine the size or positioning of an element Whether a length unit is used for sizing or positioning depends on the property and the element to which it is assigned
Length Units
You assign a measurement value to a property by assigning the number that represents the measurement, immediately followed by the unit of measure
Length Units
CSS length units are either absolute or relative Absolute length units use an exact measurement to specify the size or placement of an element
Length Units
The following CSS length units are absolute:
cm (centimeters) in (inches) mm (millimeters) pc (picas) pt (points)
Length Units
Relative length units are preferred because they adjust properties according to screen size or user preferences The following CSS length units are relative:
em (em space) ex (x-height) px (pixels) %
Percentage Units
An alternative to relative length units is percentage units, which adjust properties relative to other values You assign a percentage unit value to a property by assigning a number that represents the percentage, immediately followed by the percent symbol (%)
Color Units
A color unit represents a color value that you can assign to a property You can assign a color unit to a property using any one of 16 color names defined in the CSS1 specification
Color Units
Color Units
Most graphical computer systems use the RGB color system for specifying colors You can also assign a color using the RGB color system
Why CSS?
Advantages to Workflow Cost Savings You WILL Be Cooler
Advantages of CSS
Workflow
Faster downloads Streamlined site maintenance Global control of design attributes