CSS Tutorial
CSS Tutorial
What is CSS?
➢ CSS is a Cascading Style Sheets
➢ CSS is used for layout and formatting of the web pages.
➢ Without CSS, designing web sites makes it difficult because the many lines of code are
written in HTML.
➢ Using HTML makes the process expensive and time consuming
➢ The reason being that every line of code has to be repeated when coding in HTML
➢ CSS was designed to enable the separation of presentation and content
➢ Formatting information of web pages can be moved to a separate style sheet
Explanation
p is a selector in CSS (it points to the HTML element you want to style: <p>).
text-align a value
b) Embedded styles
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>My HTML Document</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph of text.</p>
</body>
</html>
Importing External Style Sheets
The Import @import rule helps to load an external style sheet
Example
<style>
@import url("css/style.css");
p{
color: blue;
font-size: 16px;
}
Example 2
</style>
@import url("css/layout.css");
@import url("css/color.css");
body {
color: blue;
font-size: 14px;
}
CSS Syntax
Selectors
Class selector
Enables you to specify which elements are to receive a particular
style.
Example h1, h2, h3, can be made to have different colors instead of a
single color. This can be can be achieved by use of a class selector
Syntax
.class-name { property: value; }
Example
p.large { font-size: 2em; }
ID Selectors
Helps you to assign a unique identifier to an HTML element, then
style that element by referencing its unique identifier
Use the # instead of a dot operator
#id-name {property: value;}
Example
p#intro { font-size: 2em; }
Read on selectors, there are many of them
CSS animation
Use the animationn property in conjunction with
the @keyframes keyword/at-rule, which allows you to define visual
effects for your animation.
Example
<!DOCTYPE html>
<title>Example</title>
<style>
div.bounce {
width: 100px;
padding: 20px;
background: gold;
position: relative;
animation: bounce 1s ease-in 2s 6 alternate none;
}
@keyframes bounce {
from {
top: 0px;
left: 0px;
}
to {
top: 150px;
left: 150px;
}
}
</style>
<div class="bounce">Bouncing box...</