Learner Guide - Introduction to CSS
Learner Guide - Introduction to CSS
1.0 Xaltius
Learner’s Guide – Introduction to CSS
Contents
Contents .......................................................................................................................... 3
About Xaltius ................................................................................................................... 4
Overview ......................................................................................................................... 5
Duration........................................................................................................................... 6
Administrative Matters ..................................................................................................... 7
Using the Learners’ Guide............................................................................................... 9
Introduction to CSS ....................................................................................................... 10
Introduction to CSS in web development ...................................................................... 11
How does CSS work with HTML ................................................................................... 16
Activity 1.1: To apply CSS style to basic HTML page using VS Code Editor. ............... 17
Activity 1.2: To apply Inline CSS style to basic HTML page. ......................................... 21
Activity 1.3: Styling a Web page to highlight bakery’s offerings. .................................... 23
Reference...................................................................................................................... 36
Learner’s Guide – Introduction to CSS
About Xaltius
Xaltius is a technology and data-driven
company with the expertise to provide
innovative software solutions and
training to customers around the globe.
We work to revamp and refine business
potential, driving business excellence.
As a maturing, tech-based company at
heart, we are driven by the ever-changing dynamics of digitalization to provide
personalized software solutions elevating business capabilities. Alongside our
counterparts, we offer retail and corporate training in the fields of data analytics, data
science, big data, and cloud technologies and have been actively doing that in Singapore
since inception.
Overview
Course Descriptor
This course is designed to help you understand the fundamentals of CSS and how to use
it effectively to style and layout web pages. This course will provide you with the skills to
transform plain HTML documents into visually appealing web pages.
Learning Outcomes
By the end of the course, learners will be able to:
• Understand the role and importance of CSS in web development.
• Write and apply inline, internal, and external CSS styles.
• Utilize selectors, properties, and values to style HTML elements.
Duration
Duration
Delivery
(Hours)
Facilitated Classroom Training 1.5 Hrs
Hrs 2 Hrs
Learner’s Guide – Introduction to CSS
Administrative Matters
Attendance = >75% to pass the course
Timings – 2 Hours
Ground Rules
• Please turn your mobiles to “Silent” mode of switch it off
• Please avoid bringing food or beverages into the classroom
• Please keep the classroom tidy and conducive for learning
In case of emergency
• Wait for instructions from the appointed Fire Warden/Course Instructor
• Proceed to the nearest fire escape staircase and assemble at the designated
Assembly Area
• Do not return to the classroom unless permission is given by the appointed
Learner’s Guide – Introduction to CSS
APPEAL PROCESS
1. In the event that there is a dispute over the assessor’s decision, the candidate has the
right to an appeal process. Examples of dispute over the assessment outcome may
include:
• Assessment process was unfair or invalid
• Assessment decision was incorrect and / or
• Assessment was not carried out in accordance with the assessment plan.
• Candidates who disagree with the assessment outcome should first inform the
assessor of their intention to appeal against the assessment decision. This will
allow the assessor to document the candidate’s intention in the Feedback Section
of the Summary Assessment Record.
• Candidate should then lodge a formal appeal in writing to Xaltius Academy (email:
appeal@xaltius.tech) within 5 working days from the date of result notification. The
email should state clearly the following:
o Name, NRIC and contact number
o Competency Unit assessed
o Assessment date, time and venue
o Name of assessor
o Reasons for appeal
3. The Appeal Panel will be reviewing the appeal application to establish if the
assessment conducted adhered to the Principles of Assessment and Rules of
Evidence. The participant will be notified of the assessment outcome in writing within
four weeks from the date of appeal.
5. If sufficient evidence is gathered by the Appeal Panel to indicate the appeal was made
on strong grounds, provisions will be made for a re-assessment by a different
assessor at no additional cost. The re-assessment outcome is final, and no further
appeals will be entertained.
Learner’s Guide – Introduction to CSS
The Learners’ Guide has been designed to maximize your learning. Each section has
been put together as a self-contained, competency-based learning package. Each of
these sections contains the following components represented by the icons:
Learning Outcomes
It is useful for the learner to do his/her review against the learning
outcome in preparation for the assessment.
Learning Activity
A learning activity involves the learner in ‘doing’ to learn
through experience and/or discussion with peers. Your facilitator
may use these in class or have you complete the activity as
homework.
Learner’s Guide – Introduction to CSS
Introduction to CSS
Learner’s Guide – Introduction to CSS
CSS (Cascading Style Sheets) is primarily used to style and format the layout of HTML
documents. While HTML provides the structure and content, CSS is responsible for the
visual presentation. This includes setting colours, fonts, spacing, and more.
CSS is a useful tool in web development. It provides the means to style and layout web
pages, ensuring they are visually appealing, responsive, and accessible. By separating
content from presentation, CSS allows for efficient and maintainable code, ultimately
enhancing the user experience and making web development more manageable.
Types of CSS
There are three ways of inserting a style sheet:
1. External CSS - With an external style sheet, you can change the look of an entire
website by changing just one file. Each HTML page must include a reference to
the external style sheet file inside the <link> element, inside the head section.
2. Internal CSS - An internal style sheet may be used if one single HTML page has
a unique style. The internal style is defined inside the <style> element, inside the
head section.
3. Inline CSS - An inline style may be used to apply a unique style for a single
element. To use inline styles, add the style attribute to the relevant element. The
style attribute can contain any CSS property.
Learner’s Guide – Introduction to CSS
CSS works by selecting elements within an HTML document and applying styles to them.
These styles can be defined using various CSS properties and values.
Here are some key concepts to understand when working with CSS:
• Selectors: CSS selectors are used to target specific elements within an HTML
document. Selectors can be based on element names, class names, IDs,
attributes, or other criteria. For example, the selector h1 targets all <h1> elements,
while the selector .class targets elements with a specific class name.
• Declaration Blocks: CSS rules consist of a selector and a declaration block. The
declaration block contains one or more CSS properties and their associated
values.
• Inheritance: CSS properties can be inherited from parent elements to their child
elements, meaning the child elements will inherit certain styles by default.
However, not all properties are inherited, and some can be explicitly overridden.
• Box Model: The box model is a fundamental concept in CSS that defines how
elements are structured and how their dimensions are calculated. It consists of
four components: content, padding, border, and margin. The content represents
the actual element's content, while padding, border, and margin provide space
around the content.
• CSS Units: CSS supports different units for specifying lengths, such as pixels (px),
percentages (%), em, rem, and more. These units allow developers to define sizes
and distances in a flexible and responsive manner.
• CSS Selectors: CSS provides a wide range of selectors to target elements based
on their relationship with other elements, attributes, states, and more. This includes
descendant selectors, child selectors, sibling selectors, pseudo-classes (:hover,
:focus), and pseudo-elements (::before, ::after).
• CSS Specificity: Specificity determines which CSS rules take precedence when
multiple rules target the same element. Specificity is calculated based on the types
of selectors used and the number of occurrences. It helps resolve conflicts and
ensure that the correct styles are applied.
CSS is a powerful tool for designing and styling web pages. By applying CSS rules,
developers can control the visual aspects of their websites, create engaging layouts, and
enhance the user experience.
Learner’s Guide – Introduction to CSS
Example:
Advantages of CSS
The ability to distinguish a web page's appearance from its content using CSS has the
following advantages:
• Consistency: One style code may apply across several pages, giving your website
a unified look and feel.
• Flexibility: Without changing the underlying HTML structure, CSS enables you to
quickly modify your web page's look by changing styles in a single CSS file.
• Efficiency: CSS helps to reduce repetitive code, resulting in smaller, quicker-
loading web pages.
• Accessibility: CSS provides better assistance for building web pages that are
simpler to use and understand for those who have disabilities.
• Faster Page Speed: Slower page performance results from more code. And CSS
makes it possible to write less code. With CSS, you may apply a single CSS rule
to each instance of a certain tag throughout an HTML text.
• Better User Experience: CSS facilitates a user-friendly layout and makes websites
to be pleasant to the eye. The user experience is enhanced whenever buttons and
text are placed logically and are well-organized.
Learner’s Guide – Introduction to CSS
1. Syntax
CSS syntax consists of selectors and declaration blocks. A selector points to the HTML
element(s) you want to style. The declaration block contains one or more declarations
separated by semicolons. Each declaration includes a property and a value, separated
by a colon.
h1 {
color: blue;
font-size: 24px;
}
2. Selectors
Selectors are used to target HTML elements for styling. There are several types of
selectors:
Element Selector: Selects all elements of a given type.
p{
color: red;
}
Class Selector: Selects all elements with a specified class attribute. Classes are
denoted by a dot (.) followed by the class name.
.myClass {
background-color: yellow;
}
ID Selector: Selects the element with a specified ID attribute. IDs are denoted by a
hash (#) followed by the ID name.
#myId {
margin: 10px;
}
Learner’s Guide – Introduction to CSS
input[type="text"] {
border: 1px solid black;
}
Margin: The space outside the border, separating the element from other elements.
Example:
div {
width: 200px;
padding: 10px;
border: 2px solid blue;
margin: 20px;
}
Learner’s Guide – Introduction to CSS
To manage and display the layout of web pages, CSS must be used in combination with
HTML. HTML determines the layout and content of a web page, and CSS is utilized to
add styles to that content, specifying how the page should appear and be shown to the
user. Here is how CSS and HTML interact:
1. HTML Structure: The structure of a web page is built on HTML. The headers,
paragraphs, photos, links, tables, forms, and more are all defined using tags. Each
HTML element represents the content types of a page.
2. CSS Rules: The collection of CSS rules that specify how various HTML components
should be styled. A selector and a declaration block are the two primary components of
a CSS rule. The declaration portion contains one or more style attributes and their
accompanying values, whereas the selector specifies the HTML element(s) upon which
the styles should be implemented.
For example:
/* CSS Rule */
h1 {
color: blue;
font-size: 24px;
}
Linking CSS to HTML: You must link the CSS file with the HTML file to use CSS in an
HTML page. The '<link>' tag in the HTML document's '<head>' section is commonly
used to link a css file with html document. The external CSS file's location is indicated
by the 'href' of the '<link>' tag.
Activity 1.1: To apply CSS style to basic HTML page using VS Code Editor.
Step 1: Open VS
code and Install
Live Server
extension.
To open Visual
Studio Code , go to
search bar on your
PC and type Visual
Studio Code.
A)Launch VS Code.
From the sidebar,
select Extensions.
This opens an
extensions panel.
B)Type “Live
Server” in the
search box and click
on the Install
button.
Learner’s Guide – Introduction to CSS
Step 2: Prepare
your HTML and
CSS files
First, we will create a
new folder on
desktop to store our
HTML and CSS files.
To do this, click
Open folder on the
left sidebar.
Step 3 : Creating
Files
a)Select the folder
which you have
created on your
desktop. Here The
folder name is ‘web
project’.
Create an HTML
program in this folder
by pressing the New
File button next to
your folder heading.
Name it
Learner’s Guide – Introduction to CSS
basic_Activity_1.ht
ml.
}
Add the html code
given below to which h1{
we are adding the
styling. color: blue;
text-align: center;
p{
font-size: 25px ;
font-style: italic;
h3{
font-size: large;
font-style: italic;
color:fuchsia
</style>
Learner’s Guide – Introduction to CSS
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>
Step 5 - Running A
Project
After clicking on Go
Live Option, you can
see your output on
port:5500 i.e. on your
browser.
Learner’s Guide – Introduction to CSS
Step 3: </style>
h2 { color: yellow; }:
It Styles all <h2> (heading level 2)
elements to have yellow text.
Step 5:
Adding inline CSS
For inline CSS, you need to add
coding in <body> tag in HTML
page.
<body>: Begins the body of the
HTML document, where the visible
content goes.
<h1 style="color:aqua">Heading
1</h1>: Defines an <h1> (heading
level 1) element with inline CSS to
set the text colour to aqua.
<h2
style="color:blueviolet">Headin
g 2</h2>: Defines an <h2>
element with inline CSS to set the
text color to blueviolet.
Step 6:
Run the example
Daniela, a baker, aims to establish an online presence for her bakery, "Sweet
Delights," by creating a simple website. With the basic knowledge of CSS, create
a webpage to highlight her bakery's offerings and contact and below given
details.
Step 1: Open
VS code and
Install Live
Server
extension.
To open Visual
Studio Code ,
go to search
bar on your PC
and type
Visual Studio
Code.
a)Launch VS
Code. From
the sidebar,
select
Learner’s Guide – Introduction to CSS
Extensions.
This opens an
extensions
panel.
b)Type “Live
Server” in the
search box
and click on
the Install
button.
Step 2:
Prepare your
HTML and
CSS files
First, we will
create a new
folder on
desktop to
store our
HTML and
CSS files.
Learner’s Guide – Introduction to CSS
To do this,
click Open
folder on the
left sidebar.
Step 3:
a)Select the
folder which
you have
created on
your desktop.
Here The
folder name is
‘web project’.
b)Open the
folder by
clicking on
‘select folder’.
It opens in
visual studio
code.
c)You can
create a folder
in your
preferred
directory.
project
explorer view
for your project
on the left side,
which shows
files and
folders for your
project.
Create an
HTML program
in this folder by
pressing the
New File
button next to
your folder
heading. Name
it Bakery.html.
Learner’s Guide – Introduction to CSS
main {
h1 Styling:
margin: 0;: padding: 20px;
Removes any
default margin }
from the <h1>
element. section {
margin-bottom: 20px;
main styling:
padding: padding: 15px;
20px;: Adds 20
pixels of }
padding inside
the main /* Highlight About Us section */
content area.
section.about-us {
section
styling: background-color: #91b9ea;
margin-bottom:
20px;: Adds 20 border: 2px solid #444a8f;
pixels of
margin below }
each section.
/* Highlight Contact Us section */
About US section.contact-us {
styling: Set
the background-color: #4a4d4e38;
background
colour of the border: 2px solid #00695c;
"About Us"
section to a }
light blue.
border: Adds a footer {
2-pixel solid
border with a background-color: #8f980a;
dark blue
color: #fff;
color.
text-align: center;
Contact us
section padding: 10px;
styling: Set
the position: fixed;
background
colour of the width: 100%;
"Contact Us"
section to a
Learner’s Guide – Introduction to CSS
includes an </section>
<h1> tag with
the bakery's <!-- Contact Us Section -->
welcome
message. <section class="contact-us">
<footer>
<main>: The
main content <p> Sweet Delights Bakery</p>
area of the
document. </footer>
<section </body>
class="about-
us">: Defines </html>
a section for
the "About Us"
content. It
includes an
<h2> tag and a
paragraph
describing the
bakery.
<section
class="contac
t-us">:
Defines a
section for the
"Contact Us"
content. It
includes an
Learner’s Guide – Introduction to CSS
<footer>:
Defines a
footer for the
document. It
includes a
paragraph with
the bakery's
name.
Step 6: Run
the code
Run the given
code using
“Go live”
option at the
rightmost down
corner of VS
code and you
can check for
the output in
any preferred
web browser
as shown.
Learner’s Guide – Introduction to CSS
Activity 1.4 :Creating a web page with simple CSS using Edublock (Optional)
Let’s continue to work on our Corner Book Shop web page. Now that we have some
content, it is time to add in some styling to the page.
Output:
Output:
Learner’s Guide – Introduction to CSS
Give some
spacing between
the inner text by
adding padding
(10px).
These are basic styling applied to the web page, please feel free to use your creativity
to add more styles. Have fun with it!
In the future module, we will learn more about HTML, CSS, and JavaScript in greater
details. You will learn how to write the code yourself from scratch.
Learner’s Guide – Introduction to CSS
Reference
1. Learn HTML, CSS, and JavaScript from Scratch - Free AI-Powered Course
2. CSS Tutorial
3. Web Design Weekly - The Best Web Design Newsletter
4. EduBlocks