Lecture 3
Lecture 3
Lecture3
Getting Started with CSS
• browser styles or user agent styles, built into the browser itself.
• user-defined styles, created by the user within the browser.
• external styles, which are styles created and placed within a CSS file
and linked to the website. <link href=“style_file.css” rel=“stylesheet”/>
• embedded styles, which are the styles placed within the HTML file
itself. <style> css rules <style>
• inline styles, which are added as attributes of specific elements within
the HTML file.
<p style=“color: red;”>
• Embedded styles are inserted directly into the HTML file by adding
the following style element to the document head
External style
Embedded style
2022 Dr. Ibrahim Al-Baltah 10
Inline Styles
• The very last styles to be interpreted by the browser are inline styles,
which are styles applied directly to specific elements using the
following style attribute
where the property: value pairs define the styles, which are applied
directly to that element.
More specific
Less specific
• An additional factor in how style rules are interpreted is that styles are
passed from a parent element to its children in a process known as
style inheritance.
• Thus, the following style rule sets the color of article text to blue and
that rule is passed to any paragraph, header, footer, or other element
nested within an article element. In addition, the paragraph text within
that article is centered:
@import url(basic.css);
@import url(sales.css);
2022 Dr. Ibrahim Al-Baltah 16
Working with Color in CSS
• To match any element, use the wildcard selector with the * character.
• For example, the following style rule matches every child of the article
element, setting the text color to blue:
article > * {color: blue;}
where name is the name of the font, url is the location of the font definition file,
text is an optional text description of the font format, and the descriptor: value
pairs are optional style properties that describe when the font should be used.
2022 Dr. Ibrahim Al-Baltah 35
The @font-face Rule...
• Absolute units are units that are fixed in size regardless of the output
device and are usually used only with printed media.
• They are specified in one of five standard units of measurement: mm
(millimeters), cm (centimeters), in (inches), pt (points), and pc (picas).
• For example, to set the font size of your page body text to a 12pt font,
you would apply the following style rule:
body {font-size: 12pt;}
• Note that you should not insert a space between the size value and the
unit abbreviation.
https://ww
w.w3school
s.com/cssr
ef/css_unit
s.asp
• Finally, you also can express font sizes using the following keywords:
xx-small, x-small, small, medium, large, x-large, xx-large, larger, or
smaller.
• The font size corresponding to each of these keywords is determined
by the browser.
aside {font-size: small;}
aside > h1 {font-size: larger;}
letter-spacing: value;
word-spacing: value;
• where value is the size of space between individual letters or words.
• space between lines of text and is defined with the following line-
height property
line-height: size;
• An additional way to control text spacing is to set the indentation for
the first line of a text block by using the following text-indent property
text-indent: size;
• You can specify a different font style using the following font-style
Property font-style: type;
• where type is normal, italic, or oblique.
• To change the weight of the text, use the following font-weight
property font-weight: weight;
• Where weight values can be :
• keyword bold for boldfaced text and normal for non-boldfaced text.
• keywords bolder or lighter
• values ranging from 100 (extremely light) up to 900 (extremely heavy)
in increments of 100
vertical-align: 50%;
vertical-align: -100%;
2022 Dr. Ibrahim Al-Baltah 46
2022 Dr. Ibrahim Al-Baltah 47
Combining All Text Formatting in a Single Style
• You can combine most of the text and font style properties into the
following shorthand font property
• For example, the following style rule displays the element text in
italic, bold, and small capital letters using Arial or another sans-serif
font, with a font size of 1.5em and a line height of 2em: