cit 307 - internet based programming lecture notes: week 4 instructor:dr. tolgay karanfİller

30
CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Upload: rhoda-merritt

Post on 29-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

CIT 307 - Internet Based Programming

Lecture notes: Week 4

Instructor:Dr. Tolgay KARANFİLLER

Page 2: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Contents: • Basic Facts • External CSS files save time in production and maintenance • Styles cascade • Which type of styles will have higher priorities? • Syntax • Selector • Class vs. ID • Notation • Group selectors • Property • Background • Text • Border • Margin • Padding • List • Table • Dimension • Classification • Positioning • Pseudo classes • Pseudo elements

Page 3: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

• Value • CSS Units • Comments • References

Page 4: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

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 Style Sheets can save a lot of work

External Style Sheets are stored in CSS files

Page 5: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Basic Facts: • CSS stands for Cascading Style Sheets • CSS defines how to display an HTML element • CSS has it's own notation to assign attributes for appearance

• CSS styles can be assigned to an identical element by writing it as an attribute of that element • CSS styles of a web page are normally written together as part of information describing the page (content of <head>) • A pack of styles can be implemented in a page in two ways: • Written as the content of <style> tag in <head> section • Embedded using <link> tag as an external .css file

Page 6: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

<html><head><style type="text/css">body{background-color:#d0e4fe;}h1{color:orange;text-align:center;}p{font-family:"Times New Roman";font-size:20px;}</style></head><body><h1>CSS example!</h1><p>This is a paragraph.</p></body></html>

Page 7: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

External CSS files save time in production and maintenance:

As a developer, you write your CSS codes in a .css file and embed them into as many web pages you want (like using the same image in many HTML files). This way you assign the desired style to as many elements you want in many HTML files. And you have written the styles for an element only once in your .css file. Now when you want to change a simple thing like the font size of the <p> elements in all over the website, you just need to change a line in .css file and the change is applied globally. This feature is saving a lot of time in production and maintenance of web sites, especially in large scale project where you deal with many pages at the same time.

Page 8: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

<html><head><link rel=“stylesheet” type=“text/css” href=“ex1.css” /></head> <body><h1>This header is 36pt </h1><h2>This header is blue</h2><p>This paragraph has a left margin of 50pixels.</p></body></html>

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

This is the style sheet file (ex1.css):

Page 9: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

This is the style sheet file (ex2.css):

body {background-color:tan;} h1 {color:maroon;font-size:20pt;} hr {color:navy;} p {font-size:11pt;margin-left:15px;} a:link {color:green;} a:visited {color:yellow;} a:hover {color:black;} a:active {color:blue;}

<html><head><link rel=“stylesheet” type=“text/css” href=“ex2.css” /></head> <body><h1>This is a header 1 </h1><hr /><p>You can see that the style sheet formats the text.</p><p> href="http://www.w3schools.com" target="_blank">This is a link </a></p></body></html>

Page 10: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

CSS SyntaxA 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.

Page 11: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Important parts of every style: • Selector • Property • Value

Example:

selector{ property: value } • Selector: p • Property: color • Value: #FF0000

You can easily understand that: • Content of a selector is placed within the curve braces • Each property is followed by a colon • Each value is followed by a semi-colon

Page 12: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

<html><head><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>

To make the CSS more readable, you can put one declaration on each line, like this:

Page 13: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

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;}

Page 14: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Three Ways to Insert CSS There are three ways of inserting a style sheet: External style sheet Internal style sheet Inline style

Page 15: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

External Style SheetAn external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section:

<head><link rel="stylesheet" type="text/css" href="mystyle.css" /></head>

An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with a .css extension. An example of a style sheet file is shown below:

hr {color:sienna;}p {margin-left:20px;}body {background-image:url("images/back40.gif");}

Page 16: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Internal Style SheetAn internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, by using the <style> tag, like this:

<head><style type="text/css">hr {color:sienna;}p {margin-left:20px;}body {background-image:url("images/back40.gif");}</style></head>

Page 17: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Inline StylesAn inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly!To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:

<p style="color:sienna;margin-left:20px">This is a paragraph.</p>

Page 18: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

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

Page 19: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

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:

<html><head><style type="text/css">body{background-color:#b0c4de;}</style></head><body><h1>My CSS web page!</h1><p>Hello world! This is a W3Schools.com example.</p></body></html>

Page 20: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

<html><head><style type="text/css">h1{background-color:#6495ed;}p{background-color:#e0ffff;}div{background-color:#b0c4de;}</style></head><body><h1>CSS background-color example!</h1><div>This is a text inside a div element.<p>This paragraph has it's own background color.</p>We are still in the div element.

In the example below, the h1, p, and div elements have different background colors:

Page 21: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Background ImageThe 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:

<html><head><style type="text/css">body {background-image:url('paper.gif');}</style></head>

<body><h1>Hello World!</h1></body>

</html>

Page 22: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Here you can see a list of different properties and their possible values:

Page 23: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER
Page 24: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Text Color

The default color for a page is defined in the body selector.

<html><head><style type="text/css">body {color:red;}h1 {color:#00ff00;}p.ex {color:rgb(0,0,255);}</style></head>

<body><h1>This is heading 1</h1><p>This is an ordinary paragraph. Notice that this text is red. The default text-color for a page is defined in the body selector.</p><p class="ex">This is a paragraph with class="ex". This text is blue.</p></body></html>

Page 25: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Text AlignmentThe text-align property is used to set the horizontal alignment of a text.Text can be centered, or aligned to the left or right, or justified.When text-align is set to "justify", each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers).<html><head><style type="text/css">h1 {text-align:center;}p.date {text-align:right;}p.main {text-align:justify;}</style></head><body><h1>CSS text-align Example</h1><p class="date">May, 2009</p><p class="main">In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing anyone,' he told me, just remember that all the people in this world haven't had the advantages that you've had.'</p><p><b>Note:</b> Try to resize the browser window to see how justify works.</p></body></html>

Page 26: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Text DecorationThe text-decoration property is used to set or remove decorations from text.The text-decoration property is mostly used to remove underlines from links for design purposes:

<html><head><style type="text/css">h1 {text-decoration:overline;}h2 {text-decoration:line-through;}h3 {text-decoration:underline;}h4 {text-decoration:blink;}</style></head><body><h1>This is heading 1</h1><h2>This is heading 2</h2><h3>This is heading 3</h3><h4>This is heading 4</h4><p><b>Note:</b> The "blink" value is not supported in IE, Chrome, or Safari.</p></body></html>

Page 27: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Text TransformationThe text-transform property is used to specify uppercase and lowercase letters in a text.It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word.

<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.</p><p class="lowercase">This is some text.</p><p class="capitalize">This is some text.</p></body></html>

Page 28: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

Text IndentationThe text-indentation property is used to specify the indentation of the first line of a text.

<html><head><style type="text/css">p {text-indent:50px;}</style></head><body>

<p>In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing anyone,' he told me, just remember that all the people in this world haven't had the advantages that you've had.'</p>

</body></html>

Page 29: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

All CSS Text PropertiesThe number in the "CSS" column indicates in which CSS version the property is defined (CSS1 or CSS2).

Property Description Values CSS

color Sets the color of a text color 1

direction Sets the text direction ltrrtl

2

line-height Sets the distance between lines normalnumberlength%

1

letter-spacing Increase or decrease the space between characters normallength

1

text-align Aligns the text in an element leftrightcenterjustify

1

text-decoration Adds decoration to text noneunderlineoverlineline-throughblink

1

text-indent Indents the first line of text in an element length%

1

text-shadow   nonecolorlength

 

text-transform Controls the letters in an element nonecapitalizeuppercaselowercase

1

Page 30: CIT 307 - Internet Based Programming Lecture notes: Week 4 Instructor:Dr. Tolgay KARANFİLLER

unicode-bidi   normalembedbidi-override

2

vertical-align Sets the vertical alignment of an element baselinesubsupertoptext-topmiddlebottomtext-bottomlength%

1

white-space Sets how white space inside an element is handled normalprenowrap

1

word-spacing Increase or decrease the space between words normallength

1