CSS notes
CSS notes
Button in CSS
CSS (Cascading Style Sheets) is a styling language that defines the appearance and
layout of HTML elements on a webpage. Buttons are common elements used in web
design to trigger actions or links. Applying CSS to buttons allows you to customize their
appearances, such as colours, fonts, borders, and animations.
Here are the basics and some advanced concepts related to button CSS. Remember
that CSS provides extensive flexibility, and one can combine various properties and
techniques to achieve your desired button styles.
1. HTML Markup:
You typically use the `<button>` element in your HTML markup to create a button. For
example:
<button>Click me</button>
CSS provides various ways to select and target elements. You can select a button by its
element type, class, or ID. Here are some examples:
button {
/* CSS styles */
}
o Select by class:
.my-button {
/* CSS styles */
o Select by ID:
You can start customizing buttons with basic styles like background colour, text colour,
padding, border, and font size. Here's an example:
button { background-color:
#4CAF50; colour: white;
padding: 10px 20px; border:
none; font-size: 16px;
Buttons can change appearance when users interact with them. You can define different styles
for the hover and active states. For example:
button:hover { background-
color: #45a049;
}
button:active { background-
color: #3e8e41;
5. Button Sizes:
Buttons can have different sizes based on their intended use. You can adjust their width,
height, and font size to create small, medium, or large buttons. Here's an example:
CSS Notes
.small-button { font-
size: 12px; padding:
5px 10px;
.medium-button {
font-size: 16px;
padding: 10px 20px;
.large-button { font-
size: 20px; padding:
15px 30px;
CSS allows you to customize button borders and add shadows for a more visually appealing
look. Here's an example:
You can apply transitions and animations to buttons to add interactive effects. For example,
you can animate the background colour change on hover. Here's an example:
CSS offers advanced techniques for button styling, such as gradients, rounded corners, box
shadows, and more. Here's an example combining some of these techniques:
}
CSS Notes
CSS Border
CSS border is a key property used to characterize and style the borders around HTML
components. Borders assume a vital part in website composition, assisting with making
separation, emphasis, and stylish allure. In CSS, you can utilize a few border-related
properties to control the style, variety, size, and shape of these borders. In this article,
we will investigate these CSS border properties and how to really utilize them.
o border-style o
border-color o
border-width o
border-radius
1) CSS border-style
The Border style property is used to specify the border type which you want to display on
the web page.
There are some border style values which are used with border-style property to define
a border.
Value Description
outset
It defines a 3d outset border. effect is generated according to border-color
value.
Example:
<!DOCTYPE html>
<html>
<head>
<style> .border-
example { width:
150px; height: 30px;
margin: 10px;
padding: 10px;
CSS Notes
}
.inset {
border: 3px inset #006600;
}
}
</style>
</head>
<body>
<div class = "border-example dotted"> Dotted Border </div>
<div class = "border-example dashed"> Dashed Border </div>
<div class = "border-example solid"> Solid Border </div>
<div class = "border-example double"> Double Border </div>
<div class = "border-example groove"> Groove Border </div>
Output:
CSS Notes
2) CSS border-width
The border-width property is used to set the border's width. It is set in pixels. You can
also use the one of the three pre-defined values, thin, medium or thick to set the width
of the border.
<!DOCTYPE html>
<html>
<head>
<style>
/* CSS for different border widths */
.thin-border { border: 2px solid #FF0000; /* It is 2-pixel wide
solid red border */
}
</style>
</head>
<body>
</body>
</html>
CSS Notes
Output:
3) CSS border-color
There are three strategies to set the color of the border.
o Name: It determines the color name. For instance: "red". o RGB: It determines
the RGB worth of the color. For instance: "rgb(255,0,0)". o Hex: It determines
the hex worth of the color. For instance: "#ff0000".
Note: The border-color property isn't utilized alone. It is constantly utilized with other
border properties like "border-style" property to set the border first any other way it won't
work.
Example:
<!DOCTYPE html>
<html>
<head>
<style> .my-element { width: 200px; height: 100px;
border: 2px solid #333; /* The Initial border color is dark gray */
transition: border-color 0.5s; /* Adding a smooth transition effect */
}
</style>
</head>
<body>
<div class = "my-element"> Hover </div>
</body>
</html>
Output:
This CSS property includes the properties that are tabulated as follows:
CSS Notes
Property Description
If the bottom-left value is omitted, then it will be same as the top-right. If the value of
bottom-right is eliminated, then it will be same as the top-left. Similarly, if top-right is
eliminated, then it will be the same as top-left.
Single Value:
At the point when you offer a single value, like border-radius: 30px;, it applies that radius to
all corners, making consistently adjusted edges.
Two Values:
Presenting two values, similar to border-radius: 20% 10%;, empowers you to set various
radii for even and vertical corners. The primary value addresses the top-left and
Things get much more intriguing with three and four values. With border-radius: 10%
30% 20%;, the values relate to top-left, top-right, and bottom-right/bottom-left
corners, separately. For four values like border-radius: 10% 30% 20% 40%;, you take
care of each corner independently.
Explicit Corners:
Here and there, you need to zero in on a particular corner. Use properties like
bordertop-left-radius to focus on the top-left corner, making an exceptional search for
your elements. The slash (/) permits you to set separate level and vertical radii. For
instance, border-radius: 10%/50%; sets a level radius of 10% and an upward radius of
50%.
Syntax
border-radius: 1-4 length | % / 1-4 length | % | inherit | initial;
Property values
length: It defines the shape of the corners. It denotes the size of the radius using length
values. Its default value is 0. It does not allow negative values.
percentage: It denotes the size of the radius in percentage. It also does not allow negative
values.
Example:
#roundedBox { border-
radius: 20px; background-
color: #7fd7e7;
#fancyBox {
#customBox {
}
Border-radius Example
Code:
<!DOCTYPE html>
<html>
<head>
<style> div
{
padding: 50px;
margin: 20px; border:
6px ridge red; width:
300px;
float: left;
height: 150px;
} p{ font-size:
25px;
}
#one { border-radius:
90px; background:
lightgreen;
#four {
</style>
</head>
<body>
<div id = "one">
<h2> Welcome to the Welcome to the Digitech </h2>
</div>
<div id = "two">
<h2> Welcome to the Welcome to the Digitech </h2>
</div>
<div id = "three">
<h2> Welcome to the Welcome to the Digitech </h2>
<p> border-radius: 35px 10em 10%; </p>
</div>
<div id = "four">
<h2>Welcome to the Digitech</h2>
</body>
</html>
The border-collapse property provides two main values: collapse and separation.
o Separate: This is the default value for the property. It creates separate borders for each
cell, leaving space between adjoining borders. Each cell maintains its distinct border. o
Collapse: This value collapses the borders between adjoining cells into a single border. It
Syntax:
table {
border-collapse: collapse;
Property Values
separate: It is the default value that separates the border of the table cell. Using this value,
each cell will display its own border.
collapse: This value is used to collapse the borders into a single border. Using this, two
adjacent table cells will share a border. When this value is applied, the borderspacing
property does not affect. initial: It sets the property to its default value. inherit: It
Now, let's understand this CSS property by using some examples. In the first example,
we are using the separate value of the border-collapse property. In the second
example, we are using the collapse value of the border-collapse property.
With this value, we can use the border-spacing property to set the distance between the
adjacent table cells.
<!DOCTYPE html>
CSS Notes
<html>
<head>
<style> table{
border: 2px solid blue;
text-align: center;
font-size: 20px; width:
80%; height: 50%;
} #t1 { border-collapse:
separate;
</style>
</head>
<body>
<table id = "t1">
<tr>
<td> 92 </td>
</tr>
<tr>
<td> 89 </td>
</tr>
<tr>
<td> 82 </td>
</tr>
</table> </body>
</html>
Output
CSS Notes
The border-spacing and border-radius properties cannot be used with this value.
<!DOCTYPE html>
<html>
<head>
<style> table{
} th{
} td{
#t1{
border-collapse: collapse;
</style>
</head>
<body>
<table id = "t1">
<tr>
<th> First_Name </th>
</tr>
<tr>
<td> 92 </td>
</tr>
<tr>
<td> 89 </td>
</tr>
<tr>
<td> 82 </td>
</tr>
</table> </body>
</html>
Output
Example:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JTP</title>
<style>
}
th,
td {
.heading {
background-color: cadetblue;
</style>
</head>
<body>
<div id="wrapper">
<table>
<tr class="heading">
<th>Product</th>
<th>Price</th>
</tr>
<tr class="data">
<td>Laptop</td>
<td>$999</td>
</tr>
<tr class="data">
<td>Smartphone</td>
<td>$599</td>
</tr>
CSS Notes
</table>
</div>
</body>
</html>
Output
Advantages of Border-collapse
o Improved Aesthetics: Collapsing table borders creates a neater and more organized
layout, especially when dealing with dense tabular data.
o Reduced Space: Collapsing borders reduce unnecessary spacing, optimizing the use
of available screen real estate.
o Consistent Styling: When designing complex tables, collapsing borders can aid in
maintaining a consistent style throughout the table structure.
o Cell Spacing: Refers to the space between cells. In border-collapse: separate; mode,
the spacing between cells can be adjusted using the border-spacing property. It
controls the distance between adjacent cell borders.
It tends to be characterized as a couple of values for deciding the vertical and horizontal
spacing.
At the point when just a single value is determined, then it sets both horizontal and vertical
spacing.
At the point when we utilize the two-value punctuation, then the first is utilized to set
the horizontal spacing (i.e., the space between the adjoining columns), and the
subsequent value sets the vertical spacing (i.e., the space between the nearby rows).
Syntax
border-spacing: length | initial | inherit;
Property Values
1. length: Determines the distance between the borders in pixels, centimeters, focuses, and so
on. Negative values are not permitted.
In this example, the border-spacing is set to 45 pixels separately, making both flat and
vertical spacing between the table cells. Change the value as per your plan inclinations.
This example show how the border-spacing property can be used to upgrade the visual
show of tables. Change the values in light of your particular plan necessities.
Code:
<!DOCTYPE html>
<html>
<head>
<style> table{
#space{ border-collapse:
separate; border-spacing:
45px;
</style>
</head>
<body>
<table id = "space">
<tr>
</tr>
<tr>
<td> 92 </td>
</tr>
<tr>
<td> 89 </td>
</tr>
<tr>
<td> 82 </td>
CSS Notes
</tr>
</table>
</body>
</html>
Output
Here, we are utilizing two values of the border-spacing property. The border-collapse
property is set to isolate, and the value of the border-spacing is set to 20pt 1em. The
primary value, i.e., 20pt sets the flat spacing, and the value 1em set the upward spacing.
This example show how the border-spacing property can be used to upgrade the visual
show of tables. Change the values in light of your particular plan necessities.
Code:
<!DOCTYPE html>
<html>
<head>
}
#space{ border-collapse:
separate; border-spacing:
20pt 1em;
</style>
</head>
<body>
<table id = "space">
<tr>
<tr>
<td> 92 </td>
</tr>
<tr>
<td> 89 </td>
</tr>
<tr>
<td> 82 </td>
</tr>
</table> </body>
</html>
Output
We can design exciting and entertaining user experiences using unique capabilities and
designs. The CSS card design works with hover effects, animations, and interactive
elements for web development applications.
Syntax:
The following syntax helps to create a card design of any container or tag.
Examples:
The following examples show the different designs and layouts of the CSS card. We can
use single, multiple, and attractive card designs.
Example 1:
The basic and simple CSS card design example shows the use and requirements in web design.
We can use basic information and one image on the card.
<!DOCTYPE html>
<html>
<head>
CSS Notes
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<style>
/* show basic CSS card design */
.card { box-shadow: 2px 6px 8px 2px
rgba(0,0,0,0.2); transition: 0.2s; width: 35%;
background-color: white; margin: 10px;
}
.main_div { background-color:
#F9F1F1; height:380px;
}
.container { padding:
2px 16px;
}
</style>
</head>
<body>
<div class = "main_div">
<h2> CSS Card Design </h2>
<p> Create Basic and Single Card Design </p>
<!-- basic card container tag -->
<div class = "card">
<!-- card information -->
<img src = "https://images.pexels.com/photos/11035386/pexels-
photo11035386.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt =
"Av atar" style = "width:100%">
Example 2:
The example shows multiple cards in a single web page to display various information in
a user-friendly format. We can use basic information and one image on the card.
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<style>
/* show basic CSS card design */
CSS Notes
.card { box-shadow: 2px 6px 8px 2px
rgba(0,0,0,0.2); transition: 0.2s; width: 45%;
background-color: white; margin: 10px;
}
.main_div {
background-color: #F9F1F1; height:380px;
}
.container { padding:
2px 16px;
}
#card1{
float: left;
}
#card2{ float:
right;
}
</style>
</head>
<body>
<div class = "main_div">
<h2> CSS Card Design </h2>
<p> Create multiple Card Designs to display various types of information </p>
<div class = "card" id = "card1">
<img src = "https://images.pexels.com/photos/11035386/pexels-photo-
11035386.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt = "Avatar
" style = "width:100%">
<div class = "container">
<h4>
<b> Digi Tech </b>
</h4>
Output:
Syntax:
The following syntax helps to create the card design of any container with a hover effect.
}
.card:hover {
/*CSS property design*/
}
Examples:
The following examples show the different designs and layouts of the CSS card. We can
use single or multiple attractive card designs.
Example 1:
The simple CSS card design example shows the use and requirements with the hover
effect in web design. We can change CSS properties and their values after the hover
effect on the card.
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<style>
/* show basic CSS card design */
}
.main_div { background-color:
#F9F1F1; height:380px;
}
.container { padding:
2px 16px;
}
/* card design with hover effect */
.card:hover {
box-shadow: 5px 8px 16px 5px rgba(0,0,0,0.2);
background-color:aqua; margin-left:30px;
}
</style>
</head>
<body>
<div class = "main_div">
<h2> CSS Card Design with Hover Effect </h2>
<p> Create Basic and Single Card Design </p>
<!?use single card design -->
<div class = "card">
<img src = "https://images.pexels.com/photos/11035386/pexels-photo-
11035386.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt = "Avatar" st
yle = "width:100%"> <div class = "container">
<h4>
<b> Digi Tech </b>
</h4>
<p> CSS Tutorial </p>
CSS Notes
</div>
</div>
</div>
</body>
</html>
Output:
Example 2:
The simple CSS card design example shows the multiple cards with hover effects in web
design. We can change CSS properties and their value for the hover effect on the two
cards.
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1">
}
.main_div { background-color:
#F9F1F1; height:380px;
}
.container { padding:
2px 16px;
}
#card1{
float: left;
}
#card2{ float:
right;
}
/* card design with hover effect */
#card1:hover { box-shadow: 5px 8px 16px 5px
rgba(0,0,0,0.2); background-color:aqua;
margin-left:30px;
}
#card2:hover { box-shadow: 5px 8px 16px 5px
rgba(0,0,0,0.2); background-color:orange;
margin-top:30px;
}
</style>
</head>
<body>
CSS Notes
<div class = "main_div">
<h2> CSS Card Design </h2>
<p> Create multiple Card Designs to display various types of information </p>
<div class = "card" id = "card1">
<img src = "https://images.pexels.com/photos/11035386/pexels-
photo11035386.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt =
"Av atar" style = "width:100%">
Output:
Syntax:
The following syntax helps to create a card design of any container with animation.
}
.card:hover {
animation: popup 2s;
}
@keyframes popup {
50%{
Animation property of the CSS tag
CSS Notes
}
}
Examples:
The following examples show the different designs and layouts of the CSS card. We can
use single or multiple attractive card designs.
Example 1:
The simple CSS card design example shows the use and requirements with the hover
effect in web design. We can change CSS properties and their values after the hover
effect on the card.
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<style>
/* show basic CSS card design */
.card { box-shadow: 2px 6px 8px 2px
rgba(0,0,0,0.2); transition: 0.2s; width: 45%;
background-color: white; margin: 10px;
}
.main_div { background-color:
#F9F1F1; height:380px;
}
.container { padding:
2px 16px;
}
#card1{
float: left;
}
}
/* CSS card design with hover effect and animation property */
#card1:hover { animation:
popup 2s;
}
/* CSS card design for animation tag property */
@keyframes popup {
0%{ transform:
scale(1);
}
50%{ transform:
scale(1.1);
}
70%{ transform:
scale(1.2);
}
}
</style>
</head>
<body>
<div class = "main_div">
<h2> CSS Card Design with animation </h2>
<p> Create multiple Card Designs to display various types of information < /p
>
Output:
The simple CSS card design example shows the use and requirements with the hover
effect in web design. We can change CSS properties and their values after the hover
effect on the card.
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<style>
/* show basic CSS card design */
.card { box-shadow: 2px 6px 8px 2px
rgba(0,0,0,0.2); transition: 0.2s; width: 45%;
background-color: white; margin: 10px;
}
.main_div { background-color:
#F9F1F1; height:380px;
}
.container {
CSS Notes
padding: 2px 16px;
}
#card1{
float: left;
}
#card2{ float:
right;
}
/* first card design with animation property */
#card1:hover { position:
relative; animation: myfirst
3s; animation-direction:
down;
}
@keyframes myfirst {
0% {background: red; left: 0px; top: 0px;}
50% {background: yellow; left: 50px; top: 200px;}
}
/* second card design with animation property */
#card2:hover { position:
relative; animation:
myfirst1 5s; animation-
direction: up;
@keyframes myfirst1 {
0% {background: red; right: 0px; bottom: 0px;}
50% {background: blue; right: 50px; bottom: 200px;}
}
</style>
In CSS, we use color values for specifying the color. We can also use this property for the
border-color and other decorative effects.
format. o Hexadecimal
Built-in color.
Let's understand the syntax and description of the above ways in detail.
RGB Format
RGB format is the short form of 'RED GREEN and BLUE' that is used for defining the
color of an HTML element simply by specifying the values of R, G, B that are in the
range of 0 to 255.
The color values in this format are specified by using the rgb() property. This property allows
three values that can either be in percentage or integer (range from 0 to 255).
This property is not supported in all browsers; that's why it is not recommended to use
it.
Syntax
RGBA Format
CSS Notes
It is almost similar to RGB format except that RGBA contains A (Alpha) that specifies
the element's transparency. The value of alpha is in the range 0.0 to 1.0, in which 0.0
is for fully transparent, and 1.0 is for not transparent.
Syntax
color:rgba(R, G, B, A);
Hexadecimal notation
Hexadecimal can be defined as a six-digit color representation. This notation starts with
the # symbol followed by six characters ranges from 0 to F. In hexadecimal notation,
the first two digits represent the red (RR) color value, the next two digits represent the
green (GG) color value, and the last two digits represent the blue (BB) color value.
The black color notation in hexadecimal is #000000, and the white color notation in
hexadecimal is #FFFFFF. Some of the codes in hexadecimal notation are #FF0000,
#00FF00, #0000FF, #FFFF00, and many more. Syntax
color:#(0-F)(0-F)(0-F)(0-F)(0-F)(0-F);
The black color notation in short hex is #000, and the white color notation in short hex
is #FFF. Some of the codes in short hex are #F00, #0F0, #0FF, #FF0, and many more.
HSL
It is a short form of Hue, Saturation, and Lightness. Let's understand them individually.
Hue: It can be defined as the degree on the color wheel from 0 to 360. 0 represents red,
120 represents green, 240 represents blue.
Syntax
color:hsl(H, S, L);
HSLA
It is entirely similar to HSL property, except that it contains A (alpha) that specifies
the element's transparency. The value of alpha is in the range 0.0 to 1.0, in which 0.0
indicates fully transparent, and 1.0 indicates not transparent. Syntax
color:hsla(H, S, L, A);
Built-in Color
As its name implies, built-in color means the collection of previously defined colors that
are used by using a name such as red, blue, green, etc. Syntax color: color-name;
Let's see the list of built-in colors along with their decimal and hexadecimal values.
7. Blue rgb(0,0,255)
#0000FF
8. Aqua rgb(0,255,255)
#00FFFF
9. Brown rgb(165,42,42)
#A52A2A
Example
<html>
<head>
<title>CSS hsl color property</title>
<style> h1{
text-align:center;
}
#rgb{
color:rgb(255,0,0);
}
#rgba{
color:rgba(255,0,0,0.5);
}
#hex{
color:#EE82EE;
}
#short{
color: #E8E;
}
#hsl{
color:hsl(0,50%,50%); }
#hsla{
color:hsla(0,50%,50%,0.5);
}
#built{
color:green;
}
CSS Notes
</style>
</head>
<body>
<h1 id="rgb">
Hello World. This is RGB format.
</h1>
<h1 id="rgba">
Hello World. This is RGBA format.
</h1>
<h1 id="hex">
Hello World. This is Hexadecimal format.
</h1>
<h1 id="short">
Hello World. This is Short-hexadecimal format.
</h1>
<h1 id="hsl">
Hello World. This is HSL format.
</h1>
<h1 id="hsla">
Hello World. This is HSLA format.
</h1>
<h1 id="built">
Hello World. This is Built-in color format.
</h1>
</body>
</html>
Cursors, however, may also be used to give our users various additional creative opportunities.
We should be aware that CSS already has default cursors for various often-done actions before
we start developing our custom cursors.
These cursors provide options for action at the precise spot you are hovering over.
Examples include cursors that indicate you should click links, drag and drop elements,
zoom in and out of objects, and more.
Use the CSS cursor property to describe the kind of cursor you want.
We may specify the kind of cursor that should be shown to the user using the CSS cursor
property.
This property is specified by zero or more <url> values separated by commas, followed
by one keyword value as required, and each <url> will refer to the image file. Syntax
cursor: value;
Property Values
o Auto: The default setting for this attribute is to place the cursor. o Alias: This attribute
is used to show the cursor's creation-related indicator. o All-scroll: The cursor in this
o Context-menu: The cursor in this attribute shows the presence of a context menu.
o Col-resize: When the cursor is above a column in this property, it may be resized
horizontally.
o Copy: The cursor in this property indicates that something has to be copied. o
Crosshair: The cursor appears as a crosshair in this attribute. o Default: The default
cursor.
o E-resize: The cursor in this attribute indicates that a box's right-hand edge should be
moved.
o Move: The pointer in this property implies that something has to be moved o . n-
resize: When using the n-resize property, the pointer shows that a box's upper
boundary should be shifted.
o Ne-resize: With this property, the cursor shows that a box's edge should be shifted to
the right and up.
o Nw-resize: The cursor in this attribute shows that a box's upper and lower edges are
to be moved up and left.
o No-drop: The cursor in this attribute indicates that the pulled object cannot be
dumped in this location.
o None: A cursor is not displayed for the element according to this attribute.
o Pointer: The cursor in this property serves as a pointer and displays link progress.
o Progress: The cursor in this attribute shows that the program is active. o Row-resize:
The cursor shows that this feature allows for vertical row resizing. o S-resize: When
using this property, the pointer shows that a box's bottom boundary should be
lowered.
o Se-resize: The cursor in this attribute indicates that a box's edge should be shifted to
the right and down.
o Sw-resize: The cursor in this attribute indicates that a box's left and lower edges
should be moved.
o Text: The cursor in this attribute denotes text that may be chosen.
o URL: This property contains a list of custom cursor URLs separated by commas and a
generic cursor at the end of the list.
o W-resize: When using this property, the pointer shows that a box's left edge should
be moved.
Example
This example shows how to utilize the cursor property. The program is busy since the cursor
property's value is set to wait.
<!DOCTYPE html>
<html>
<head>
<title> CSS cursor property </title>
<style>
CSS Notes
.wait { cursor:
wait;
}
h1 { color:
red;
}
</style>
</head>
<body>
<center>
<h1>Welcome to the page</h1>
<p>To change the mouse cursor, move the mouse over the text</p>
</center>
</body>
</html>
Output
When a user hovers their mouse over a list of items, a cursor may be created using CSS
properties. Using the HTML <ul> and <li> tags, first construct a list of the objects, and
then utilize the CSS property: To make the cursor and hand hover over the list of
objects, use hover to cursor:grab. Syntax
element:hover {
cursor:grab/pointer;
Example
<!DOCTYPE html>
<html>
<head>
<title>make our cursor as hand</title>
<style> body
{ width:90%;
}
CSS Notes
h1 { color:red;
text-align:center;
}
li:hover{ cursor:grab;
}
</style>
</head>
<body>
<h1>Welcome to the course list</h1>
<div class = "sub">Course Lists:</div>
<ul>
<li>CSE</li> <li>ECE</li>
<li>IT</li>
<li>MECH</li>
<li>CIVIL</li>
<li>AI</li>
<li>EEE</li>
</ul>
</body>
</html>
Output
Here, we'll utilize CSS to alter the cursor's color in the input fields. We will utilize the
caret-color attribute to alter the cursor's color. The cursor's color for textareas, input
fields, and other editable places can be changed using this attribute. Syntax
o Auto: The value is set by default. It takes advantage of the web browser's most
recent color.
o Color: It's used to specify the caret's color value. Any value (RGB, hex, namedcolor,
etc.) may be utilized.
Example
As an illustration, let's use the caret-color property to set the cursor color for input fields.
<!DOCTYPE html>
<html lang="en">
<head>
CSS Notes
<title>
Changing the color of the cursor using CSS
</title>
<style> body {
text-align: center;
}
/* Change the cursor color to red */
input[type="text"] { caret-color: red;
}
</style>
</head>
<body>
<h1 style="color: black;">
Welcome to the page
</h1>
<h3>
Changing the color of the cursor using CSS
</h3>
<form action="">
<label for="name">Enter Your Name</label>
<input type="text" name="name" id="">
<br><br>
</html>
Output
In CSS, the cursor property is used to specify the kind of mouse cursor that will be
shown when the mouse is hovered over an element. The browser's default setting for
the cursor is the pointer. Additionally, CSS may be used to customize it if necessary.
The cursor property's default setting is 'auto'. Additionally, adding the value auto to the
cursor property is optional because it is already set to auto by default.
Syntax cursor
: value;
CSS Notes
Property Value: It describes the cursor property's value.
Example: To display the cursor as a crosshair in this example, we will set the cursor property
value to 'cursor: crosshair'.
<!DOCTYPE html>
<html>
<head>
<style>
.cursor { cursor:
crosshair;
}
</style>
</head>
<body style="text-align:left;">
<h1 style="color:red;">
Welcome to the page
</h1>
<p class="cursor">
Login Credentials
</p>
</body>
</html>
Output
CSS Display
CSS display is the most important property of CSS which is used to control the layout of
the element. It specifies how the element is displayed.
inherited no
animation supporting no
version css1
Syntax
display:value;
1. display: inline;
2. display: inline-block;
3. display: block;
4. display: run-in;
5. display: none;
The inline element takes the required width only. It doesn't force the line break so the flow
of text doesn't break in inline example.
CSS Notes
The inline elements are:
o <span> o
<a> o
<em> o
<b> etc.
<!DOCTYPE html>
<html>
<head>
<style>
p { display:
inline;
}
</style>
</head>
<body>
<p> Hello Digitech.com </p>
<p>Java Tutorial.</p>
<p>SQL Tutorial.</p>
<p>HTML Tutorial.</p>
<p>CSS Tutorial.</p>
</body> </html>
Output:
Hello Digitech.com Java Tutorial. SQL Tutorial. HTML Tutorial. CSS Tutorial.
<!DOCTYPE html>
<html>
<head>
<style>
p { display: inline-
block;
}
</style>
</head>
<body>
<p>Hello Digitech.com</p>
<p>Java Tutorial.</p>
<p>SQL Tutorial.</p>
<p>HTML Tutorial.</p>
<p>CSS Tutorial.</p>
</body>
</html>
Output:
Hello Digitech.com.com Java Tutorial. SQL Tutorial. HTML Tutorial. CSS Tutorial.
The CSS display block element takes as much as horizontal space as they can. Means
the block element takes the full available width. They make a line break before and
after them.
<!DOCTYPE html>
<html>
CSS Notes
<head>
<style>
p { display:
block;
}
</style>
</head>
<body>
<p>Hello Digitech</p>
<p>Java Tutorial.</p>
<p>SQL Tutorial.</p>
<p>HTML Tutorial.</p>
<p>CSS Tutorial.</p>
</body>
</html>
Output: Hello
Digitech Java
Tutorial.
SQL Tutorial.
HTML Tutorial.
This property doesn't work in Mozilla Firefox. These elements don't produce a specific box
by themselves.
<!DOCTYPE html>
<html>
<head>
<style>
p { display: run-
in;
}
</style>
</head>
<body>
<p> Hello Digitech.com </p>
<p>Java Tutorial.</p>
<p>SQL Tutorial.</p>
<p>HTML Tutorial.</p>
<p>CSS Tutorial.</p>
</body>
</html>
Output:
Hello Digitech.com
Java Tutorial.
SQL Tutorial.
HTML Tutorial.
CSS Tutorial.
CSS Notes
The "none" value totally removes the element from the page. It will not take any space.
<!DOCTYPE html>
<html>
<head> <style>
h1.hidden {
display: none;
}
</style>
</head>
<body>
<h1>This heading is visible.</h1>
<h1 class="hidden">This is not visible.</h1>
<p>You can see that the hidden heading does not contain any space.</p>
</body>
</html>
Output:
Property-value Description
CSS Float
The CSS float property is a positioning property. It is used to push an element to the
left or right, allowing other element to wrap around it. It is generally used with images
and layouts.
To understand its purpose and origin, let's take a look to its print display. In the print display,
image is set into the page such that text wraps around it as needed.
CSS Notes
How it works
Elements are floated only horizontally. So it is possible only to float elements left or right,
not up or down.
1. A floated element may be moved as far to the left or the right as possible. Simply, it
means that a floated element can display at extreme left or extreme right.
2. The elements after the floating element will flow around it.
4. If the image floated to the right, the texts flow around it, to the left and if the image
floated to the left, the text flows around it, to the right.
clear The clear property is used to avoid elements after left, right, both,
the floating elements which flow around it. none, inherit
float It specifies whether the box should float or not. left, right, none,
inherit
Value Description
none It specifies that the element is not floated, and will be displayed just where
it occurs in the text. this is a default value.
<!DOCTYPE html>
<html>
<head>
<style> img
{ float:
right;
CSS Notes
}
</style>
</head>
<body>
<p>The following paragraph contains an image with style
<b>float:right</b>. The result is that the image will float to the right in the paragraph.<
/p>
CSS Font
CSS Font property is used to control the look of texts. By the use of CSS font property
you can change the text size, color, style and more. You have already studied how to
make text bold or underlined. Here, you will also know how to resize your font using
percentage.
1. CSS Font color: This property is used to change the color of the text. (standalone
attribute)
2. CSS Font family: This property is used to change the face of the font.
3. CSS Font size: This property is used to increase or decrease the size of the font.
4. CSS Font style: This property is used to make the font bold, italic or oblique.
6. CSS Font weight: This property is used to increase or decrease the boldness and
lightness of the font.
ADVERTISEMENT
o By a color name o By
hexadecimal value o By
RGB
<!DOCTYPE html>
<html>
<head>
<style> body
{ font-size:
100%;
CSS Notes
}
h1 { color: red; } h2 { color:
#9000A1; } p{
color:rgb(0, 220, 98); }
}
</style>
</head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<p>This is a paragraph.</p>
</body>
</html>
Output:
This is heading 1
This is heading 2
This is a paragraph.
specifies the font family name like Arial, New Times Roman etc.
Sans-serif: A sans-serif font doesn't include the small lines at the end of characters.
Example of Sans-serif: Arial, Verdana etc.
<!DOCTYPE html>
<html>
<head>
<style> body {
font-size: 100%;
}
h1 { font-family: sans-serif; }
h2 { font-family: serif; } p{
font-family: monospace; }
}
</style>
</head>
<body>
<h1>This heading is shown in sans-serif.</h1>
<h2>This heading is shown in serif.</h2>
<p>This paragraph is written in monospace.</p>
</body>
</html>
Output:
These are the possible values that can be used to set the font size:
Output:
<!DOCTYPE html>
<html>
}
h2 { font-style: italic; } h3
{ font-style: oblique; } h4
{ font-style: normal; }
}
</style>
</head>
<body>
<h2>This heading is shown in italic font.</h2>
<h3>This heading is shown in oblique font.</h3>
<h4>This heading is shown in normal font.</h4>
</body>
</html>
Output:
</style>
</head>
<body>
<h3>This heading is shown in normal font.</h3>
<p>This paragraph is shown in small font.</p>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<body>
<p style="font-weight:bold;">This font is bold.</p>
<p style="font-weight:bolder;">This font is bolder.</p>
<p style="font-weight:lighter;">This font is lighter.</p>
Output:
CSS Font-size
The font-size property in CSS is used to specify the height and size of the font. It affects
the size of the text of an element. Its default value is medium and can be applied to
every element. The values of this property include xx-small, small, x-small, etc.
Syntax
font-size: medium|large|x-large|xx-large|xx-small|x-small|small|;
Absolute-size
It is used to set the text to a definite size. Using absolute-size, it is not possible to
change the size of the text in all browsers. It is advantageous when we know the
physical size of the output.
Relative-size
It is used to set the size of the text relative to its neighboring elements. With relativesize, it
is possible to change the size of the text in browsers.
Font-size with pixels
When we set the size of text with pixels, then it provides us the full control over the size
of the text.
Example
<!DOCTYPE html>
<html>
<head>
<style>
#first { font-
size: 40px;
}
#second { font-
size: 20px;
}
</style>
</head>
<body>
</body>
</html>
Font-size with em
It is used to resize the text. Most of the developers prefer em instead of pixels. It is
recommended by the world wide web consortium (W3C). As stated above, the default
text size in browsers is 16px. So, we can say that the default size of 1em is 16px.
}
</style>
</head>
<body>
Example
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body>
</body>
</html>
font-size: length;
Example
<!DOCTYPE html>
<html>
<head>
<style>
.length {
color:red; font-
size: 5cm;
}
</style>
CSS Notes
</head>
<body>
<h1>font-size property</h1>
CSS font-family
HTML pages' look and formatting are specified using the language known as CSS
(Cascading Style Sheets). The `font-family` property in CSS is used to specify the
preferred font(s) for text content within an HTML element. The 'font-family' property is
broken down into primary and advanced ideas here:
1. Font Family Name: A font family name may be provided as a string value. For
instance:
The browser will try to utilize the Arial font in this situation. If Arial isn't accessible, a standard
sans-serif font will be used instead.
2. Generic Font Families: When typefaces are unavailable, one might fall back on one
of five generic font families. The following generic families:
1. Font Stacks: If the specified font is unavailable, you may provide alternative font
families. This is known as a font stack. For instance:
In this case, the browser will first attempt to apply the "Helvetica Neue" typeface. As such, it
will try to utilize Arial; if possible, it will turn back on a standard sans-serif font.
2. System Fonts: The system typefaces pre-installed on a user's device may be used
using CSS. You may instruct the browser to use the operating system's default font by
providing the general name of the font family. For instance:
p{
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
In this case, the browser will try to utilize the system's default fonts. It will utilize the
Apple system typeface on Apple-branded devices, San Francisco on macOS, and Segoe
UI on Windows.
3. Web Fonts: Custom fonts retrieved from a distant server rather than placed on the
user's device are called web fonts. To import and utilize web fonts in your CSS, use the
'@font-face' rule. For instance:
}
CSS Notes
This example uses the '@font-face' syntax to import the "MyWebFont" web font, which
is subsequently utilized in the 'font-family' property.
These are the fundamental concepts and more complex concepts around the
'fontfamily' property in CSS. One can manage the look and feel of the text on your
websites by using several font families.
1. Serif Fonts: Serif fonts include little artistic strokes or lines at the extremities of
the letters, referred to as serifs. They are regarded as more formal and
conventional and are often employed for body content in printed products.
5. Fantasy Fonts: Typefaces with beautiful and inventive flourishes are included in
the category of fantasy fonts. They are frequently utilized for imaginative and
artistic designs like logos, posters, and material with a fantastical theme. Unique
and unusual letterforms may be seen in fantasy typefaces, integrating symbols
or ornate motifs. Chiller, Jokerman, and Ravie are other examples.
CSS font weight is a property used in web development to control the thickness and
boldness of text within a webpage. It is used to define the weight of the text. The
available weight depends on the font family used by the browser.
It plays an important role in typography because it gives designers and programmers more
control over how text visually appears and emphasizes text elements.
PauseNext
Mute
Duration 18:10
Loaded: 0.37%
Â
Fullscreen
NOTE: Together with other CSS properties like font size, font family, and font style, the
font-weight property is frequently used to provide consistent text design throughout an
entire website.
Syntax and Property Values
The CSS font-weight property contains various property values for controlling the weight and
boldness of text and adheres to a specified syntax.
CSS Notes
Syntax:
1. font-weight: normal | lighter | bolder | bold | number | inherit |initial | unset; Property
Values:
o Normal: It is the default font weight whose numeric value is 400. It refers to the
standard weight for the selected font family.
o Lighter: It considers the existing font weight of the font family and makes the
font weight lighter than the parent element. Compared to the font weight of the
parent element, the font weight is lighter when the lighter value is used.
o Bolder:Contrarily, the bolder value makes the font weight heavier than the
parent element's font weight. It considers the existing font weight of the font
family and makes the font-weight heavier compared to the parent element.
o Bold: As its name implies, it defines the bold font weight, and its numeric value
is 700.
o Number: It sets the font weight based on the specified number. Its range can be
between 1 to 1000.
o Inherit: Using the inherent value, the font weight may inherit from its parent
element. It can be helpful when you want an element's font weight to match its
parent's.
o Unset: The unset value returns the font weight to its default normal or natural
value setting based on inheritance rules.
Specific HTML elements can have the font-weight attribute applied in CSS to modify
the text's weight and boldness. Doing so allows you to create various text styles and
p{
font-weight: normal; /* Sets the font weight to normal for all paragraphs */
}
In the example above, the default font weight, which is normal (often 400), will be used
for all paragraphs (<p>) within the HTML content. Example 2: Making Headings Bold
h1, h2, h3 { font-weight: bold; /* Sets the font weight to bold for h1, h2, and h3
headings */
This CSS rule sets the <h1>, <h2>, and <h3> elements' font-weight bold (often 700), causing
these headings to be displayed boldly.
/* Other CSS properties can also be combined here for comprehensive text styling *
/
}
The font weight, font size, and font-family properties are used in this example to style
the h4> headers. For the chosen elements, this develops a unified and consistent
typographic style.
When using CSS, you can target the body selector to apply a global font weight to the
entire document or just a portion. All web page text can have a uniform font weight
by applying the font-weight property to the body element.
This strategy can be helpful when you want to keep your website's visual design
consistent throughout.
Example 1:
This example applies the font-weight attribute to the body selector with a value of 400,
which stands for the standard (normal) font weight. This will guarantee that the font
weight of every text element inside the <body> tag is consistent and proper.
body { font-weight: 400; /* Sets the font weight to 400 for the entire
document */ h1 { font-weight: 700; /* Sets the font weight to 700 for all
h1 headings */
This example uses a global font weight for the entire document while applying various
font weights to specific HTML components. The rest of the content will use the global
font weight (400), with the headers (<h1>) having a bold font weight of 700 and the
paragraphs (<p>) having a softer font-weight of 300.
ADVERTISEMENT
Therefore, you can manage the overall appearance of text on your website by utilizing
the body selector to establish a universal font weight.
CSS's font-weight property can be used with other text-related properties to produce
font-family
p{
font-weight: 300; /*font-weight 300 for paragraphs */ font-family:
"Helvetica Neue", Arial, sans-serif; /* Applies a specific fontfamily to
paragraphs */
}
}
Here, all paragraphs (<p>) are given a custom font weight of 300 (a lighter style).
Furthermore, we designate a specific font family for paragraphs, which will impact the
font weight and overall look of the text. Example 2: Combining with font-size
For blockquotes in this illustration, the font-weight property is set to bold. In addition,
the line height property is changed to 1.5 times the font size. Example 4: Combining
with text-decoration
a{
font-weight: 500; /* font-weight 500 for anchor links */ text-
decoration: underline; /* Underlines anchor links */
For anchor links (<a>), we have specified a custom font weight of 500. The anchor links
are also underlined using the text-decoration attribute, helping them stand out and
be easier to recognize.
o Responsive Design: Take into account adjusting font weight for various screen
sizes. Ensure that the font-weight scales correctly for different viewports. What
may be readable on a wide screen may be difficult to read on smaller devices.
o Test with Screen Readers: Test your website using screen readers to make sure
that visitors who are blind can distinguish between different font weights. It's
crucial to ensure that the desired emphasis is properly communicated because
screen readers frequently announce the bold text. o Font Pairing: Pay attention
to font pairings when using various font weights. Readability may need to be
improved by some font choices that conflict or produce distracting visual
patterns.
Examples
<!DOCTYPE html>
<html>
<head>
}
p.one{
font-weight: normal;
}
p.two{ font-
weight: lighter;
p.three{ font-
weight: bolder;
p.four{ font-
weight: bold;
p.five{ font-
weight: 1000;
p.six{ font-
weight: initial;
}
p.seven{ font-
weight: inherit;
}
p.eight{ font-
weight: unset;
}
</style>
</head>
<body> <p
class="one"> normal
property value </p>
<p class="two">
lighter property value
</p>
<p class="three">
bolder property value
</p>
<p class="four">
bold property value
</p>
<p class="five">
number property value
</p>
<p class="six">
initial property value
</p>
<p class="seven">
inherit property value
</p>
<p class="eight">
unset property value
</p>
This CSS property only works for the fonts with additional faces like expanded and
condensed faces; otherwise, it will be affectless for the fonts that don't have condensed
or expanded faces.
The nine keyword values for choosing the width of the font-face are given in the following
syntax.
Syntax
font-stretch: normal | semi-condensed | condensed | extra-condensed | ultra-
condensed | semi-expanded | expanded | extra-expanded | ultra-expanded
Property Values
Example
<!DOCTYPE html>
<html>
<head>
<title>
CSS font-stretch Property
</title>
}
.normal { font-stretch:
normal;
}
.semi-condensed { font-stretch:
semi-condensed;
}
.condensed { font-stretch:
condensed;
}
.extra-condensed { font-stretch:
extra-condensed;
}
.ultra-condensed { font-stretch:
ultra-condensed;
.semi-expanded { font-stretch:
semi-expanded;
.expanded { font-stretch:
expanded;
}
.extra-expanded {
font-stretch: extra-expanded;
}
.ultra-expanded { font-stretch:
ultra-expanded;
}
</style>
</head>
<body>
<h1> Example of the font-stretch property </h1>
<div class = "normal">
normal </div>
</div>
<div class = "condensed"> condensed
</div>
</div>
</div>
<div class = "semi-expanded"> semi-expanded
</div>
</div>
</body>
</html>
Output
CSS Icons
Introduction
With the help of CSS icons, we can add icons to the HTML page from the icon library.
All the icons available in the icon library can be formatted using the CSS properties. We
can customize the icon based on size, color, shadow, etc. We can graphically represent
the icons used in size, color, shadow, etc. There are three types of icons available on
the internet. These are as follows.
We required the CDN link to make all the icons on the webpage. We can also customize
the predefined icons with the help of CSS.
Approach
To use the icons first, we must link the CDN link inside the <head> tag. To achieve this,
we have to follow the below steps.
o First, we have to add the name of the icon of the class in the HTML element. o
We can add the icons with the help of <i> and <span> elements.
o Then, we need all the icons to be customized with the required CSS
properties, such as size, color, shadow, etc.
We must follow the syntax below when adding icons to the web page.
Syntax:
<i class="fa fa-cloud"></i>
Example 1:
In the below example, we use the font property with each icon class & whose value is set
to 32px.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
.custom-icon:hover {
color: #ff0000; cursor:
pointer;
}
</style>
</head>
<body>
<h1>Welcome To javaTpoint</h1>
<i class="fa fa-cloud custom-icon"></i>
<i class="fa fa-heart custom-icon"></i>
<i class="fa fa-file custom-icon"></i>
<i class="fa fa-car custom-icon"></i>
<i class="fa fa-bars custom-icon"></i>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title> <link rel= "stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/4.7.0/css/fontawesome.min.css"> <style>
.red-icon {
color: red;
.blue-icon {
color: blue;
}
.green-icon {
color: green;
Syntax:
We must follow the syntax below to import the Google icon into our webpage.
<i class="material-icons">cloud</i>
Example 3:
In the below example, we will see the implementation of the "material-icons" class with the
required icon.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title> <link rel= "stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons">
}
</style>
</head>
<body>
<h1> Welcome to DigiTech </h1>
<i class="material-icons custom-icon">cloud</i>
<i class="material-icons custom-icon">favorite</i>
<i class="material-icons custom-icon">attachment</i>
<i class="material-icons custom-icon">computer</i>
Example 4:
In the below code, we will see the implementation of the "material-icons" class with the
cloud shape.
ADVERTISEMENT
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel= "stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
.custom-icon { margin: 10px; /* Add some margin
between icons */ cursor: pointer; /* Add a pointer
cursor on hover */
.red-icon {
color: red;
.blue-icon {
color: blue;
.green-icon {
color: green;
}
</style>
</head>
<body>
<h1> Welcome to DigiTech </h1>
<i class="material-icons custom-icon red-icon" style="font-size: 30px;">cloud</i>
<i class="material-icons custom-icon blue-icon" style="font-size: 40px;">cloud</i>
<i class="material-icons custom-icon green-icon" style="font-size: 50px;">cloud</i>
<i class="material-icons custom-icon red-icon" style="font-size: 60px;">cloud</i>
<i class="material-icons custom-icon blue-icon" style="font-size: 70px;">cloud</i>
<i class="material-icons custom-icon red-icon" style="font-size: 35px;">favorite</i>
<i class="material-icons custom-icon blue-icon" style="font-size: 45px;">favorite</i>
<i class="material-icons custom-icon green-icon" style="fontsize:
55px;">favorite</i>
Output:
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
Example 5:
In the below example, we have implemented the font-size property and all the glyph icon
class & all the value is set to different numbers.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title> <link rel= "stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.
css"> <style> .custom-icon { font-size: 32px;
color: #007bff; /* Custom color (blue) */ margin:
10px; /* Add some margin between icons */
</style>
</head>
<body>
<h1>Welcome to DigiTech</h1>
<i class="glyphicon glyphicon-cloud custom-icon"></i>
<i class="glyphicon glyphicon-user custom-icon"></i>
<i class="glyphicon glyphicon-thumbs-up custom-icon"></i>
<i class="glyphicon glyphicon-remove custom-icon"></i>
<i class="glyphicon glyphicon-envelope custom-icon"></i>
CSS Images
Images are an important part of any web application. Including a lot of images in a web
application is generally not recommended, but it is important to use the images
wherever they required. CSS helps us to control the display of images in web
applications.
The styling of an image in CSS is similar to the styling of an element by using the
borders and margins. There are multiple CSS properties such as
border property, height property, width property, etc. that helps us to style an image.
Thumbnail Image
The border property is used to make a thumbnail image.
Example
<!DOCTYPE html>
<html>
<head>
<style> img{
border: 2px solid red;
border-radius:5px;
padding:10px;
}
h2{ color:red;
}
</style>
</head>
<body>
<h1>Thumbnail Image</h1>
<img src="tp.png"></img>
<h2> Welcome to Digitech </h2>
</body>
</html>
Transparent image
To make an image transparent, we have to use the opacity property. The value of this
property lies between 0.0 to 1.0, respectively.
Example
<!DOCTYPE html>
<html>
<head>
<style> img{
border: 2px solid red;
border-radius:5px;
padding:10px;
opacity:0.3;
}
h2{ color:red;
}
</style>
</head>
<body>
<h1>Transparent Image</h1>
<img src="jp.png"></img>
<h2> Welcome to Digitech </h2>
</body>
Rounded image
The border-radius property sets the radius of the bordered image. It is used to create the
rounded images. The possible values for the rounded corners are given as follows:
Example
<!DOCTYPE html>
<html>
<head>
<style> #img1{
border: 2px solid green;
border-radius:10px;
padding:5px;
}
#img2{ border: 2px
solid green; border-
radius:50%;
padding:5px;
h2{ color:red;
}
</style>
</head>
<body>
<h1>Rounded Image</h1>
<img src="jtp.png" id="img1"></img>
<h2>Welcome to javaTpoint</h2>
<h1>Circle Image</h1>
<img src="p.png" id="img2"></img>
<h2> Welcome to Digitech </h2>
</body>
</html>
Responsive Image
It automatically adjusts to fit on the screen size. It is used to adjust the image to the specified
box automatically.
Example
<!DOCTYPE html>
<html>
<head>
<style> #img1{
max-width:100%;
height:auto;
}
h2{ color:red;
}
</style>
</head>
<body>
Center an Image
We can center an image by using the left-margin and right-margin property. We have to
set these properties to auto in order to make a block element.
Example
<!DOCTYPE html>
<html>
<head>
<style>
#img1{ margin-
left:auto; margin-
right:auto;
display:block;
}
h1,h2{ text-align:center;
}
</style>
</head>
<body>
<h1>Center image</h1>
<img src="dp.png" id="img1"></img>
<h2>Welcome to Digitech</h2>
</body>
</html>
CSS Important
This property in CSS is used to give more importance compare to normal property. The
!important means 'this is important'. This rule provides a way of making the Cascade
in CSS.
If we apply this property to the text, then the priority of that text is higher than other
priorities. It is to be recommended not to use this CSS property into your program until
it is highly required. It is because the more use of this property will cause a lot of
unexpected behavior.
If a rule is defined with this attribute, it will reject the normal concern in which the later
used rule overrides the previous ones. If we use more than one declaration marked
!important, then the normal cascade takes it over again. That means the new marked
!important will replace the previous one.
It increases the priority of the CSS property and ignores the overriding properties.
Syntax
... }
Example
Example
<!DOCTYPE html>
<html>
<head>
<style>
h1 { color:
white ;
}
body {
background-
color:lightblue
!important;
text-
align:center;
background-
color:yellow;
}
</style>
</head>
<body>
<h1>Hello World.</h1>
<h1>Welcome to the digitech. This is an example of <i>!important</i> proper
ty.</h1> <p></p>
</body>
</html>
In the above example, we can see that instead of pink, the background color of the
body is light blue because, in the body tag, the !important is applied after the light
blue background color.
Example
In this example, we are applying the !important attribute on the border of the text. The
color of the border of h1 heading will remain red despite of other declarations. The
color and border-color of heading h2 will remain green and violet despite of other
declarations.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style> body{
text-align: center;
}
h1 { border-color: red
!important; border: 5px
green solid; border-color:
black;
}
h2{ color: green !important;
color: red; border-color:violet
!important; border: 5px green
solid;
}
</style>
</head>
<body>
</body>
</html>
It defines the amount of space above and below inline elements. It allows you to set the
height of a line of independently from the font size.
value description
number It specifies a number that is multiplied with the current font size to set the
line height.
}
h3.big { line-
height: 200%;
}
</style>
</head>
<body>
<h3>
This is a heading with a standard line-height.<br>
This is a heading with a standard line-height.<br>
The default line height in most browsers is about 110% to 120%.<br>
</h3>
<h3 class="small">
This is a heading with a smaller line-height.<br>
This is a heading with a smaller line-height.<br>
This is a heading with a smaller line-height.<br>
This is a heading with a smaller line-height.<br>
</h3>
<h3 class="big">
This is a heading with a bigger line-height.<br>
This is a heading with a bigger line-height.<br>
This is a heading with a bigger line-height.<br>
This is a heading with a bigger line-height.<br>
</h3>
</body>
</html>
1. Unordered List: By default, the list elements in unordered lists are denoted with
bullets, which are tiny black circles.
2. Ordered List: The list elements in ordered lists are identified by numbers and letters.
The following CSS list properties are available for usage in controlling the CSS lists:
ADVERTISEMENT
o List-style-type:This property is used to determine the look of the list item marker,
such as a disc, character, or custom counter style.
o List-style-image: The pictures that will serve as list item markers may be specified
using this parameter.
o List-style-position: It describes where the marker box should be about the main
block box. o List-style: The list style is configured with this attribute.
List-style-type property
The default list type of marker may be changed to a variety of other types, including
square, circle, Roman numerals, Latin letters, and many more. The entries in an
unordered list are denoted by round bullets (•), while the items in an ordered list are
numbered by default using Arabic numerals (1, 2, 3, etc.).
PlayNext
Mute
/
Duration 18:10
Loaded: 2.94%
Â
Fullscreen
ADVERTISEMENT
The markings or bullets will be removed if we set their value to none.
Syntax:
list-style-type:value;
1. circle
3. decimal-leading-zeroes , eg :01,02,03,04,etc
4. lower-roman
5. upper-roman
8. square
Note: The default padding and margin are also included in the list. It is necessary to add
padding:0 and margin:0 to the <ol> and <ul> tags to eliminate this.
Example
This example shows a CSS List with several list-style types and values set to square and upper-
alpha and many.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Example for CSS Lists</title>
5. <style>
6. .num{
7. list-style-type:decimal;
8. }
9. .alpha{
54.
55. </body>
56. </html>
Output
It indicates whether the marker appears within or outside of the box holding the bullet points.
It has two values in it.
o Inside: This indicates that the list item will contain the bullet points. If the text in
this extends to the second line, it will wrap beneath the marker.
o Outside: It indicates that the list item's bullet points will be outside of it. It is a
default value.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>CSS Lists</title>
5. <style>
6. .num{
7. list-style-type:decimal;
8. list-style-position:inside;
9. }
10. .roman{
11. list-style-type:upper-roman;
12. list-style-position:outside;
13. }
14. .circle{
15. list-style-type:circle;
16. list-style-position:inside;
17. }
18. .disc{
19. list-style-type:disc;
20. list-style-position:inside;
21. }
The list may be styled using CSS. The lists can have custom backgrounds, padding, borders,
and colors.
The different stylistic properties are applied to the element in the CSS List described in
this example.
1. <!DOCTYPE html>
2. <html>
3.
4. <head>
5. <style>
6. ul.main {
7. list-style: circle;
8. background: lightblue;
9. padding: 30px;
10. width: 70px
11. }
12. </style> 13. </head>
14.
15. <body>
16. <h2>
17. Welcome
18. </h2>
19. <p> Unordered lists </p>
20. <ul class="main">
21. <li>one</li>
22. <li>two</li>
23. <li>three</li>
24. </ul> 25. </body>
26.
Output
HARSHAN DIGI TECH
Lists styled with colour
We may decorate lists with colors to make them more visually appealing and engaging.
Anything added to the <ul> or <ol> tags will affect the whole list. However, anything
added to a specific <li> tag will only affect that list's items.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Example for CSS Lists</title>
5. <style>
6. .order{
7. list-style: lower-alpha;
8. background: lightblue;
9. padding:20px;
10. width: 90px;
11. }
12. .order li{
13. background: pink;
14. padding: 20px;
15. font-size:10px;
16. margin:10px;
17. }
18. .unorder{
19. list-style: circle inside;
20. background: lightblue;
21. padding:20px;
22. width: 90px;
23. }
24. .unorder li{
25. background: pink;
26. color:black;
27. padding:10px;
28. font-size:10px;
29. margin:10px;
30. }
31.
32. </style>
33. </head>
34. <body>
35. <h1>
36. Welcome to the course
37. </h1>
38. <h2>
39. Ordered Lists
40. </h2>
41. <ol class="order">
42. <li>ONE</li>
43. <li>TWO</li>
44. </ol>
45. <h2>
46. Unordered lists
47. </h2>
48. <ul class="unorder">
49. <li>ONE</li>
50. <li>TWO</li>
51. </ul>
52.
53. </body>
54. </html>
Output
Top, bottom, left and right margin can be changed independently using separate
properties. You can also change all properties at once by using shorthand margin
property.
Property Description
margin This property is used to set all the properties in one declaration.
Value Description
length It is used to specify a margin pt, px, cm, etc. its default value is 0px.
<!DOCTYPE html>
<html>
<head>
<style>
p{ background-color:
pink;
}
p.ex { margin-top:
50px; margin-bottom:
50px; margin-right:
}
</style>
</head>
<body>
<p>This paragraph is not displayed with specified margin. </p>
<p class="ex">This paragraph is displayed with specified margin.</p>
</body>
</html>
Output:
4. margin 50px;
It identifies that:
top margin value is 50px right
<!DOCTYPE html>
<html>
<head>
<style>
p{ background-color:
pink;
}
p.ex { margin: 50px 100px 150px
200px;
}
</style>
</head>
<body>
<p>This paragraph is not displayed with specified margin. </p>
<p class="ex">This paragraph is displayed with specified margin.</p>
</body> </html>
Output:
It identifies that:
<!DOCTYPE html>
<html>
<head>
<style>
p{ background-color:
pink;
}
p.ex { margin: 50px 100px
150px;
}
</style>
</head>
<body>
<p>This paragraph is not displayed with specified margin. </p>
<p class="ex">This paragraph is displayed with specified margin.</p>
</body>
</html> Output:
It identifies that:
<!DOCTYPE html>
<html>
<head>
<style>
p{ background-color:
pink;
}
p.ex { margin: 50px
100px;
}
</style>
</head>
<body>
<p>This paragraph is not displayed with specified margin. </p>
<p class="ex">This paragraph is displayed with specified margin.</p>
</body>
</html> Output:
It identifies that:
<!DOCTYPE html>
<html>
<head>
<style>
p{ background-color:
pink;
}
p.ex { margin:
50px;
}
</style>
</head>
<body>
<p>This paragraph is not displayed with specified margin. </p>
<p class="ex">This paragraph is displayed with specified margin.</p>
</body> </html>
Output:
The main aim of the CSS rule is to make the webpage more responsive to deliver the
optimized design for the different screen sizes. With the help of media queries, we can
also specify the style for the screen readers.
Syntax:
We can write the media query with the help of the below syntax.
@media not|only media type and (media feature and|or|not media feature)
{
// CSS Property
}
Used Keywords
Below are some keywords that will be used while writing the media queries. These are as
follows.
o Note: With the help of this keyword, we can revert the entire media query.
o Only: With the help of this keyword, we can prevent the old browser from applying
the style property.
o And: With the help of this keyword, we can combine two media features and media
queries.
Media Types
There are different types of media available in the media query. These are as follows.
o Print: We can use this for printer devices. o Screen: We can use this for the mobile or
computer screen type, etc. o Speech: We can use this for the screen reader, which is
Media Features
Many features are being used for the media query. These are as follows. o
Any hover:
With the help of this, the user can hover over any element. o
Any-pointer:
With the help of this feature, we can perform a mechanism that is used for pointing
devices. o Any-ratio:
With the help of this, we can set the ratio between the width and height of the screen's
viewport.
o Color:
With the help of this, we can set the color for all the components of the output device.
o Color-gamut:
With the help of this, we can set the range for the color component that the output
Grid:
With the help of this, we can specify the number of rows and columns to be displayed on
the web page.
o Height:
With the help of this, we can set the height of the viewport which is going to be displayed on
the webpage.
o Hover:
With the help of this, the user can hover over any element. o
Inverted colors:
With the help of this, we can define the inverted colors for any of the devices. o
Light level:
With the help of this, we can define the level of the lights. o
max-aspect-ratio:
With this help, we can set the maximum height and width for displaying the viewport on
the web page.
o Max-color:
With the help of this, we can define the number of bits per color component that will
o Max-height:
With the help of this, we can set the maximum height for the display area of the browser.
o Max-monochrome:
With the help of this, we can define the maximum number of bits per color for the
monochrome devices.
o Max-resolution:
With the help of this, we can specify the maximum resolution to be displayed in the output
devices.
o Max-width:
With the help of this, we can set the maximum width for the display area of the browser.
o min-aspect-ratio:
With this help, we can set the minimum height and width for displaying the viewport on
the web page.
o Min-color:
With the help of this, we can define the minimum number of bits per color
With the help of this, we can define a minimum number of colors that the output devices can
display.
o Min-height:
With the help of this, we can set the minimum height for the display area of the
browser. o Min-resolution:
With the help of this, we can specify the minimum resolution to be displayed in the output
devices.
o Min-width:
With the help of this, we can set the minimum width for the display area of the browser.
o Monochrome:
With the help of this, we can provide the number of bits to display on the
With the help of this, we can set the viewport that it is going to display in landscape
With the help of this, we can control the situation when the content overflows the
viewport. o Overflow-inline:
With the help of this, we can control the situation when the content with an inline axis
With the help of this, we can create the primary input mechanism for a pointing device.
o Resolution:
With the help of this, we can set the resolution for the devices by taking the help of dpi or
PCM.
o Scan:
With the help of this, we can perform the scanning process for the devices. o
Update:
Width:
With the help of this, we can set the width of the viewpoint.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
margin: 0;
padding: 0;
}
}
</style>
</head>
<body>
<div class="content">
<h1>Hello, Media Query Example!</h1>
<p>This is an example of how to use @media rules to apply different styles based on
screen size.</p>
</div>
</body>
</html>
Output:
When the screen resolution is more than 764 px, the webpage looks like below.
With the help of a navigation bar, we can improve the presentation and styling of a
web page, and it also includes the design, colors, fonts, and spacing described using
CSS. A CSS navigation bar is developed and styled using CSS properties and rules to
produce a particular appearance and functionality.
o Links for navigation: The menu contains links to the site's various pages and
sections. These links frequently have button, text, or icon styling.
o Dropdown Menus: Dropdown menus are another feature that can be added to
navigation bars. Additional links or options are displayed when a user hovers
over or selects a menu item.
o Style: CSS lets designers alter the navigation bar's visual elements, such as
colors, fonts, borders, and hover effects. This aids in producing a unified and
visually appealing design that blends with the website's overall aesthetic.
With the help of a CSS navigation bar, we can enhance the user experience and make it
simple for visitors to navigate a website's content, so it is a crucial part of web design.
Example
Let's take a simple example of how we can create a horizontal navigation bar using CSS:
<!DOCTYPE html>
<html>
<head>
<style>
/* Basic styling for the navigation bar */
.navbar { background-color: #333; /*
Background color */ overflow: hidden; /* Clear
floats */
}
</style>
</head>
<body>
<div class="navbar">
<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#services">Services</a>
<a href="#portfolio">Portfolio</a>
<a href="#contact">Contact</a>
</div>
</body>
</html>
Output:
CSS Opacity
The CSS opacity property is used to specify the transparency of an element. In simple word,
you can say that it specifies the clarity of the image.
CSS filter
CSS filters are used to set visual effects to text, images, and other aspects of a webpage.
The CSS filter property allows us to access the effects such as color or blur, shifting on
the rendering of an element before the element gets displayed.
brightness()
As its name implies, it is used to set the brightness of an element. If the brightness is
0%, then it represents completely black, whereas 100% brightness represents the
original one. It can also accept values above 100% that provide brighter results.
Example
<!DOCTYPE html>
<html>
<head>
<title>CSS filter property</title>
<style>
body{ text-
align:center;
}
#img1 { filter:
brightness(130%);
}
</style>
</head>
<body>
<img src = "tiger.png" > <h2>Original Image </h2>
<img src = "tiger.png" id = "img1"> <h2>brightness(130%)</h2>
</body>
</html> blur()
It is used to apply the blur effect to the element. If the blur value is not specified, then
the value 0 is used as a default value. The parameter in blur() property does not accept
the percentage values. A larger value of it creates more blur.
Example
<!DOCTYPE html>
<html>
<head>
<title>CSS filter property</title>
}
#img1 {
filter: blur(2px);
}
</style>
</head>
<body>
<img src = "tiger.png" > <h2>Original Image </h2>
<img src = "tiger.png" id = "img1"> <h2>blur(2px)</h2>
</body>
</html> invert()
It is used to invert the samples in the input image. Its 100% value represents completely
inverted, and 0% values leave the unchanged input. Negative values are not allowed in
it.
Example
<!DOCTYPE html>
<html>
<head>
<title>CSS filter property</title>
<style>
body{ text-
align:center;
}
#img1 {
filter: invert(60);
}
</style>
</head>
<body>
<img src = "tiger.png" > <h2>Original Image </h2>
<img src = "tiger.png" id = "img1"> <h2>invert(60)</h2>
</body>
</html>
saturate()
It sets the saturation of an element. The 0% saturation represents the completely
unsaturated element, whereas the 100% saturation represents the original one. The
values greater than 100% are allowed that provides super-saturated results. We cannot
use negative values with this property.
Example
<!DOCTYPE html>
<html>
<head>
<title>CSS filter property</title>
<style>
body{ text-
align:center;
}
#img1 { filter:
saturate(40);
</html>
drop-shadow()
It applies the drop-shadow effect to the input image. The values it accepts are hshadow, v-
shadow, blur, spread, and color.
Example
<!DOCTYPE html>
<html>
<head>
<title>CSS filter property</title>
<style>
body{ text-
align:center;
}
#img1 { filter: drop-shadow(10px 20px
30px yellow);
}
</style>
</head>
<body>
<img src = "tiger.png" > <h2>Original Image </h2>
<img src = "tiger.png" id = "img1"> <h2> dropshadow(10px 20px
30px yellow);</h2>
</body>
</html>
contrast()
It adjusts the contrast of the input. Its 0% value will create a completely black image,
whereas the 100% values leave the unchanged input, i.e., represents the original one.
Values greater than 100% are allowed that provides results with less contrast.
Example
<!DOCTYPE html>
<html>
<head>
<title>CSS filter property</title>
<style>
body{ text-
align:center; }
#img1 { filter:
contrast(50%);
}
</style>
</head>
<body>
<img src = "tiger.png" > <h2>Original Image </h2>
<img src = "tiger.png" id = "img1"> <h2> contrast(50%)</h2>
</body>
opacity()
It is used to apply transparency to the input image. Its 0% value indicates completely
transparent, whereas the 100% value represents the original image, i.e., fully opaque.
Example
<!DOCTYPE html>
<html>
<head>
<title>CSS filter property</title>
<style>
body{ text-
align:center;
}
#img1 { filter:
opacity(40%);
}
</style>
</head>
<body>
<img src = "tiger.png" > <h2>Original Image </h2>
<img src = "tiger.png" id = "img1"> <h2> opacity(40%)</h2>
</body>
</html>
hue-rotate()
It applies a hue-rotation on the input image. Its perimeter value defines the number of
degrees around the color circle; the image will be adjusted. Its default value is 0 degree,
which represents the original image. Its maximum value is 360 degrees.
Example
<!DOCTYPE html>
<html>
<head>
<title>CSS filter property</title>
<style>
body{ text-
align:center;
}
#img1 { filter: hue-
rotate(240deg);
}
</style>
</head>
<body>
<img src = "tiger.png" > <h2>Original Image </h2>
<img src = "tiger.png" id = "img1"> <h2> hue-rotate(240deg)</h2>
</body>
</html>
grayscale()
It converts the input image into black and white. 0% grayscale represents the original one,
whereas 100% represents completely grayscale. It converts the object colors into 256
shades of gray.
<!DOCTYPE html>
<html>
<head>
<title>CSS filter property</title>
<style>
body{ text-
align:center;
}
#img1 { filter:
grayscale(80%);
}
</style>
</head>
<body>
<img src = "tiger.png" > <h2>Original Image </h2>
<img src = "tiger.png" id = "img1"> <h2> grayscale(80%)</h2>
</body>
</html>
sepia()
It is used to transform the image into a sepia image. 0% value represents the original image,
whereas the 100% value indicates the completely sepia.
Example
<!DOCTYPE html>
<html>
<head>
<title>CSS filter property</title>
<style>
body{ text-
align:center;
}
#img1 { filter:
sepia(90%);
}
</style>
</head>
<body>
<img src = "tiger.png" > <h2>Original Image </h2>
<img src = "tiger.png" id = "img1"> <h2> sepia(90%)</h2>
</body>
</html>
<!DOCTYPE html>
<html>
<head> <style> img.trans { opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
</style>
</head>
<body>
<p>Normal Image</p>
<img src="rose.jpg" alt="normal rose">
<p>Transparent Image</p>
<img class="trans" src="rose.jpg" alt="transparent rose">
</body>
Normal Image
Transparent Image
Note 1: Chrome, Firefox, Opera, Safari, and IE9 use the opacity property for
transparency. The opacity value ranges from 0.1 to 1.0. Lower value produces the greater
opacity.
Note 2: The older versions of IE use filter: alpha(opacity=x). Here x value varies from 0
to 100. Lower value produces the greater opacity.
CSS Padding
CSS Padding property is used to define the space between the element content and
the element border.
It is different from CSS margin in the way that CSS margin defines the space around
elements. CSS padding is affected by the background colors. It clears an area around
the content.
Top, bottom, left and right padding can be changed independently using separate
properties. You can also change all properties at once by using shorthand padding
property.
Property Description
Value Description
}
p.padding { padding-
top: 50px; padding-right:
100px; padding-bottom:
150px; padding-left:
200px;
}
</style>
</head>
<body>
<p>This is a paragraph with no specified padding.</p>
<p class="padding">This is a paragraph with specified paddings.</p>
</body>
</html>
Output:
There are ways to define position absolute, like top, bottom, left, and right when we
use position absolute. These attributes specify the element's distance from the
document or its nearest-positioned ancestor.
o Can overlap other elements: Because positioned elements are out of the
page's natural flow, they can overlap other elements. The "z-index" property
allows you to modify the order in which overlapping elements are stacked.
o A positioned element will scroll with the page if it is scrolled unless its position
is "fixed."
.container {
position: relative;
o Custom positioning: With absolute positioning, you are not limited by the
natural flow of elements and can position elements wherever you want on the
page. This can be helpful when designing intricate layouts or unique layouts
that require precise control over the placement of individual elements.
o Creating fixed elements: You can create elements that stay fixed in a particular
position on the screen, even when the page is scrolled, by combining "position:
absolute" with suitable values for the "top," "bottom," "left," or "right"
properties. This is frequently used for sidebars, headers, and fixed navigation
bars.
o Z-index and layering: With absolute positioning, you can manage how
elements are stacked using the "z-index" property. This helps you create layered
effects or manage the visibility of overlapping elements when you want certain
elements to appear above or below others.
CSS Vertical Align
The CSS vertical align property is used to define the vertical alignment of an inline or
table-cell box. It is the one of the self-explanatory property of CSS. It is not very easy
property for beginners.
What it does
1. It is applied to inline or inline-block elements.
2. It affects the alignment of the element, not its content. (except table cells)
3. When it applied to the table cells, it affect the cell contents, not the cell itself.
value description
baseline It aligns the baseline of element with the baseline of parent element.
This is a default value.
top It aligns the top of the element with the top of the tallest element on
the line.
It aligns the bottom of the element with the lowest element on the
bottom
line.
textbottom the bottom of the element is aligned with the bottom of the parent
element's font.
<!DOCTYPE html>
<html>
<head> <style>
img.top { vertical-align:
text-top;
}
img.bottom { vertical-align:
text-bottom;
}
</style>
</head>
<body>
<p><img src="goodmorning.jpg" alt="Good Morning Friends"/> This is an image
with a default alignme nt.</p>
<p><img src="good-
morning.jpg" class="top" alt="Good Morning Friends"/> This is an image with a text
-top alignment.</p> <p><img src="goodmorning.jpg" class="bottom"
alt="Good Morning Friends"/> This is an image with a text-bottom alignment.</p>
</body>
</html> Output:
CSS Width
The CSS width property is used to set the width of the content area of an element.
It does not include padding borders or margins. It sets width of the area inside the
padding, border, and margin of the element.
}
img.big {
width: 150px;
}
p.ex { height:
150px; width:
150px;
}
</style>
</head>
<body>
<img class="normal" src="good-morning.jpg" width="95" height="84"><br>
<img class="big" src="good-morning.jpg" width="95" height="84">
<p class="ex">The height and width of this paragraph is 150px.</p>
<p>This is a paragraph.</p>
This is a paragraph.
<!DOCTYPE html>
<html>
<head> <style>
img.normal {
width: auto;
}
img.big {
width: 50%;
}
img.small {
width: 10%; }
</style>
</head>
<body>
<img class="normal" src="good-morning.jpg" width="95" height="84"><br>
<img class="big" src="good-morning.jpg" width="95" height="84"><br>
<img class="small" src="good-morning.jpg" width="95" height="84">
</body>
</html> Output:
Note: You can also use the "min-width" and "max-width" property to control the size of
image.
It does not include padding borders or margins, whereas it sets the height of the area
inside the padding, border, and margin of the element. It can accept the length and
percentage values. But it does not allow negative values.
If we set the height to a numeric value (like in px, %, etc.), the content can be overflow
if it does not fit in the given height. We can manage the overflowing content by
defining the overflow property.
If the height of the container is not explicitly defined, and the element is not absolutely
positioned (i.e., position: absolute;), the value of height property is set to auto. The
min-height and max-height properties can also be used to control the size.
Now, we will see some of the examples to understand this property more clearly.
Example
Here, we are using the keyword value auto and the length values of height property
in px and em.
<!DOCTYPE html>
<html>
<head>
<style> #auto{
height: auto; width:
275px; border: 2px
solid blue; }
Value Description
auto It is a default value. Using this value browser is responsible for calculating the
height of the element. Negative values are not allowed.
length It specifies the height of an element using the length units such as px, cm, pt, etc.
Negative values are not allowed.
% It defines the height of the container in %. Negative values are not allowed.
} p{ font-size:
20px;
</style>
</head>
<body>
<div id ="auto">
<img src="jtp.png">
<p> Welcome to the Digitech.com </p>
</div>
<div id ="px">
</div><br>
<div id ="em">
<img src="p.png">
<p> Welcome to the Digitech.com </p>
</div>
</body>
</html>
Output
Example
<!DOCTYPE html>
<html>
<head>
<style> #per{
position: absolute;
width: auto; height:
65%; border: 2px solid
blue;
p{ font-size:
20px;
}
</style>
</head>
<body>
<div id ="per">
<img src="p.png">
<p> Welcome to the Digitech.com </p>
</div>
</body>
</html>
Output
Hover in CSS
What is CSS Hover?
The :hover selector in CSS applies styles to an element while the cursor hovers over it.
It's frequently employed to produce interactive effects or to draw attention to
elements when they're being interacted with.
You can target an element with the :hover selector using its tag name, class, or ID.
For Example:
.button:hover { background-
color: #ff0000;
color: #ffffff;
}
The background color in the previous example will turn red (#ff0000) when a user
hovers over an element with the class "button," while the text color will turn white
Various hover effects can be produced by combining the :hover selector with other
CSS elements like font size, border, or transform. It's a potent tool for boosting your
website or application's visual feedback and interactivity.
Syntax:
:hover { css
declarations;
Example 1:
HTML Code:
Code:
.hover-button {
background-color: #eaeaea; color:
#333333; padding: 10px 20px;
border: none; cursor: pointer;
transition: background-color 0.3s ease;
.hover-button:hover { background-
color: #ff0000;
color: #ffffff; }
Explanation:
In the above example, we have a button with a class hover-button. The button's initial
color combinations are a light grey background (#eaeaea) and dark grey text
(#333333). When the mouse hovers over the button, the background color changes to
red (#ff0000) and the text color to white (#ffffff).
With a duration of 0.3 seconds and an ease timing function, the transition property in
the hover-button class ensures a fluid transition for the background color change
when the mouse hovers over the button.
Other elements, such as links (<a>), images (<img>), divs (<div>), or any other
element you want to make interactive, can use similar hover effects. You can create
various hover effects suited to your design needs by changing the properties and
values within the :hover selector.
HTML Code:
<div class="image-zoom">
<img src="image.jpg" alt="Image">
</div>
CSS Code:
.image-zoom {
overflow: hidden; }
.image-zoom:hover img {
transform: scale(.2);
Code:
.underline-link { text-decoration:
none; transition: border-bottom 0.3s
ease;
.underline-link:hover { border-
bottom: 2px solid #ff0000;
o Support for Transitions and Animations: The :hover selector can be used with
CSS transitions and animations to produce slick, aesthetically pleasing effects.
By defining transition or animation properties, you can specify the duration,
timing function, and other animation-related settings to regulate how the styles
change when an element is hovered over.
o Adding Additional Selectors: The :hover selector can be used with other CSS
selectors to focus on particular elements or apply styles under predefined
criteria. For instance, you can create unique and tailored hover effects by
combining the :hover selector with class selectors, ID selectors, or
pseudoelements.
o Cross-Browser Support: Most modern web browsers support the CSS: hover
feature. It is a CSS specification component compatible with most widely used
browsers, including Chrome, Firefox, Safari, Edge, and others. This ensures
consistency in appearance and behaviour across different platforms.
HTML Layouts
HTML layouts provide a way to arrange web pages in well-mannered, well-structured,
and in responsive form or we can say that HTML layout specifies a way in which the
web pages can be arranged. Web-page layout works with arrangement of visual
elements of an HTML document.
Web page layout is the most important part to keep in mind while creating a website
so that our website can appear professional with the great look. You can also use CSS
and JAVASCRIPT based frameworks for creating layouts for responsive and dynamic
website designing.
Following are different HTML5 elements which are used to define the different parts
of a webpage.
<aside>: It is used to define content aside from the content (like a sidebar)
NOTE: HTML layouts create an individual space for every part of the web page. So that
every element can arrange in a significant order.
Description of various Layout elements
HTML <header>
The <header> element is used to create header section of web pages. The header
contains the introductory content, heading element, logo or icon for the webpage, and
authorship information.
Example:
HTML <nav>
The <nav> elements is a container for the main block of navigation links. It can contain
links for the same page or for other pages.
Example:
<nav style="background-color:#bcdeef;">
<h1 style="text-align: center;">Navgation Links</h1>
<ul>
<li><a href="#">link1</a></li>
<li><a href="#">link2</a></li>
<li><a href="#">link3</a></li>
<li><a href="#">link4</a></li>
</ul>
</nav>
HTML <section>
HTML <section> elements represent a separate section of a web page which contains
related element grouped together. It can contain: text, images, tables, videos, etc.
HTML <article>
The HTML
tag is used to contain a self-contained article such as big story, huge article, etc.
Example:
HTML <aside>
HTML <aside> define aside content related to primary content. The <aside> content must be
related to the primary content. It can function as side bar for the main content of web page.
Example:
<aside style="background-color:#e6e6fa">
<h2>Sidebar information</h2>
<p>This conatins information which will represent like a side bar for a webpage</p>
</aside>
HTML <footer>
HTML <footer> element defines the footer for that document or web page. It mostly contains
information about author, copyright, other links, etc.
Example:
<footer style="background-color: #f0f8ff; width: 100%; text-align: center;">
<h3>Footer Example</h3>
<p>© Copyright 2018-2020. </p>
</footer>
HTML <details>
HTML <details> element is used to add extra details about the web page and use can hide or
show the details as per requirement.
Example:
HTML <summary>
HTML <summary> element is used with the <details> element in a web page. It is used as
summary, captions about the content of <details> element.
Example:
<details>
<summary>HTML is acronym for?</summary>
<p style="color: blue; font-size: 20px;">Hypertext Markup Language</p>
</details>
element is designed to display tabular data. It is not good for a layout. Although first
creating a layout is easy, but if you want to change or redesign your website, then it
will be a complicated task.
Following is an example for the creation of a simple web page layout using HTML table.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
li{
display: inline-block;
padding: 10px;} a{
color:#20b2aa;
}
</style>
</head>
<body>
<!-- Header Section -->
<table width="100%" style="border-collapse:collapse;">
<tr>
<td colspan="2" style="background-color:#1a1a1a; text-align: center;">
<h3 style="font-size: 30px; color: #ff6a6a;">javaTpoint Table-layout</h3>
</td>
</tr>
<!-- Nav Section -->
<tr>
<td colspan="2" style="background-color:#666666;">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Menu</a></li>
<li><a href="#">About-us</a></li>
<li><a href="#">Contact us</a></li>
</ul>
</td>
</tr>
<!-- Main Section -->
<tr>
<td style="background-color:#e6e6fa; width:80%; height: 400px; textalign:
center;">
Note: This example is just for show you how to create layout using table but it's not
recommended to use table layout.
CSS Frameworks
CSS provides many frameworks like W3.CSS, Bootstrap, and many more, to create your
layout fast. Using CSS frameworks you can easily create a responsive and attractive
web layout. You just need to add a link for these frameworks, and you can use all
properties available in the framework.
CSS Float
You can create an entire web layout using CSS float property.
Advantage: It is very easy to learn and use. You just learn how the float and clear
properties work.
Disadvantage: Floating elements are tied to the document flow, which may harm the
flexibility.
Example:
<!DOCTYPE html>
<html>
<head> <style>
div.container { width:
100%; border: 1px
solid gray;
}
header, footer { padding:
1em; color: white;
background-color: #000080;
nav {
float: left;
max-width: 160px;
margin: 0; padding:
1em;
nav ul { list-style-
type: none; padding:
0;
nav ul a { text-
decoration: none;
}
article { margin-left:
170px; border-left: 1px
solid gray; padding: 1em;
overflow: hidden;
}
</style>
</head>
<body>
<header>
<h1>Tutorials Gallery</h1>
</header>
<nav>
<ul>
<li><a href="#">HTML</a></li> <li><a href="#">CSS</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</nav>
<article>
<h1>HTML</h1>
<p>HTML tutorial or HTML 5 tutorial provides basic and advanced concepts of html.
Our HTML tutorial is developed for beginners and professionals.</p>
<p>TML is an acronym which stands for Hyper Text Markup Language. Let's see wha
t is Hyper Text and what is Markup Language?</p>
</article>
<footer>Copyright © Copyright Digitech </footer>
</div>
</body>
</html>
CSS Flexbox
Flexbox is a new layout mode in CSS3.
Advantage: It ensures that the page layout must accommodate different screen sizes
and different display devices.
<!DOCTYPE html>
<html>
<head>
<style> .flex-container
{ display: -webkit-
flex; display: flex;
.flex-container > * {
padding: 15px; -webkit-
flex: 1 100%; flex: 1
100%;
.article { text-
align: left;
.nav {background:#eee;}
.nav ul { list-style-
type: none; padding:
0;
}
</style>
</head>
<body>
<div class="flex-container">
<header>
<h1>City Gallery</h1>
</header>
<nav class="nav">
<ul>
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</nav>
<article class="article">
<h1>HTML</h1>
<p>HTML tutorial or HTML 5 tutorial provides basic and advanced concepts of html.
Our HTML tutorial is developed for beginners and professionals.</p>
<p>TML is an acronym which stands for Hyper Text Markup Language. Let's see wha
t is Hyper Text and what is Markup Language?</p>
</body>
</html> Layout
using div
<!DOCTYPE html>
<html>
<head>
<title>Webpage using div</title>
<style>
body{
margin:0px;
}
.header{ padding:
10px; background-
color:#455e64; text-align:
center;
}
.header h2{
color: black; }
/*===============[Nav CSS]==========*/
.nav{
background-color:#243238;
padding: 5px;
}
.nav a{
color: #fff;
} .lside{
float: left; width: 80%;
min-height: 440px;
background-color: #f0f8ff;
text-align: center;
}
.rside
{ text-align: center;
float: right; width: 20%;
min-height: 440px;
background-color: #c1cdcd; }
.footer p{
color: #8fbc8f;
}
</style>
</head>
<body>
<div>
<div class="header">
<h2> Div Layout</h2>
</div>
<!-- Nav -->
<div class="nav">
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">MENU</a></li>
<li><a href="#">ABOUT</a></li>
<li><a href="#">CONTACT</a></li>
<li style="float: right;"><a href="#">LOGIN</a></li>
<li style="float: right;"><a href="#">SIGN-UP</a></li>
</ul>
</div>
o Vertical Offset (required): The height at which the shadow should be displaced
from the element. The shadow is moved up or down by a positive or negative
number. o Blur Radius (optional): This parameter controls how blurry the
shadow will be. The shadow will be more hazy the higher the value. The shadow
will display a sharp edge if the value is zero.
o Spread Radius (optional): The spread radius modifies the shadow's size. A
positive value makes the size larger, while a negative value makes it smaller. If
left out, the blur radius automatically calculates the shadow size.
o Color (optional): The shadow's color, if applicable. You may represent colors
using various methods, including named colors, RGB, HEX, or HSL values.
Output
/* Basic border shadow */ boxshadow: rgb(85, 91, 255) 0px 0px 0px 3px, rgb(31,
193, 27) 0px 0px 0px 6px, rgb(255, 217, 19) 0px 0px 0px 9px, rgb(255, 156, 85) 0px
0px 0px 12px, rgb(255, 85, 85) 0px 0 p x 0px 15px;
Output
Advanced Border Shadow Techniques
1. Multiple Shadows:
A single element can have many shadows applied to it, separated by commas. This
enables you to produce more complicated shadow effects. The above example can be
applied here.
2. Inset Shadows:
The element will appear to be pressed into the backdrop if the "inset" keyword is used
to produce an inner shadow impact.
A more distinct border-like shadow effect can be produced by utilizing a spread radius
that is not zero.
Additionally, you may create shadow effects by adding transitions or animations to the
box-shadow attribute.
@keyframes mymove {
50% {box-shadow: 10px 20px 30px blue;}
}
Output
h-shadow: It is the required value. It specifies the position of the horizontal shadow
and allows negative values.
v-shadow: It is also the required value that specifies the position of the vertical
shadow. It does not allow negative values. blur-radius: It is the blur-radius, which is
an optional value. Its default value is 0. color: It is the color of the shadow and also an
optional value. none: It is the default value, which means no shadow. initial: It is used
to set the property to its default value. inherit: It simply inherits the property from its
parent element.
<!DOCTYPE html>
<html>
<head>
<title> font-weight property </title>
<style>
p.simple{ text-shadow:
3px 3px red;
<body>
<p class="simple">
Simple Shadow
</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title> font-weight property </title>
<style>
p.fuzzy{ text-shadow: 3px
3px 3px violet; font-size:30px;
text-align:center;
}
</style>
</head>
<body>
<p class="fuzzy">
Fuzzy Shadow
</p>
</body>
</html>