CSS
CSS
Syntax
Selector
{
Property: value;
Property: value;
Property: value;
Property: value;
}
Inline CSS: Inline CSS is used within the tag having style as attribute.
Syntax:
<p style=”color:red; background-color:green; text-align:justify;”> . . .
</p>
Internal CSS: Internal CSS is used within the <head> . . . </head> part having
style as internal tag.
Syntax:
<head>
<style>
p
{
color:red;
background-color:green;
text-align:justify;
}
</style>
</head>
<body>
<p> . . . </p>
</body>
External CSS: External CSS is written in a separate file having ‘.css’ extension.
All styles should be written one after another and the same file should be
linked with the ‘.html’ file in <head> . . . </head> part.
Syntax A: The file – mystyle.css
p
{
color:red;
background-color:green;
text-align:justify;
}
CSS Class: A CSS class is a kind of identifier for a group of similar tags or
elements.
For ex. - Many <p> elements can be given a common class parastyle1 thereby
enabling all those paragraphs to be stylized using the CSS of class parastyle1.
Syntax:
<head>
<style>
.parastyle1
{
color:red;
background-color:green;
text-align:justify;
}
</style>
</head>
<body>
<p class=”parastyle1”> . . . </p>
<p> . . . </p>
<p class=”parastyle1”> . . . </p>
</body>
For ex. – A certain <p> element can be given a particular ID parastyle1 thereby
enabling that only paragraph to be stylized using the CSS of ID parastyle1.
Syntax:
<head>
<style>
#parastyle1
{
color:red;
background-color:green;
text-align:left;
}
#parastyle2
{
color:green;
background-color:red;
text-align:right;
}
</style>
</head>
<body>
<p id=”parastyle1”> . . . </p>
<p> . . . </p>
<p id=”parastyle2”> . . . </p>
</body>
NOTE: While writing a style, classes are written with a dot (.) whereas IDs are
written with a hash (#).
3. CSS on Body
CSS designs the <body> element in the following ways-
Before we start with CSS on Links, we must understand the four states of a link.
These are:
For every state, we can develop a style. The most important thing is to keep
the order of these states always, as they are.
<div style="overflow-x:auto;">
<table>
... table content ...
</table>
</div>
Input, textarea,
box-sizing border-box; element sizing
select
Input, textarea,
border 1px solid #ddd; Border of element
select
border-bottom
border-top Input, textarea, Particular border of
1px solid #ddd;
border-left select element
border-right
Display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
max-width: 100%;
height: auto;
Code:
<html>
<head>
<style>
*{
box-sizing: border-box;
}
body {
margin: 0;
}
/* Style the header */
.header {
background-color: #f1f1f1;
background-image:url('img/head2.jpg');
repeat:xy;
padding: 20px;
text-align: center;
}
/* Style the top navigation bar */
.topnav {
overflow: hidden;
background-color: #333;
}
/* Style the topnav links */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Change color on hover */
.topnav a:hover {
background-color: #ddd;
opacity:0.5;
color: black;
}
/* Style the left sidebar */
.column1 {
background-color:gray;
width:20%;
height:700px;
display:inline-block;
}
/* Style the Main Section */
.column2 {
background-color:lavender;
background-image:url('img/back2.jpg');
repeat:xy;
float:right;
width:80%;
height:700px;
display:inline-block;
}
/* Style the Sidebar Links */
.column1 a{
display: block;
color: #f2f2f2;
text-align: center;
padding: 0;
text-decoration: none;
}
</style>
</head>
<body>
<div class="header">
<h1>Header</h1>
<p>Resize the browser window to see the responsive effect.</p>
</div>
<div class="topnav">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>
<div class="column1">
<h2 style="background-color:black; display:block;color:white;">Column1</h2>
<a href="#">Link 1</a><br>
<a href="#">Link 2</a><br>
<a href="#">Link 3</a><br>
</div>
<div class="column2">
<h2 style="background-color:#ddd; display:block;color:black;">Column2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium
urna. Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique. Quisque
vehicula, risus eget aliquam placerat, purus leo tincidunt eros, eget l</p>
</div>
</body>
</html>