Professional Documents
Culture Documents
MOLINO
Technological University of the Philippines
CSS Introduction
Internal CSS
<head>
<style>
h3 {color:green;}
</style>
</head>
Used for single page.
External CSS
<head>
<link rel = “stylesheet” href=“heading.css”>
</head>
Used for many pages.
CSS Syntax
A CSS stylesheet consists of a set of rules that are interpreted by the web browser and then
applied to the corresponding elements such as paragraphs, headings, etc. in the document.
A CSS rule have two main parts, a selector and one or more declarations:
Each declaration includes a CSS property name and a value, separated by a colon. Multiple CSS declarations are
separated with semicolons, and declaration blocks are surrounded by curly braces.
CSS Selector
CSS selectors are the rule set that is used to select the HTML content on HTML
pages so that they can be styled as we choose.
The style rules associated with that selector will be applied to the elements
that match the selector pattern.
Selectors are one of the most important aspects of CSS as they allow you to
target specific elements on your web page in various ways so that they can be
styled.
Universal Selector
The universal selector, denoted by an asterisk (*), matches every single element on the page.
Example:
Output:
Element Type Selector
An element type selector matches all instance of the element in the document with the
corresponding element type name.
Example:
Output:
ID Selector
The id selector is used to define style rules for a single or unique element. The id selector is
defined with a hash sign (#) immediately followed by the id value.
Example:
Output:
Class Selector
The class selectors can be used to select any HTML element that has a class attribute. All the elements
having that class will be formatted according to the defined rule. The class selector is defined with a period sign (.)
immediately followed by the class value.
Example:
Output:
Descendant Selector
You can use these selectors when you need to select an element that is the descendant of another
element.
Example:
Output:
Child Selector
A child selector is used to select only those elements that are the direct children of some element.
A child selector is made up of two or more selectors separated by a greater than symbol (>).
Example:
Output:
Group Selector
Often several selectors in a style sheet share the same style rules declarations. You can group them into a
comma-separated list to minimize the code in your style sheet. It also prevents you from repeating the same
style rules over and over again.
Example:
Output:
Attribute Selector
Attribute Selector means the property, character or behavior of the Selector.
CSS Colors
The color property defines the text color (foreground color in general) of an element.
For instance, the color property specified in the body selector defines the default text
color for the whole page. Let's try out the following example to see how it works:
You can specify your color values in various formats. Following table lists all the possible
formats −
Color Names
HTML Color Names
Hexadecimal
RGB
CSS Colors
Color Name
Color Name
<body>
<p style = "background-color:yellow;">
This text has a yellow background color.
</p>
</body>
</html>
CSS Set the Background Image
The background-image property set an image as a background of an HTML element.
<style>
body {
background-image: url("/css/images/css.jpg");
background-color: #cccccc;
}
</style>
https://developer.mozilla.org/en-US/docs/Web/CSS/background-image
CSS Repeat the Background Image
<style>
body {
background-image: url("/css/images/css.jpg");
background-repeat: repeat;
}
</style>
</head>
https://developer.mozilla.org/en-US/docs/Web/CSS/background-repeat
CSS Repeat the Background Image
Similarly, you can use the value repeat-y to repeat the background image vertically
along the y-axis, or the value no-repeat to prevent the repetition altogether.
CSS Set the Background Image Position
background-position:100px;
background-position: right top;
https://developer.mozilla.org/en-US/docs/Web/CSS/background-position
CSS Set the Background Image Position
CSS Set the Background Image Position
CSS Set the Background Attachment
https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment
CSS Background Shorthand Property
The background property is a shorthand property for setting all the individual background
properties, i.e., background-color, background-image, background-repeat, background-
attachment and the background-position property at once.
Using the shorthand notation the above example can be written as:
CSS Fonts
Web Safe Fonts
CSS Fonts
The CSS font properties define the font family, boldness, size, and the style of a text.
The font properties are: font-family, font-style, font-weight, font-size, and font-variant.
CSS Font Style
The letter-spacing property is used to add or subtract space between the letters that make up a word.
The word-spacing property is used to add or subtract space between the words of a sentence.
The text-transform property is used to capitalize text or convert text to uppercase or lowercase letters.
The white-space property is used to control the flow and formatting of text.
The text-shadow property is used to set the text shadow around a text.
CSS Text
TextColor
Text Color TextTransformation
Text Transformation
Word Spacing
TextAlignment
Text Alignment
TextDecoration
Text Decoration
LetterSpacing
Letter Spacing
Text Indentation
CSS Text
CSS Box Model Hierarchy
Static
Relative
Absolute
Fixed
Initial
Inherit
https://css-tricks.com/almanac/properties/p/position/
REFERENCES
https://www.w3schools.com/css/
https://www.tutorialspoint.com/css/index.htm
https://htmldog.com/guides/css/
https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps
https://www.tutorialrepublic.com/css-tutorial/
https://www.csstutorial.net/
https://css-tricks.com/
<!DOCTYPE html> body{
<html lang="en"> background-color: #f4f4f4;
<head> color: #555555;
<meta charset="UTF-8"> font-family: Arial, Helvetica, sans-serif;
<meta name="viewport" content="width=device-width, font-size: 16px;
initial-scale=1.0"> line-height: 1.6em;
<title>Document</title> margin: 0;
<link rel="stylesheet" href="style.css"> }
</head> #main-header{
<body> background-color:teal;
<header id="main-header"> color: #ffffff;
<div class="container"> }
<h1>My Webpage</h1>
</div> .container{
</header> width: 80%;
<nav id="navbar"> margin: auto;
<div class="container"> overflow: hidden;
<ul> }
<li><a href="home.html">Home</a></li> #navbar{
<li><a href="#">About Us</a></li> background-color: #333333;
<li><a href="#">Service</a></li> color: #ffffff;
<li><a href="#">Contact Us</a></li> }