WD Unit-3
WD Unit-3
SEMESTER: 1
(Unit -3 )
*Concept of CSS
What is CSS?
● CSS, or Cascading Style Sheets, is a language used to style and layout web pages by
controlling the visual appearance of HTML elements.
● CSS describes how HTML elements are to be displayed on screen, paper, or
in other media.
● CSS is used to define styles for your web pages, including the design, layout
and variations in display for different devices and screen sizes.
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
CSS Syntax:-
Example:-
<!DOCTYPE html>
<html>
<head>
<style> body {
Background-color: lightblue;
}
H1 {
Color: white;
Text-align: center;
}
P{
Font-family: verdana; font-size: 20px;
}
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
</style>
</head>
<body>
<h1>My First CSS Example</h1>
<p>This is a paragraph.</p>
</body>
</html>
Css selectors
SEMESTER: 1
3. ID Selector (#)
The ID selector targets an element with a specific ID. IDs should be unique
within a page.
<html>
<head>
<title>ID Selector Example</title>
<style>
/* Select the element with the id “unique” */
#h1 {
Font-size: 24px; /* Larger text for the element with id “unique” */
Color: red; /* Red text */
}
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
</style>
</head>
<body>
<h1 id=”h1”>This is a unique heading with larger red text.</h1>
<p>This paragraph is not affected by the ID selector.</p>
</body>
</html>
4. Grouping Selector:
The grouping selector is used to apply the same styles to multiple elements at
once. You can Group multiple selectors (tags, classes, IDs) together, separated by
commas, and apply a Common set of styles to them.
<html>
<head>
<title>Grouping Selector Example</title>
<style>
H1, p{
Font-family: Arial, sans-serif; /* Apply the same font to all */
Color: darkgreen; /* Apply dark green text color */
Font-size: 16px; /* Apply the same font size */
}
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph with the same styling as the heading.</p>
</body>
</html>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
Types of CSS
1.Inline CSS
Inline CSS is applied directly to an HTML element using the style attribute. It is
generally used for styling a single element.
Example:
<p style=”color: blue; font-size: 18px;”>This is inline CSS</p>
2. Internal CSS
Internal CSS is written within the <style> tag inside the <head> section of an
HTML document. It’s typically used when styling a single page.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
P{
Color: green;
Font-size: 20px;
}
</style>
</head>
<body>
<p>This is internal CSS</p>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
</body>
</html>
3.External CSS
External CSS is written in a separate .css file, and linked to the HTML document
using the <link> tag. This method is preferred for styling multiple pages
consistently.
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
Example:
Style.css
P{
Color: red;
Font-size: 22px;
}
Index.html
<!DOCTYPE html>
<html>
<head>
<link rel=”stylesheet” href=”style.css”>
</head>
<body>
<p>This is external CSS</p>
</body>
</html>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
*CSS Properties
1. Color
2. Text-align
3. Text-decoration
4. Text-transform
5. Text-shadow
6. Text-indent
Example
<html>
<head>
<title> TEXT PROPERTIES</title>
<style>
P
{ text-align: center;
Text-decoration: underline overline;
Text-shadow: 2px 2px red;
Text-transform: uppercase;
Text-indent: 30px;
}
</head>
<body>
<p> hello, bca semester-1</p>
</body>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
1.Background Styling
Definition: Background styling in CSS is used to set the background color, image, or gradient for
Elements on a webpage.
Common Properties:
Background-repeat: Controls if and how a background image repeats (e.g., horizontally or vertically).
Example:
<!DOCTYPE html>
<html>
<head>
<title>Background Styling Example</title>
<style>
Body {
Background-color: #f0f8ff; /* Light blue background */
}
Header {
Background-image: url(‘header-bg.jpg’); /* Add an image background */
Background-repeat: no-repeat; /* No repeating of the image */
Background-size: cover; /* Image covers the entire header */
Padding: 50px;
Text-align: center;
Color: white;
}
</style>
</head>
<body>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
<header>
<h1>Welcome to My Webpage</h1>
<p>This is the header tag. </p>
</header>
</body>
</html>
2. Text Formatting
Definition: Text formatting in CSS changes how text appears, including its color, alignment, decoration,
And transformations.
Common Properties:
Example:
<!DOCTYPE html>
<html>
<head>
<title>Text Formatting Example</title>
<style>
H1 {
SEMESTER: 1
3.Font Control
Definition: Font control in CSS allows you to choose the font style, size, and weight, making text look
More attractive and readable.
Common Properties:
Font-family: Sets the font type (e.g., Arial, Times New Roman).
Font-size: Sets the font size.
Font-weight: Controls how bold the text is (e.g., normal, bold, 100–900).
Font-style: Sets the style (e.g., normal, italic, oblique).
Example:
<!DOCTYPE html>
<html>
<head>
<title>Font Control Example</title>
<style>
P{
Font-family: Arial, sans-serif; /* Sets the font type */
Font-size: 20px; /* Sets font size */
Font-weight: bold; /* Makes the text bold */
Font-style: italic; /* Makes the text italic */
Color: #333; /* Dark color for readability */
}
</style>
</head>
<body>
<p>This paragraph demonstrates font control. The text is in Arial, bold, italic, and slightly larger than
The default font size.</p>
</body>
</html>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
Example:
<html >
<head>
<title>Block Elements Example</title>
<style>
.container {
Background-color: #f3f3f3;
Padding: 20px;
Width: 80%;
Margin: 0 auto;
}
.header, .content, .footer {
Margin: 10px 0; }
</style>
</head><body>
<div class=”container”>
<div class=”header”>
<h1>Welcome to My Website</h1>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
</div>
<div class=”content”>
<p>This is a sample paragraph in the main content area.</p>
</div>
<div class=”footer”>
<p>© 2024 My Website</p>
</div> </div></body>
</html>
●OBJECTS
●The CSS object-position property is used to specify how an <img> or
<video> should be positioned within its container.
Example:
<html>
<body>
<p style=”border: 1px solid black , object-fit: cover; object-position: 15% 100%;> Hello
World</p>
<div style=”border: 1px solid black”>Hello World</div>
<p>The P and the DIV elements are both block elements, and they will always start on a
new line and take up the full width available (stretches out to the left and right as far as it
can).
</p>
</body></html>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
<html>
<head>
<style> ul.a {
List-style-type: circle;
}
</style>
</head>
<body>
<h2>The list-style-type Property</h2>
<p>Example of unordered lists:</p>
<ul class=”a”>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul></body>
</html>
•To specify table borders in CSS, use the border property.
•The example below specifies a solid border for <table>, <th>, and <td> elements.
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
<!DOCTYPE html>
<html >
<head>
<title>Table Example</title>
<style>
Table {
Width: 50%;
Border-collapse: collapse;
}
Th, td {
Border: 1px solid #000;
Padding: 10px;
Text-align: left;
}
Th {
Background-color: #f3f3f3;
}
</style>
</head>
<body> <h2>Student Grades</h2>
<table>
<tr><th>Student Name</th>
<th>Grade</th>
</tr>
<tr>
<td>Alice</td>
<td>A</td> </tr>
<tr>
<td>Bob</td> <td>B+</td>
</tr>
<tr> <td>Charlie</td>
<td>A-</td>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
● In CSS, the term "box model" is used when talking about design and layout.
● The CSS box model is essentially a box that wraps around every HTML
element. It consists of: content, padding, borders and margins. The image
below illustrates the box model:
●Explanation of the different parts:
●Content – The content of the box, where text and images appear
●Padding – Clears an area around the content. The padding is transparent
●Border – A border that goes around the padding and content
●Margin – Clears an area outside the border. The margin is transparent
Example:-
<style>
Div {
Background-color: light-grey; width: 300px;
Border: 15px solid green; padding: 50px;
Margin: 20px;
}
</style>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
SEMESTER: 1
2.Display :-
● The display property is used to specify how an element is Shown on a
web page.
● Every HTML element has a default display value, depending On
what type of element it is. The default display value for Most elements
is block or inline.
● The display property is used to change the default display
Behavior of HTML elements.
Display Property Values :-
1. Inline :- Displays an element as an inline element
Ex :
Li {Display: inline;}
2. Block :- Displays an element as a block element
Ex :-
Span {
Display: block;
}
3.Positioning :-
The position property specifies the type of positioning method used for
An element.There are five different position values
● static
● relative
● fixed
● absolute
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
● sticky
Example :-
Div{
Position: sticky, fixed……;
Padding: 5px;
Background-color: #cae8ca;
Border: 2px solid #4CAF50;
}
4.Floating :-
The float property is used for positioning and formatting content e.g.
Let an image float left to the text in a container.
The float property can have one of the following values:
● left – The element floats to the left of its container
● right – The element floats to the right of its container
● none – The element does not float (will be displayed just where it
Occurs in the text). This is default
● inherit – The element inherits the float value of its parent
Example :-
Img {
Float: right;
}
5.Align :-
Set an alignment of the text.
Example :
Text-align: center;
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
6.Pseudo class :-
A pseudo-class is used to define a special state of an element.
For example, it can be used to:
● Style an element when a user moves the mouse over it
● Style visited and unvisited links differently
● Style an element when it gets focus
● Style valid/invalid/required/optional form elements
Example:
<html>
<head>
<style>
/* mouse over link */
A:hover {
Color: hotpink;
/* selected link */
A:focus {
Color: blue;
}</style>
</head>
<body>
<h2>Styling a link depending on state</h2>
<p><b><a href=”default.asp” target=”_blank”>This is a
link</a></b></p>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
</body>
</html>
7.Navigation bar:
Having easy-to-use navigation is important for any web site.
● With CSS you can transform boring HTML menus into good-
looking
navigation bars.
● A navigation bar needs standard HTML as a base.
● In our examples we will build the navigation bar from a standard
HTML list.
● A navigation bar is basically a list of links, so using the <ul> and
<li>
elements makes perfect sense:
Example :-
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css">
<title>Simple Navbar</title>
</head>
<body>
<nav class="navbar">
<div class="logo">MyLogo</div>
<ul class="nav-links">
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</body>
</html>
8.Image sprites:
● An image sprite is a collection of images put into a single image.
● A web page with many images can take a long time to load and
Generates multiple server requests.
● Using image sprites will reduce the number of server requests and
Save bandwidth.
Image Sprites – Simple Example
Instead of using three separate images, we use this single image
(“img_navsprites.gif”):
With CSS, we can show just the part of the image we need.
In the following example the CSS specifies which part of the
“img_navsprites.gif” image to show:
#home {
Width: 46px;
Height: 44px;
Background: url(img_navsprites.gif) 0 0;
}
9.Attribute selector :-
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
Example:-
<style>
A[target] {
Background-color: yellow;
}</style>
A[target=”_blank”] {
Background-color: yellow;
</style>
10.Grouping selector:
The grouping selector is used to apply the same styles to multiple
elements at once. You can Group multiple selectors (tags, classes, IDs)
together, separated by commas, and apply a Common set of styles to
them.
Example
<html>
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
<head>
<title>Grouping Selector Example</title>
<style>
H1, p{
Font-family: Arial, sans-serif; /* Apply the same font to all */
Color: darkgreen; /* Apply dark green text color */
Font-size: 16px; /* Apply the same font size */
}
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph with the same styling as the heading.</p>
</body>
</html>
}*CSS Color
● Colors are specified using predefined color names, or RGB, HEX, HSL,
RGBA, HSLA values.
● The color property specifies the color of text.
Example:
<!DOCTYPE html>
<head>
<title>CSS Color Example</title>
<style>
/* Using hexadecimal color */
H1 {
Course Code: 4040233136
Course Name: Web designing
using HTML
SEMESTER: 1
<body>
<details> - Defines additional details that the user can open and close on demand
SEMESTER: 1