Presentation is loading. Please wait.

Presentation is loading. Please wait.

( Cascading style sheet )

Similar presentations


Presentation on theme: "( Cascading style sheet )"— Presentation transcript:

1 ( Cascading style sheet )
Chapter#3 CSS ( Cascading style sheet )

2 Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation semantics (the look and formatting) of a document written in a markup language. Its most common application is to style web pages written in HTML.

3 Cont.… A style sheet consists of a list of rules. Each rule or rule-set consists of one or more selectors, and a declaration block. A declaration-block consists of a list of declarations in braces. Each declaration itself consists of a property, a colon (:), and a value. If there are multiple declarations in a block, a semi-colon (;) must be inserted to separate each declaration.

4 Cont.…

5 Cont.… Inline styles, inside the HTML document, style information on a single element, specified using the style attribute Embedded or internal style, blocks of CSS information inside the <head> element of HTML itself External style sheets, i.e., a separate CSS file referenced from the document

6 Example : The following example demonstrates the inline style <!doctype html> <html> <body> <p style=”font-family:arial;color:blue;font-size:medium”> This is a paragraph formatted with inline css style. </p> </body> </html>

7 Example : The following example demonstrates the internal style <!doctype html> <html> <head> <style> P { Font-family:arial; Font-size:medium; Color:blue; Text-align:justify; } </style> </head> <body> <p> This is a paragraph formatted with internal css style. </p> </body> </html>

8 Example The following example demonstrates the external style. Create a new document in notepad, define the following css styles within it and save it with the name Style.css P { Font-family:arial; Font-size:medium; Color:blue; Text-align:justify; } H1 Font-family:arial black; Background-color:blue; Color:white;

9 Cont.… Create another new document in notepad and create a html file with the following html markup. To link an external css file, use <link> element of html within the <head> element. <!doctype html> <html> <head> <link rel=”stylesheet” type=”text/css” href=”MyStyle.css”/> </head> <body> <h1> Heading </h1> <p> This is a paragraph formatted with internal css style. </p> </body> </html>

10 CSS Colors Colors in CSS are most often specified by: 1. a valid color name - like "red" 2. an RGB value - like "rgb(255, 0, 0)" 3. a HEX value - like "#ff0000"

11 Color Names Color Name Red Green Blue Orange Yellow Cyan Black
Red Green Blue Orange Yellow Cyan Black Note: Color names are case-insensitive: "Red" is the same as "red" or "RED".

12 RGB (Red, Green, Blue) RGB color values can be specified using this formula: rgb(red, green, blue). Each parameter (red, green, blue) defines the intensity of the color between 0 and 255. Color RGB rgb(255,0,0) rgb(0,255,0) rgb(0,0,255) rgb(255,165,0) rgb(255,255,0) rgb(0,255,255)

13 Cont.… Color RGB rgb(0,0,0) rgb(128,128,128) rgb(255,255,255)

14 Hexadecimal Colors RGB values can also be specified using hexadecimal color values in the form: #RRGGBB, where RR (red), GG (green) and BB (blue) are hexadecimal values between 00 and FF (same as decimal 0-255).

15 CSS Backgrounds

16 Background Color The background-color property specifies the background color of an element. The background color of a page is set like this: Example: body {     background-color: lightblue; } h1 {     background-color: green; } div {     background-color: lightblue; } p {     background-color: yellow; }

17 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. Example body { background-image: url("paper.gif"); }

18 Background Image - Repeat Horizontally or Vertically
This example shows us that how we will repeat the background image horizontally. body { background-image: url("gradient_bg.png"); background-repeat: repeat-x; } This example shows us that how we will repeat the background image vertically. body { background-image: url("gradient_bg.png"); background-repeat: repeat-y; }

19 Set position and no-repeat
body {     background-image: url("img_tree.png");     background-repeat: no-repeat;     background-position: right top; }

