Top Banner
CSS Web Engineering 1 Ishaq Khan Shinwari MCS City University Peshawar
27

Css, CaseCading Style Sheet

Aug 20, 2015

Download

Technology

Ishaq Shinwari
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Css, CaseCading Style Sheet

1

CSSWeb Engineering

Ishaq Khan ShinwariMCS City University Peshawar

Page 2: Css, CaseCading Style Sheet

2

What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML

elements Styles are normally stored in Style

Sheets Styles were added to HTML 4.0 to solve

a problem

Page 3: Css, CaseCading Style Sheet

3

External Style Sheets can save you a lot of work

External Style Sheets are stored in CSS files

Multiple style definitions will cascade into one

Page 4: Css, CaseCading Style Sheet

4

How to Insert a Style Sheet

When a browser reads a style sheet, it will format the document according to it. There are three ways of inserting a style sheet:

1) External Style Sheet 2) Internal Style Sheet 3) Inline Style Sheet

Page 5: Css, CaseCading Style Sheet

5

HTML file

<html> <head> <link rel="stylesheet" type="text/css"

href="ex1.css" /> </head> <body> <h1>This header is 36 pt</h1>

<h2>This header is blue</h2> <p>This paragraph has a left margin of

50 pixels</p> </body> </html>

Page 6: Css, CaseCading Style Sheet

6

Css file

body {background-color: yellow} h1 {font-size: 36pt} h2 {color: blue} p {margin-left: 50px}

Page 7: Css, CaseCading Style Sheet

7

CSS Heading <html>

