CSS in Web Design

Add to Favourites
Post to:

Description
With plain HTML you define the colors and sizes of text and tables throughout your pages. If you want to change a certain element you will therefore have to work your way through the document and change it. CSS do this easily.
So CSS is an excellent addition to plain HTML.

Comments
Presentation Transcript Presentation Transcript

Slide 1 : In the Name of Allâh, the Most Beneficent, the Most Merciful

Role of CSS in web page design : Role of CSS in web page design By: Ch. Muhammad Fiaz

What is CSS? : What is CSS? CSS stands for Cascading Style Sheets CSS is an extension to basic HTML that allows you to style your web pages. CSS is the sister technology to HTML that is used to display the web pages. 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

Why we need CSS : Why we need CSS With plain HTML you define the colors and sizes of text and tables throughout your pages. If you want to change a certain element you will therefore have to work your way through the document and change it.With CSS you define the colors and sizes in "styles". Then as you write your documents you refer to the styles. Therefore: if you change a certain style it will change the look of your entire site. so CSS is an excellent addition to plain HTML. Another big advantage is that CSS offers much more detailed attributes than plain HTML for defining the look and feel of your site.Finally, CSS can be written so the user will only need to download it once - in the external style sheet document. When surfing the rest of your site the CSS will be cached on the users computer, and therefore speed up the loading time.

Pre-requisite to understand CSS : Pre-requisite to understand CSS You have used HTML in the past You know the basic HTML tags and vocabulary. Birth of CSS 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.

But, when tags like , and color attributes were added to the HTML 3.2 specification, 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. 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.

How to use CSS : How to use CSS CSS can be used in three ways: inline. Internal external Mostly internal and external CSS are used in most cases.

In-line : In-line In-line styles are fed straight ( at the spot) into the HTML tags using the style attribute. They look something like this:

text

This will make that specific paragraph red. But, if you remember, the best-practice approach is that the HTML should be a stand-alone, presentation free document, and so in-line styles should be avoided wherever possible.

Internal : Internal Embedded, or internal styles are used for the whole page. Inside the head tags, the style tags surround all of the styles for the page. This would look something like this: CSS Example ... This will make all of the paragraphs in the page red and all of the links blue. Similarly to the in-line styles, we can keep the HTML and the CSS files separate

External : External External styles are used for the whole, multiple-page website. There is a separate CSS file, which will simply look something like:  p { color: red; }   a { color: blue; } If this file is saved as "web.css" then it can be linked to in the HTML like this:   CSS Example ...

CSS Syntax : CSS Syntax Now whatever it usage may be, once you know its basic syntax then you can use it any way easily. 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.

CSS Syntax : CSS Syntax

The id and class Selectors : The id and class Selectors 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 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": Example #para1{text-align:center;color:red;}

The class Selector : The class Selector 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: Example .center {text-align:center;} You can also specify that only specific HTML elements should be affected by a class. In the example below, all p elements with class="center" will be center-aligned: Example p.center {text-align:center;}

Multiple Style Sheets : 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.  For example, an external style sheet has these properties for the h3 selector: h3{color:red;text-align:left;font-size:8pt;} And an internal style sheet has these properties for the h3 selector: h3{text-align:right;font-size:20pt;} If the page with the internal style sheet also links to the external style sheet the properties for h3 will be: color:red;text-align:right;font-size:20pt; The color is inherited from the external style sheet and the text-alignment and the font-size is replaced by the internal style sheet.

Cascading order : 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: Browser default External style sheet Internal style sheet (in the head section) 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).

Example: CSS Background : Example: 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-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: Example body {background-color:#b0c4de;} background-image:url('paper.gif'); background-repeat:repeat-x; background-position:right top;}

Want to learn?

Sign up and browse through relevant courses.

Name:
Your Email:
Password:
Country:
Contact no:


Area code Number
Subjects you are interested in:
Word verification: (Enter the text as in image)


Sign Up Already a member? Sign In
I agree to WizIQ's User Agreement & Privacy Policy
Muhammad Fiaz
Experienced Web site Design & Development Trainer
1 Member Recommends
1 Follower

Your Facebook Friends on WizIQ

Give live classes, create & sell online courses

Try it free Plans & Pricing

Connect