In the previous lecture, we learned about:
In this lecture, we will learn:
<div> Tag and Layered TechnologyInline CSS is written directly inside an HTML element using the style attribute.
<tag style="property:value;">
<h1 style="color:red;">
Welcome to CSS
</h1>
The color property changes text color.
<p style="color:blue;">
This text is blue.
</p>
The font-family property changes the font style.
<p style="font-family:Arial;">
Welcome Students
</p>
Used to control text size.
<p style="font-size:20px;">
Large Text
</p>
Controls spacing between lines.
<p style="line-height:30px;">
This is line one.
This is line two.
</p>
Controls horizontal alignment.
<p style="text-align:center;">
Center Text
</p>
Adds or removes text decoration.
<p style="text-decoration:underline;">
Underlined Text
</p>
Changes letter case.
<p style="text-transform:uppercase;">
welcome students
</p>
Controls text thickness.
<p style="font-weight:bold;">
Bold Text
</p>
Used to create borders around elements.
<div style="border:1px solid black;">
Content Here
</div>
Changes element background color.
<div style="background-color:yellow;">
Welcome
</div>
Adds an image as background.
<div style="background-image:url(images/bg.jpg);">
</div>
Controls image repetition.
background-repeat:no-repeat;
Controls image placement.
background-position:center center;
Everything displayed on a webpage is measured using pixels.
Examples:
width:300px;
height:200px;
font-size:14px;
margin:10px;
Pixels help developers control:
A good web designer understands measurements and spacing.
The <div> tag is one of the most important HTML elements.
DIV stands for:
Division
It is used to divide a webpage into sections or layers.
<div>
Header Area
</div>
Developers often call DIV:
Websites are built using layers.
Example:
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
Each DIV creates a separate layer.
One layer can overlap another layer.
position:absolute;
Using positioning, one DIV can appear above another DIV.
Block elements occupy the full available width.
Examples:
<div></div>
<p></p>
<h1></h1>
<ul></ul>
<div>
Content
</div>
Positioning controls where elements appear on a webpage.
Default position.
position:static;
Moves element relative to its original position.
position:relative;
left:20px;
top:10px;
Places element relative to its parent.
position:absolute;
left:100px;
top:50px;
left
right
top
bottom
Element remains visible even when page scrolls.
position:fixed;
bottom:0;
right:0;
.chat-box{
position:fixed;
bottom:20px;
right:20px;
}
The properties:
left
right
top
bottom
are commonly used with:
and can also be used with relative positioning.
Comments help explain code.
They are ignored by browsers.
/* This is a CSS Comment */
/* Header Styling */
#header{
background:#000;
}
Many developers start CSS with a reset.
*{
margin:0;
padding:0;
}
body{
background:#030303;
font-size:12px;
font-family:Arial, Verdana, sans-serif;
color:#000000;
}
| Property | Purpose |
|---|---|
| background | Background color |
| font-size | Text size |
| font-family | Font style |
| color | Text color |
Selectors are used to target HTML elements.
Targets HTML tags.
p{
color:red;
}
<p>Hello</p>
Targets class attributes.
.box{
background:yellow;
}
<div class="box">
Content
</div>
Targets a unique element.
#header{
background:black;
}
<div id="header">
</div>
$("p")
$(".box")
$("#header")
| ID | Class |
|---|---|
| Unique | Reusable |
| Used once per page | Used multiple times |
| Uses # symbol | Uses . symbol |
| Higher priority | Lower priority |
<div id="header"></div>
<div class="box"></div>
<div class="box"></div>
These are the most important layout properties in CSS.
Margin creates space outside an element.
margin:20px;
Outside Space
[ Element ]
Padding creates space inside an element.
padding:20px;
[ Content ]
Float is used to align elements left or right.
float:left;
or
float:right;
<div style="float:left;">
Left Column
</div>
<div style="float:right;">
Right Column
</div>
In this lecture, we learned:
In the next lecture, we will learn more advanced CSS concepts and start building complete webpage layouts.