Web CH 3
Web CH 3
R
G H
B S
L
A
R H
G E
B X
A
10
Compiled By Aliazar D. (MSc in SEng)
• CSS Background Image
• CSS background-color ✓ The background-image
CSS Backgrounds ✓ The background-color property specifies an image to
property specifies the use as the background of an
• The CSS background background color of an element.
properties are used to add element. background-image: url(“image.png");
background effects for ✓ You can set the background ✓ By default, the background-
elements. color for any HTML image property repeats an
• CSS background properties: elements: body, <h1>, <p>, image both horizontally and
and <div> elements. vertically but to display the
⁕ background-color
✓ The opacity property background image only once
⁕ background-image background-repeat: no-repeat;
specifies the
⁕ background-repeat property is used.
opacity/transparency of an
✓ The background-position
⁕ background- element. It can take a value property is used to specify the
attachment from 0.0 - 1.0. The lower position of the background
⁕ background-position value, the more transparent. image. background-position: right top;
⁕ Background • CSS background - Shorthand property
• The background-attachment It is used to specify all the background properties in one single
property. When using the shorthand property the order of the property
property specifies whether
values is:1. background-color, 2. background-image 3. background-
the background image repeat, 4.background-attachment and 5. background-position. It does
should scroll or be fixed not matter if one of the property values is missing, as long as the other
11
Compiled By Aliazar D. (MSc in SEng) ones are in this order. background: #ffffff url("img_tree.png") no-repeat right top;
CSS Borders
• The border-style property specifies what kind of border to
display.
• The following values are allowed:
⁕ 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
Compiled By Aliazar D. (MSc in SEng) 12
Conti.. ⁂ CSS Border Sides
† If the border-style property has
• CSS Border - Shorthand
Property
four values: † The border property is a
• CSS Border Width shorthand property for the
✓ The border-width property ⁕ border-style: dotted solid double
dashed; following individual border
specifies the width of the four
borders. ⁕ top border is dotted properties:
border-width: 5px; ⁕ right border is solid ⁕ border-width
✓ The border-width property can ⁕ bottom border is double ⁕ border-style (required)
have from one to four values (for ⁕ left border is dashed ⁕ border-color
the top border, right border, border: 5px solid red;
bottom border, and the left † If the border-style property has
three values: • CSS Rounded Borders
border):
border-width: 25px 10px 4px ⁕ border-style: dotted solid double; † The border-radius property
35px; ⁕ top border is dotted is used to add rounded
• CSS Border Color ⁕ right and left borders are solid borders to an element
✓ The border-color property is used ⁕ bottom border is double
to set the color of the four borders. † If the border-style property has
border-color: red; two values:
✓ The border-color property can ⁕ border-style: dotted solid;
have from one to four values (for
the top border, right border, ⁕ top and bottom borders are dotted
bottom border, and the left ⁕ right and left borders are solid
border). † If the border-style property has border: 2px solid red;
border-color: red green blue one value: border-radius: 5px;
yellow; ⁕ border-style: dotted; border-radius: 8px;
⁕ all four borders are dotted border-radius: 12px; 13
Compiled By Aliazar D. (MSc in SEng)
CSS Margins and Padding
CSS Padding
CSS Margins • The margin property is a shorthand • The CSS padding properties are
• The CSS margin properties are used to create space property for the following individual
around elements, outside of any defined borders. used to generate space around an
• margin properties:
CSS has properties for specifying the margin for element's content, inside of any
each side of an element: • margin-top
⁕ margin-top • margin-right defined borders.
⁕ margin-right • margin-bottom • For individual slides and shorthand
⁕ margin-bottom • margin-left property the same strategies are
⁕ margin-left • If the margin property has four values:
• All the margin properties can have the following with CSS Margins.
✓ margin: 25px 50px 75px 100px;
values:
(top, right, bottom, left)
⁕ auto - the browser calculates the margin
⁕ length - specifies a margin in px, cm, etc. • If the margin property has three values:
⁕ % - specifies a margin in % of the width of ✓ margin: 25px 50px 75px; (top,
the containing element left and right, bottom)
⁕ inherit - specifies that the margin should be • If the margin property has two values:
inherited from the parent element
✓ margin: 25px 50px; (top and div {
div {
border: 1px solid black; bottom, left and right) padding-top: 50px;
margin-top: 100px; • If the margin property has one value: padding-right: 30px;
margin-bottom: 100px; ✓ margin: 25px; (all four margins) padding-bottom: 50px;
margin-right: 150px; ✓ You can set the margin property to auto padding-left: 80px;
margin-left: 80px; to horizontally center the element
background-color: lightblue;
}
within its container. Compiled By Aliazar D. (MSc in SEng) 14
}
CSS Height, Width and Max-width
• The CSS height and width properties are used • Setting max-width
to set the height and width of an element.
⁜ The max-width property is used to set
• The CSS max-width property is used to set the maximum width of an element.
the maximum width of an element. ⁜ The max-width can be specified in
• The height and width properties may have the length values, like px, cm, etc., or in
following values: percent (%) of the containing block, or
◙ auto - This is default. The browser set to none (this is default. Means that
calculates the height and width there is no maximum width).
◙ length - Defines the height/width in px, ⁜ If you for some reason use both the
cm, etc. width property and the max-width
◙ % - Defines the height/width in percent property on the same element, and the
of the containing block value of the width property is larger
◙ initial - Sets the height/width to its than the max-width property; the max-
default value width property will be used (and the
◙ inherit - The height/width will be width property will be ignored).
inherited from its parent value
• The height and width properties do not
include padding, borders, or margins. It sets
the height/width of the area inside the
padding, border, and margin of the element. 15
Compiled By Aliazar D. (MSc in SEng)
The CSS Box Model
• The CSS box model is essentially a box that wraps around every
HTML element. It consists of: margins, borders, padding, and
the actual content. .
• Explanation of the different parts:
⁕ Content - The content of the box, where text and images
appear
⁕ Padding - Clears an area around the content. The padding
is transparent
⁕ Border - A border that goes around the padding and
content
⁕ Margin - Clears an area outside the border. The margin is
transparent
div {
width: 300px;
border: 15px
solid green;
padding: 50px;
margin: 20px; Compiled By Aliazar D. (MSc in SEng) 16
}
• The outline-style property specifies•
CSS Outline the style of the outline, and can
The outline-width
property specifies the
width of the outline,
have one of the following values:
• An outline is a line drawn outside the ♠ dotted - Defines a dotted outline and can have one of
element's border to make the element ♠ dashed - Defines a dashed outline the following values:
"stand out". ♠ solid - Defines a solid outline thin (typically 1px),
♠ double - Defines a double outline medium (typically
♠ groove - Defines a 3D grooved 3px), thick (typically
outline 5px), A specific size
♠ ridge - Defines a 3D ridged outline (in px, pt, cm, em, etc)
• The outline-color
• CSS has the following outline properties: ♠ inset - Defines a 3D inset outline
♠ outset - Defines a 3D outset outline property is used to set
⁍ outline-style
♠ none - Defines no outline the color of the outline
⁍ outline-color
⁍ outline-width ♠ hidden - Defines a hidden outline • The outline-offset
property adds space
⁍ outline-offset
between an outline and
⁍ outline
the edge/border of an
• Outline differs from borders!
element.
• Unlike border, the outline is drawn
• The shorthand outline
outside the element's border, and may
property for setting the
overlap other content.
following individual
• Also, the outline is NOT a part of the
outline properties:
element's dimensions; the element's total
• outline-width
width and height is not affected by the
• outline-style (required)
width of the outline. Compiled By Aliazar D. (MSc in SEng) 17
• outline-color
CSS Text
• CSS has a lot of properties for formatting text. • Text Decoration
• Text Color ✓ The text-decoration-line property is used to add a decoration line to text.
✓ The color property is used to set the color of the text. The values are overline, line-through, underline, and overline underline.
• Text Alignment ✓ The text-decoration-color property is used to set the color of the decoration
⁕ The text-align property is used to set the horizontal line.
alignment of a text. ✓ The text-decoration-style property is used to set the style of the decoration
⁕ A text can be left or right aligned, centered, or line. The values are solid, double, dotted, dashed, and wavy.
justified (justify). ✓ The text-decoration-thickness property is used to set the thickness of the
• Text Align Last decoration line.
✓ The text-align-last property specifies how to align the ✓ The text-transform property is used to specify uppercase and lowercase
last line of a text. letters in a text. The values are uppercase, lowercase, and capitalize.
• Text Direction
✓ The text-shadow property adds shadow to text. you only specify the
⁕ The direction and unicode-bidi properties can be used horizontal shadow and the vertical shadow in px.
to change the text direction of an element. • Text Spacing
direction: rtl; ✓ letter-spacing: Specifies the space between characters in a text.
unicode-bidi: bidi-override;
✓ line-height: Specifies the line height.
• Vertical Alignment
✓ text-indent: Specifies the indentation of the first line in a text-block.
✓ The vertical-align property sets the vertical alignment
of an element. The values are baseline (default), text-
✓ white-space: Specifies how to handle white-space inside an element.
top, text-bottom, sub and sup. ✓ word-spacing: Specifies the space between words in a text 18
Compiled By Aliazar D. (MSc in SEng)
CSS Fonts
• Choosing the right font has a huge Generic Font Family Examples of Font Names
impact on how the readers experience a Serif Times New Roman
website. Georgia
• In CSS there are five generic font Garamond
families:
1. Serif fonts have a small stroke at
the edges of each letter. They Sans-serif Arial
create a sense of formality and Verdana
elegance. Helvetica
2. Sans-serif fonts have clean lines
(no small strokes attached). They Courier New
Monospace
create a modern and minimalistic Lucida Console
look.
Monaco
3. Monospace fonts - here all the
letters have the same fixed width. Cursive Brush Script MT
They create a mechanical look. Lucida Handwriting
4. Cursive fonts imitate human
handwriting.
Fantasy Copperplate
5. Fantasy fonts are Papyrus
decorative/playful fonts.
Compiled By Aliazar D. (MSc in SEng) 19
Conti..
• CSS Font Family • CSS Font Size
♠ The font-size property sets the size of the text.
♠ The CSS font-family property is used to specify the font
♠ To make the Font Size Responsive, the text size can be set with a vw unit, which
of a text. means the "viewport width".
♠ If the font name is more than one word, it must be in • CSS Google Fonts
quotation marks, like: "Times New Roman". (Fallback Fonts!) ♠ Google Fonts are free to use, and have more than 1000 fonts to choose from.
• CSS Font Style ♠ To use google fonts
♠ The font-style property is mostly used to specify italic 1. Add a stylesheet link to request the desired web font(s):
text. ♠ <link rel=“stylesheet”
href="https://fonts.googleapis.com/css?family=Font+Name">
♠ This property has two values: 2. Style an element with the requested web font, either in a stylesheet:
♠ normal - The text is shown normally I. .css-selector {font-family: 'Font Name', serif; }
♠ italic - The text is shown in italics II. or with an inline style on the element itself:
• CSS Font Weight <div style="font-family: 'Font Name', serif;">Your text</div>
♠ <link rel="stylesheet" href="https://fonts.googleapis.com/c
♠ The font-weight property specifies the weight of a font. ss?family=Sofia">
The values are normal, lighter, bold and you can specify ♠ font-family: "Sofia", sans-serif;
with number like 1000. ♠ To use multiple Google fonts, just separate the font names with a pipe character
• CSS Font Variant (|)
♠ The font-variant property specifies whether or not a text ♠ <link rel="stylesheet" href="https://fonts.googleapis.com/c
ss?family=Audiowide|Sofia|Trirong">
should be displayed in a small-caps font.
• The font property is a shorthand property for: font-style, font-variant, font-weight, font-
♠ In a small-caps font, all lowercase letters are converted to size/line-height and font-family. The font-size and font-family values are required. If one
uppercase letters. However, the converted uppercase of the other values is missing, their default value are used.
letters appears in a smaller font size than the original
uppercase letters in the text. Compiled By Aliazar D. (MSc in SEng) 20
CSS Icons
• Icons can easily be added to HTML page, by <body> • Bootstrap Icons
using an icon library. such as Font Awesome. <i class="fas fa-cloud"></i> • To use the Bootstrap glyphicons, add
Add the name of the specified icon class to <i class="fas fa-heart"></i> the following line inside the <head>
any inline HTML element (like <i> or <i class="fas fa-car"></i> section of the HTML page:
<span>). <i class="fas fa-file"></i> • <link rel="stylesheet"
• Font Awesome Icons <i class="fas fa-bars"></i> href="https://maxcdn.bootstrapcdn.co
• To use the Font Awesome icons, go to </body> m/bootstrap/3.3.7/css/bootstrap.min.cs
fontawesome.com, sign in, and get a code to • Google Icons s">
add in the <head> section of the HTML page: • To use it, add the link below inside the <body>
<script <head> section of the HTML page: <i class="glyphicon glyphicon-
src="https://kit.fontawesome.com/yourcode.js"cross <link rel="stylesheet" cloud"></i>
origin="anonymous"></script> href="https://fonts.googleapis.com/icon?fa <i class="glyphicon glyphicon-
<head> mily=Material+Icons"> remove"></i>
<meta name="viewport" content="width=device- <i class="material-icons">cloud</i> <i class="glyphicon glyphicon-user"></i>
width, initial-scale=1"> <i class="material-icons">favorite</i> <i class="glyphicon glyphicon-
<script <i class="material-icons">attachment</i> envelope"></i>
src="https://kit.fontawesome.com/a076d05399.js" <i class="material-icons">computer</i> <i class="glyphicon glyphicon-thumbs-
crossorigin="anonymous"></script> up"></i>
<i class="material-icons">traffic</i>
<!--Get your own code at fontawesome.com--> </body>
Compiled By Aliazar D. (MSc in SEng) 21
</head>
CSS Links
<style>
• Links can be styled with any CSS • /* unvisited link */
property (e.g. color, font-family, a:link {
color: red;
background, etc.). }