wt unit2 css
wt unit2 css
wt unit2 css
• Inline CSS
• An inline CSS is used to apply a unique style to a single HTML element.
• An inline CSS uses the style attribute of an HTML element.
<body>
</body>
</html>
Internal CSS:
<!DOCTYPE html>
<html> This is a heading
<head>
<style>
body {background- This is a
paragraph.
color:
powderblue;}
h1 {color: blue;}
p {color: red;font-
size:40px;}
</style>
</head>
<body>
<h1>This is a
heading</h1>
<p>This is a
paragraph.</p>
</body>
</html>
External CSS:
An external style sheet is used to define the style for many HTML pages.
</body>
</html>
Block level Elements
The two most common display values are block and inline.
Block-level Elements
Example
<p>Hello World</p>
<div>Hello World</div>
Inline Elements
Example
<span>Hello World</span>
CSS properties:
CSS text Properties:
Property Description
text-
indent
Indents first line of paragraph.
line-
height
Sets space between lines.
<html>
<style>
.text
{
background-
color:yellow;
font-size:50px;
font-weight:bold;
text-
transform:uppercase;
text-align:center;
border-style:dotted;
word-spacing:30px;
letter-spacing:40px;
}
</style>
</head>
<div class="text">
welcome to
rkgit</div>
</body>
</html>
CSS Font Properties:
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.
CSS selectors are used to "find" (or select) the HTML elements
we want to style.
3.class selector 4.
5.
<!DOCTYPE html>
<html> paragraph will be
affected by the style.
<head>
<style> Me too!
p{
text-align: center; hello world
color: red;
}
</style>
</head>
<body>
<p>paragraph will be
affected by the
style.</p>
<p >Me too!</p>
<p>hello world</p>
</body>
</html>
2.ID selector: The id selector uses the id attribute of an HTML
element to select a specific element.The id of an element is
unique within a page, so the id selector is used to select one
unique element!
Id selector Output
</body>
</html>
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character,
followed by the class name.
<!DOCTYPE html>
<html> Red and center-aligned
heading
<head>
<style> Red and center-aligned
.center { paragraph.
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1
class="center">Red
and center-aligned
heading</h1>
<p class="center">Red
and center-aligned
paragraph.</p>
</body>
</html>
4.CSS UNIVERSAL SELECTOR:
The universal selector (*) selects all HTML elements on the page.
Example
The CSS rule below will affect every HTML element on the page:
*{
text-align: center;
color: blue;
}
The grouping selector selects all the HTML elements with the same
style definitions.
</body>
</html>
CSS Box Model
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:
• Content - The content of the box, where text and images appear
The box model allows us to add a border around elements, and to define
space between elements.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: lightgrey;
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
</style>
</head>
<body>
</body>
</html>
Output:
The CSS box model is essentially a box that wraps around every HTML
element. It consists of: borders, padding, margins, and the actual
content.
Output:
padding
The CSS margin properties are used to create space around elements,
outside of any defined borders.
With CSS, you have full control over the margins. There are properties
for setting the margin for each side of an element (top, right, bottom,
and left).
CSS Padding
The CSS padding properties are used to generate space around
an element's content, inside of any defined borders.
With CSS, you have full control over the padding. There are
properties for setting the padding for each side of an element
(top, right, bottom, and left).
</body> </body>
</html> </html>
Tables with CSS
<html>
<head>
<style>
table, th, td {
border: 1px solid;
background-color:red;
color:yellow;
}
</style>
</head>
<body>
<h2>Add a border to a table:</h2>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td> </tr>
</table>
</body>
</html>
output
Firstname Lastname
Peter Griffin
Lois Griffin
<html>
<head>
<style>
ul.a {
list-style-type: circle;
}
ul.b {
list-style-type: square;
}
ol.c {
list-style-type: upper-roman;
}
ol.d {
list-style-type: lower-alpha;
}
</style>
</head>
<body>
<ul class="b">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ol class="d">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
</body>
</html>
The <div> tag is used as a container for HTML elements - which is then
styled with CSS or manipulated with JavaScript.