Computer 8 - 3rd Quarter Lessons
Computer 8 - 3rd Quarter Lessons
Introduction to CSS
CSS – Cascading Style Sheet
It is used to control the layout of HTML documents.
It is used to add styles like text color, font type, paragraph spacing, column size and layout,
background image & color, etc.
It is usually a text file separate from your HTML file.
html files uses attribute names and values, and angle brackets.
css makes use of properties and values, and curly braces.
Capabilities of CSS
1. Web pages are easily updated.
2. Objects can be positioned where you want them.
3. Objects can be layered in 3D.
4. You can create custom tags.
Advantages of CSS
1. It saves time.
2. Pages load faster.
3. Multiple link tags can be added to one document.
3 Kinds of CSS
1. Inline Style
2. Internal Style or Embedded Style
3. External Style or Linked Style
Inline Style
Inline styles are placed straight into the HTML tags using the style attribute
ex. <p style=”font-family: Arial; color: red”> This is a paragraph </p>
font-family and color are called properties
Arial and red are called values
Inline style should be avoided since it mixes content with presentation.
Types of Selector
1. Element selector
ex. h1 {color:#000000;}
2. Descendant selector
ex. ul em {color:#000000;} This means the em is inside the ul.
3. Class selector
ex. h1.black {color:#000000;} You need to create a class name.
4. ID selector
ex. #black {color:#000000;} You need to create an id name.
CSS Property
It is a type of attribute of HTML tag.
In simple terms, all HTML attributes are converted into CSS properties.
examples:
color
border
font
text-align
Value
the value assigned to properties
examples:
red for color property
solid for border property
16pt Arial for font property
center for text-align property
Types of Values
Length and Percentage (numeric value with unit, e.g. 5px)
examples:
px for pixels
em for calculated size of font (e.g. 2em = 2x the current font size)
pt for points (for measurement typically of printed media)
% for percentages
cm for centimeters
in for inches
mm for millimeters
Colors
examples:
A color name like red
A hexadecimal color code like #ff0000 or #f00
An RGB color code like rgb(255, 0, 0) use web-safe colors which are available
online.
CSS Comments
Comments are used to explain the code.
They are ignored by browsers.
A CSS comment starts with /* and ends with */
text-align sets the horizontal alignment of text in an element; possible values are left, right,
center, and justify
o p {text-align: justify;}
text-decoration specifies the decoration added to text; possible values are underline, overline,
line-through, and none. (You can use none to remove underline from hyperlinks.)
o p {text-decoration: underline;}
o a:link {text-decoration: none;}
text-transform sets the cases for text; possible values are capitalize, lowercase, uppercase, and
none.
o p {text-transform: uppercase;}
text-indent sets the indent of the first line of a paragraph; possible values are % or a number
specifying indent space.
o p {text-indent: 100px;}
letter-spacing sets the extra spacing between letters of an element's text
o p {letter-spacing: 15px;}
word-spacing sets the extra spacing between the words in the text content
o p {word-spacing: 50px;}
Background properties
The background CSS property provide fundamental styles to an element, such as color, image,
and position.
Individual background properties can be set as:
o background-color
o background-image
o background-repeat
o background-position
o background-attachment
background-color sets the background color for a page.
o body {background-color: lightblue;}
background-image sets the background color for the <body> element.
o body {background-image: url("paper.gif");}
|____________|
This is how image files
are specified in CSS.
background-repeat sets if how a background image will be repeated.
o By default, a background image is repeated both vertically and horizontally
o Possible values: repeat, repeat-x (horizontal, laying down), repeat-y (vertical, standing
up), no-repeat
o body {background-image: url("paper.gif"); background repeat: repeat-x;}
background-position sets the starting position of a background image.
o By default, a background image is placed at the top-left corner of an element
o Possible values: left top, left center, left bottom, right top, right center, right bottom,
center top, center center, center bottom
o body {background-image: url("paper.gif"); background repeat: no-repeat; background-
position: center;}
background-attachment sets whether a background image scrolls with the rest of the page, or is
fixed.
o By default, a background image scrolls with the page
o Possible values: scroll, fixed, and local
o body {background-image: url("paper.gif"); background-repeat: no-repeat; background-
position: center; background-attachment: fixed;}
Background shorthand sets different background properties in one declaration.
o body {background: lightblue url(“paper.gif”) no-repeat center fixed;}
To change the alignment of text with CSS, use the [text-align] property.
Which of these is not a predefined value for text-align property? left, right, center, middle
To place a horizontal line through text using the text-decoration property, used the line-through value.
The correct predefined value for font-style property to create an italicized text is italic
The correct CSS property for specifying the typeface of text is font-family
Which of the following is not a predefined value for font-weight? bold, lighter, bolder, medium
When using a font family name that has white spaces on it, enclose the name in double quotes
The CSS property that will apply bold formatting to text is font-weight
Which of these is not a generic font name? serif, monospace, sans-serif, modern