Professional Documents
Culture Documents
CSS Lecture Slides 24102022 012810pm
CSS Lecture Slides 24102022 012810pm
What is CSS?
CSS stands for Cascading Style Sheets,
Design language intended to simplify the process of
making web pages presentable
handles the look and feel part of a web page
Advantages of CSS
Example:
<h1 style ="color:black;"> This is inline CSS </h1>
Output:
This is inline CSS
Internal Style Sheet
<head>
<style type="text/css">
Style Rules
............
</style>
</head>
Internal Style Sheet(Cont…)
Example:
<head>
<style type="text/css">
h1{
color: balck;
}
</style>
</head>
Output:
This is inline CSS
External Style Sheet
Example :
Consider a simple style sheet file with a name mystyle.css having the
following rules:
h1, h2, h3 {
color: black;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
External Style Sheet(Cont…)
Now you can include this file mystyle.css in any
HTML document as follows:
<head>
<link href="mystyle.css“ rel="stylesheet"/>
</head>
Priorities of Style Sheet
Inline
Internal
External
CSS Comments
/* This is an external style sheet file */
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}
/* end of style rules. */
Selectors
Class selector
Id selector
Descendant Selector
Child Selectors
Attribute Selectors
Grouping Selectors
Class selector
.red
{
color: red;
}
ul li
{
color: red;
}
Child Selectors
body > p
{
color: #000000;
}
background-color
background-image
background-repeat
background-position
background-attachment
background property
Set the Background Color
<p style="background-color:yellow;">
This text has a yellow background color.
</p>
Set the Background Image
<table
style="background-image:url(/images/pattern1.gif);">
<tr><td>
This table has background image set.
</td></tr>
</table>
Repeat the Background Image
<table
style="background-image:url(/images/pattern1.gif);
background-repeat: repeat;">
<tr><td>
This table has background image which repeats multiple
times.
</td></tr>
</table>
Repeat the Background
Image(Cont…)
Horizontally:
<table style="background-image:url(/images/pattern1.gif);
background-repeat: repeat-x;">
<tr><td>
This table has background image set which will repeat horizontally.
</td></tr>
</table>
Repeat the Background
Image(Cont…)
Vertically:
<table
style="background-image:url(/images/pattern1.gif);
background-repeat: repeat-y;">
<tr><td>
This table has background image set which will repeat
vertically.
</td></tr>
</table>
background-position
<table style="background-image:url(/images/pattern1.gif);
background-position:100px 200px;">
<tr><td>
This table has background image positioned 100
pixels away from the left and 200 pixels from the top.
</td></tr>
</table>
Set the Background Attachment
<p style="background-image:url(/images/pattern1.gif);
background-attachment:fixed;">
This parapgraph has fixed background image.
</p>
<p style="background-image:url(/images/pattern1.gif);
background-attachment:scroll;">
This parapgraph has scrolling background image.
</p>
CSS Fonts
CSS Fonts
font-family property
font-style property
font-variant property
font-weight property
font-size property
font-family property
<p style="font-family:georgia,garamond,serif;">
This text is rendered in either georgia, garamond, or the
default
serif font depending on which font you have at your system.
</p>
It will produce the following result:
font-style property
<p style="font-style:italic;">
This text will be rendered in italic style
</p> t-style:italic;">
Explore it by yourself
CSS Links
CSS Links
:link signifies unvisited hyperlinks.
:visited signifies visited hyperlinks.
:hover signifies an element that currently has the
user's mouse pointer hovering over it.
:active signifies an element on which the user is
currently clicking.
Explore it by yourself
CSS Tables
CSS Tables
border-collapse specifies whether the browser should control the
appearance of the adjacent borders that touch each other or whether
each cell should maintain its style.
border-spacing specifies the width that should appear between table
cells.
caption-side captions are presented in the <caption> element. By
default, these are rendered above the table in the document. You use
the caption-side property to control the placement of the table caption.
empty-cells specifies whether the border should be shown if a cell is
empty.
table-layout allows browsers to speed up the layout of a table by using
the first width properties it comes across for the rest of a column
rather than having to load the whole table before rendering it.
CSS Border
CSS Border
The border properties allow you to specify how the
border of the box representing an element should look.
There are three properties of a border you can change:
<a href="http://www.w3schools.com">w3schools.com</a>
<a href="http://www.wikipedia.org">wikipedia.org</a>
</body>
</html>
Mouse Hover Example Output
Position property in CSS
Static
Relative
Absolute
Fixed
sticky
Static positioning example
<div id="OuterDiv">
<h3>Machine Learning Testing: Survey, Landscapes and Horizons</h3>
<div id="InnerDiv">Inner div</div>
<p>This paper provides a comprehensive survey of Machine Learning
Testing (ML testing) research. It covers 138 papers on testing properties (e.g.,
correctness, robustness, and fairness), testing components (e.g., the data,
learning program, and framework), testing workflow (e.g., test generation and
test evaluation), and application scenarios (e.g., autonomous driving, machine
translation). The paper also analyses trends concerning datasets, research trends,
and research focus, concluding with research challenges and promising research
directions in machine learning testing.
</p>
</div>
Static positioning example
#OuterDiv{
margin-left:15px;
margin-top:10px;
background-color:red;
width:700px;
height:300px;
}
#InnerDiv{
background-color:green;
width:50px;
height:50px;
position:static;
}
h3{
position:static;
}
Findings
There is no change in page because by default each
item has position static as shown in output
And static position not take top, left etc. attributes
Relative positioning example
<div id="OuterDiv">
<h3>Machine Learning Testing: Survey, Landscapes and Horizons</h3>
<div id="InnerDiv">Inner div</div>
<p>This paper provides a comprehensive survey of Machine Learning
Testing (ML testing) research. It covers 138 papers on testing properties (e.g.,
correctness, robustness, and fairness), testing components (e.g., the data,
learning program, and framework), testing workflow (e.g., test generation and
test evaluation), and application scenarios (e.g., autonomous driving, machine
translation). The paper also analyses trends concerning datasets, research trends,
and research focus, concluding with research challenges and promising research
directions in machine learning testing.
</p>
</div>
Relative positioning example
#OuterDiv{
margin-left:15px;
margin-top:10px;
background-color:red;
width:700px;
height:300px;
}
#InnerDiv{
background-color:green;
width:50px;
height:50px;
position:static;
}
h3{
position:relative;
top:90px;
}
Findings
You can apply top, bottom, right and left property
on any item which having position relative
When apply top or any other with position relative
then this will no disturb other items position
Padding will disturb all the items position
Output
Absolute positioning example
<div id="OuterDiv">
<h3>Machine Learning Testing: Survey, Landscapes and Horizons</h3>
<div id="InnerDiv">Inner div</div>
<p>This paper provides a comprehensive survey of Machine Learning
Testing (ML testing) research. It covers 138 papers on testing properties (e.g.,
correctness, robustness, and fairness), testing components (e.g., the data,
learning program, and framework), testing workflow (e.g., test generation and
test evaluation), and application scenarios (e.g., autonomous driving, machine
translation). The paper also analyses trends concerning datasets, research trends,
and research focus, concluding with research challenges and promising research
directions in machine learning testing.
</p>
</div>
Absolute positioning example
body{background-color:aqua;}
#OuterDiv{
margin-left:15px;
margin-top:10px;
background-color:red;
width:700px;
height:300px;
position:relative;}
#InnerDiv{
background-color:green;
width:50px;
height:50px;
position:absolute;
top:0px;
left:0px;}
Findings
• Element having absolute position will release its actual
space
• And start location from its parent element which who
have position relative, absolute or fixed
• Can apply top, bottom, left or right properties on that
elements
Output