20 Background Image - Fixed position
body { background-image: url("img_tree.png"); background-repeat: no-repeat; background-position: right top; background-attachment: fixed; } We can apply the code by using single line property. body { background: #ffffff url("img_tree.png") no-repeat right top; }

21 CSS Height and Width Dimensions:
Note: The CSS dimension properties allow you to control the height and width of an element. This element has a width of 100%.

22 Setting height and width
The height and width properties are used to set the height and width of an element. The height and width can be set to auto (this is default. Means that the browser calculates the height and width), or be specified in length values, like px, cm, etc., or in percent (%) of the containing block.

23 Cont… This <div> element has a height of 100 pixels and a width of 500 pixels. Example: div { width: 500px; height: 100px; border: 3px solid blue; }

24 CSS Borders

25 Border-Style The following values are use for border-style. dotted - Defines a dotted border Dashed - Defines a dashed border Solid - Defines a solid border double - Defines a double border Groove - Defines a 3D grooved border. The effect depends on the border-color value ridge - Defines a 3D ridged border. The effect depends on the border-color value Inset - Defines a 3D inset border. The effect depends on the border-color value Outset - Defines a 3D outset border. The effect depends on the border-color value None - Defines no border Hidden - Defines a hidden border

26 Example 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;} p.none {border-style: none;} p.hidden {border-style: hidden;} p.mix {border-style: dotted dashed solid double;}

27 Result:

28 Border Width Border-width has three values: Thin Medium Thick Example:
border-style:solid; border-width:thin; } border-width:medium; border-width:thick;

29 Border Color Border-color property sets the color of the border on its edges p { border-style: solid; border-color: red; }

30 Border - Individual Sides
We can give style to each side of border individually by using the following properties. p { border-top-style: dotted; border-right-style: solid; border-bottom-style: dotted; border-left-style: solid; }

31 Border Shorthand property
Here we have single line property to set the border including border-width, border-style, border-color. p { border: 1px solid red; }

32 CSS Margins The CSS margin properties set the size of the white space OUTSIDE the border. Margin pull the web object to a specified direction

33 Margin - Individual Sides
Example: p {     margin-top: 100px;     margin-bottom: 100px;     margin-right: 150px;     margin-left: 80px; } margin-top margin-right margin-bottom margin-left

34 Margin - Shorthand Property
The margin property is a shorthand property for the following individual margin properties: margin-top margin-right margin-bottom margin-left Example p {     margin: 100px 150px 100px 80px; }

35 CSS Padding Properties
The CSS padding properties are used to generate space around content. The padding properties set the size of the white space between the element content and the element border.

36 Padding - Individual Sides
CSS has properties for specifying the padding for each side of an element: padding-top padding-right padding-bottom padding-left All the padding properties can have the following values: length - specifies a padding in px, pt, cm, etc. % - specifies a padding in % of the width of the containing element.

37 Example p {     padding-top: 50px;     padding-right: 30px;     padding-bottom: 50px;     padding-left: 80px; }

38 Padding - Shorthand Property
To shorten the code, it is possible to specify all the padding properties in one property. The padding property is a shorthand property for the following individual padding properties: padding-top padding-right padding-bottom padding-left Example p {     padding: 50px 30px 50px 80px; }

39 Padding formats padding: 25px 50px 75px 100px;
top padding is 25px right padding is 50px bottom padding is 75px left padding is 100px If the padding property has three values: padding: 25px 50px 75px; right and left paddings are 50px If the padding property has two values: padding: 25px 50px; top and bottom paddings are 25px right and left paddings are 50px If the padding property has one value: padding: 25px; all four paddings are 25px

40 CSS Text

41 Css text formatting Text Color:
The color property is used to set the color of the text. Text Alignment: The text-align property is used to set the horizontal alignment of a text. A text can be left or right aligned, centered, or justified. Text Decoration: The text-decoration property is used to set or remove decorations from text. The value text-decoration: none; is often used to remove underlines from links: Text Transformation: The text-transform property is used to specify uppercase and lowercase letters in a text.

42 Css text formatting Text Indentation
The text-indent property is used to specify the indentation of the first line of a text: Letter Spacing The letter-spacing property is used to specify the space between the characters in a text. Word Spacing The word-spacing property is used to specify the space between the words in a text. Line Height The line-height property is used to specify the space between lines:

43 Example h1 { color: green; text-align: center/left/right; text-align: justify; text-decoration: overline/underline/line-through; Text-transform: uppercase/lowercase/capitalize; text-indent: 50px; letter-spacing: 3px; line-height: 1.8; word-spacing: 10px; }

44 Css fonts

45 Css fonts Font Family The font family of a text is set with the font-family property. The font-family property should hold several font names as a "fallback" system. If the browser does not support the first font, it tries the next font, and so on. Font Style The font-style property is mostly used to specify italic text. Font Size The font-size property sets the size of the text. Font Weight The font-weight property specifies the weight of a font:

46 Example p { font-family: "Times New Roman", Times, serif; font-style: normal/italic/oblique; font-size: 40px/em/%; font-weight: normal/bold/value in px; }

47 CSS Layout - The display Property


Download ppt "( Cascading style sheet )"

Similar presentations


Ads by Google