<head> <style type="text/css"> h1 {color: #00ff00} h2 {color: #dda0dd} p {color: rgb(0,0,255)} </style> </head>

<body> <h1>This is header 1</h1> <h2>This is header 2</h2> <p>This is a paragraph</p> </body>

</html>

Page 8: Css, CaseCading Style Sheet

8

CSS Background Color <html> <head>

<style type="text/css"> body {background-color: red} h1 {background-color: #00ff00} h2 {background-color: transparent} p {background-color: rgb(250,0,255)} </style>

</head>

<body>

<h1>This is header 1</h1> <h2>This is header 2</h2> <p>This is a paragraph</p>

</body> </html>

Page 9: Css, CaseCading Style Sheet

9

CSS Background Image <html> <head>

<style type="text/css"> body {background-image: url('bgdesert.jpg')} </style>

</head>

<body> </body>

</html>

Page 10: Css, CaseCading Style Sheet

10

CSS Background Image Repead

<html> <head>

<style type="text/css"> body { background-image: url('bgdesert.jpg'); background-repeat: repeat } </style>

</head>

<body> </body> </html>

Page 11: Css, CaseCading Style Sheet

11

Background Image Repeat on vertically <html> <head>

<style type="text/css"> body { background-image: url('bgdesert.jpg'); background-repeat: repeat-y } </style>

</head>

<body> </body> </html>

Page 12: Css, CaseCading Style Sheet

12

Background Image Repeat on Horizontally <html> <head>

<style type="text/css"> body { background-image: url('bgdesert.jpg'); background-repeat: repeat-x } </style>

</head>

<body> </body> </html>

Page 13: Css, CaseCading Style Sheet

13

Set the color of Text <html>

<head> <style type="text/css"> h1 {color: #00ff00} h2 {color: #dda0dd} p {color: rgb(0,0,255)} </style> </head>

<body> <h1>This is header 1</h1> <h2>This is header 2</h2> <p>This is a paragraph</p> </body>

</html>

Page 14: Css, CaseCading Style Sheet

14

Set the background-color of the text <html> <head> <style type="text/css"> span.highlight { background-color:yellow } </style> </head>

<body> <p> <span class="highlight">This is a text.</span> This is a text. This is a text. This is a

text. This is a text. This is a text. This is a text. This is a text. This is a text. <span class="highlight">This is a text.</span>

</p> </body> </html>

Page 15: Css, CaseCading Style Sheet

15

Specify the space between characters <html>

<head> <style type="text/css"> h1 {letter-spacing: -3px} h4 {letter-spacing: 0.5cm} </style> </head>

<body> <h1>This is header 1</h1> <h4>This is header 4</h4> </body>

</html>

Page 16: Css, CaseCading Style Sheet

16

Word spacing <html> <head> <style type="text/css"> p { word-spacing: 30px } </style> </head> <body>

<p> This is some text. This is some text. </p>

</body> </html>

Page 17: Css, CaseCading Style Sheet

17

Align the text <html> <head> <style type="text/css"> h1 {text-align: center} h2 {text-align: left} h3 {text-align: right} </style> </head>

<body> <h1>This is header 1</h1> <h2>This is header 2</h2> <h3>This is header 3</h3> </body>

</html>

Page 18: Css, CaseCading Style Sheet

18

Text Decoration <html> <head> <style type="text/css"> h1 {text-decoration: overline} h2 {text-decoration: line-through} h3 {text-decoration: underline} h4 {text-decoration: blink} a {text-decoration: none} </style> </head>

<body> <h1>This is header 1</h1> <h2>This is header 2</h2> <h3>This is header 3</h3> <h4>This is header 4</h4> <p><a href="../default.asp.htm">This is a link</a></p> </body>

</html>

Page 19: Css, CaseCading Style Sheet

19

Control the letters in a text <html> <head> <style type="text/css"> p.uppercase {text-transform: uppercase} p.lowercase {text-transform: lowercase} p.capitalize {text-transform: capitalize} </style> </head>

<body> <p class="uppercase">This is some text in a paragraph</p>

<p class="lowercase">This is some text in a paragraph</p>

<p class="capitalize">This is some text in a paragraph</p> </body>

</html>

Page 20: Css, CaseCading Style Sheet

20

Set the text direction of an element <html> <head> <style type="text/css"> div.one { direction: rtl } div.two { direction: ltr } </style> </head> <body>

<div class="one">Some text. Right-to-left direction.</div> <div class="two">Some text. Left-to-right direction.</div>

</body> </html>

Page 21: Css, CaseCading Style Sheet

21

Set the font of a text <html> <head> <style type="text/css"> h3 {font-family: times} p {font-family: courier} p.sansserif {font-family: sans-serif} </style> </head>

<body> <h3>This is header 3</h3> <p>This is a paragraph</p> <p class="sansserif">This is a paragraph</p> </body>

</html>

Page 22: Css, CaseCading Style Sheet

22

Font Size <html> <head> <style type="text/css"> h1 {font-size: 150%} h2 {font-size: 130%} p {font-size: 100%} </style> </head>

<body> <h1>This is header 1</h1> <h2>This is header 2</h2> <p>This is a paragraph</p> </body>

</html>

Page 23: Css, CaseCading Style Sheet

23

Font Style <html> <head> <style type="text/css"> h1 {font-style: italic} h2 {font-style: normal} p {font-style: oblique} </style> </head>

<body> <h1>This is header 1</h1> <h2>This is header 2</h2> <p>This is a paragraph</p> </body>

</html>

Page 24: Css, CaseCading Style Sheet

24

All the border properties in one declaration <html> <head> <style type="text/css"> p { border: medium double rgb(250,0,255) } </style> </head>

<body> <p>Some text</p> </body>

</html>

Page 25: Css, CaseCading Style Sheet

25

Set the style of the four borders

<html> <head> <style type="text/css"> p.dotted {border-style: dotted} p.dashed {border-style: dashed} p.solid {border-style: solid} p.double {border-style: double} p.groove {border-style: groove} p.ridge {border-style: ridge} p.inset {border-style: inset} p.outset {border-style: outset} </style> </head>

Page 26: Css, CaseCading Style Sheet

26

Cont…….

<body> <p class="dotted">A dotted border</p>

<p class="dashed">A dashed border</p>

<p class="solid">A solid border</p>

<p class="double">A double border</p>

<p class="groove">A groove border</p>

<p class="ridge">A ridge border</p>

<p class="inset">An inset border</p>

<p class="outset">An outset border</p> </body>

</html>

Page 27: Css, CaseCading Style Sheet

27

There is No Shortcut to success

Keep Smile!