CSSTYPES
CSSTYPES
CSS Style Rule Syntax as follows − ➢ The selector points to the HTML element you want to style.
selector { property: value; property: value; } ➢ The declaration block contains one or more declarations
separated by semicolons(;).
➢ p is a selector in CSS (it points to the HTML element you want to style: <p>).
➢ color is a property, and red is the property value
➢ text-align is a property, and center is the property value
Three ways to apply CSS:
To use CSS with HTML document, there are three ways:
➢ Inline CSS: Define CSS properties using style attribute in the HTML elements.
➢ Internal or Embedded CSS or Document Styles: Define CSS using <style> tag in <head> section.
➢ External CSS: Define all CSS property in a separate .css file, and then include the file with HTML file
using tag in section.
1.Inline CSS:
G.Syntax: <element style=“style rules”>
➢ Inline CSS is used to apply CSS in a single element.
Example: <h1 style=“color:red ; text-align:center; ” > hello <h1>
➢ It can apply style uniquely in each element.
➢ To apply inline CSS, you need to use style attribute within HTML element.
➢ We can use as many properties as we want, but each property should be separated by a semicolon (;).
<!DOCTYPE html>
<html>
<head> <title></title> </head> Output:
<body> Learning HTML using Inline CSS
<h3 style="color: red;” > Learning HTML using InlineCSS </h3>
<p style=“color:red;”> paragraph</p>
</body>
</html>
INLINE STYLE
Example of inline Style:
<!DOCTYPE html>
<html>
<head> <title></title> </head>
<body>
<h3 style="color: red; font-style: italic;text-align: center;font-size: 50px; “ >
Learning HTML using Inline CSS</h3>
<p >My first paragraph with out style</p>
<p style=“color:blue;margin-left:40px;>My second paragraph with style</p>
</body>
</html>
➢ The <link> tag defines the relationship between the current document and an external resource.
➢ The <link> tag is most often used to link to external style sheets.
Link tag Attributes:
➢ href: Specifies the location of the linked document
➢ Type: Specifies the media type of the linked document
➢ Rel: Required. Specifies the relationship between the current document and the linked
document
HTML File name: externalex.html CSS file name: style.css
!DOCTYPE html> File1 body{
<html> background-color:lavender;
<head> text-align: center;
<link rel="stylesheet" type="text/css" href="style.css"> }
</head> h2{
<body> font-style: italic;
<h2>Learning HTML with External CSS</h2> size: 30px;
color: #f08080; File2
<p class="blue">This is a blue color paragraph</p>
}
<p class="red">This is a red color paragraph</p> p{
<p class="green">This is a green color paragraph</p> font-size: 20px;
</body> }
</html>
.blue{
color: blue;
}
.red{
color: red;
}
.green{
color: green;
}
Import rule:@import:
Import the "navigation.css" style sheet into the current style sheet:
@import "navigation.css"; /* Using a string */
Or
@import url("navigation.css"); /* Using a url */
<html>
<head>
<style type=“text/css”>
@import url("navigation1.css");
@import url("navigation2.css");
</style>
</head>
<body>
</body>
</html>
Example to represent the hierarchy of CSS:
<!DOCTYPE HTML> Followings are default CSS styles applicable hierarchy.
<html>
<head> •Inline style (specified within the element using style attribute).
<title> CSS !important</title> •Internal style sheet (specified within the STYLE element/tag).
<style>
p{ •External style sheet (using link attribute, external style sheet to be attached).
background-color:green; Inline level style has highest priority by default and applicable to the
color:white; element first.
}
div p { Output
background-color:yellow;
color:black;
}
</style>
</head>
<body>
<p>Page level style applied</p>
<p style="background-color:red;">Element level style applied</p>
<p>Page level style applied</p>
<div>
<p>Page level style applied </p>
</div>
</body>
</html>
CSS Selector
➢ CSS selectors are used to select the content you want to apply style.
➢ Selectors are the part of CSS rule set.
➢ CSS selector does the following works.
❖ CSS selectors select HTML elements according to its id, class, type, attribute etc.
❖ Apply specified CSS properties.
There are several different types of selectors in CSS.
1. CSS Element Selector
2. CSS Class Selector
3. CSS Id Selector
4. Descendent Selector
5. Child Selector
6. CSS Universal Selector
7. Adjacent sibling selector
8. CSS Group Selector
9. Attribute Selector
10. Pseudo – Classes
11. Pseudo-element
1. CSS Element Selector
➢ The most commonly and easy to use selector are Type Selector or Element Selector.
➢ Element selector select any XHTML element on a page that matches the selector regardless of their
position in the document tree.
<!DOCTYPE HTML>
p{ <html>
font-weight:bold; <head>
} <title> CSS Element Selector</title>
<style>
p{
font-weight:bold;
}
</style>
</head>
<body>
<div>Div element</div>
<p>Para(p) element1 </p>
<p>Para(p) element2 </p>
<ul>
<li> List item(li) element </li>
Output <li> List item (li) element </li>
</ul>
</body>
</html>
2. Class Selector:
➢ Class selectors can be used to select any XHTML element that has a class attribute regardless of their
position in the document tree
➢ CSS class selector name starts with “.” followed by class name.
G.Syntax: Example:
.class name .firstitem {
{ font-weight:bold;
css rules; color:blue;
} }
Example:
<body>
<h3 class=“firstitme”>BCA Department</h3>
<p class=“firstitem”> BCA course is of six semesters, spread across three years<p>
<p class=“f”> BSc course is of six semesters, spread across three years<p>
<p > BSc course is of six semesters, spread across three years<p>
</body>
<!DOCTYPE html>
<html>
<head>
<style>
/*Internal CSS using class name*/
.bl{color: blue;}
.rd{color: red;}
.gn{color: green;}
</style>
</head>
<body>
<h2>Learning HTML with internal CSS</h2>
<p style=“color:yellow;”>p tag</p>
<p class="bl">This is a blue color paragraph</p>
<p class="rd">This is a red color paragraph</p>
<p class="gn">This is a green color paragraph</p>
<h2 class="bl"> header two</h2>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<title> CSS Class Selector</title> Above example,
<style>
.heading {
Sets text color green to CSS class “.heading” applied H1
color:green;
}
element.
.firstItem { Sets text color red to CSS class “.firstItem” applied two P
color:red; elements.
}
</style>
</head> Output
<body>
<h1 class="heading">Class selector</h1>
<div>
<p class="firstItem">P element - Group 1</p>
<p>P element - Group 1</p>
</div>
<div>
<p class="firstItem">P element - Group 2</p>
<p>P element - Group 2</p>
</div>
</body> </html>
3. ID Selector
➢ Selects element which has a specified ID name/ID as an attribute.
➢ CSS ID selector name starts with “#” followed by ID name.
➢ Note: ID name to be unique in a web page.
G.Syntax: Example:
#idname #p1 {
{ border:groove;
css rules }
}
Example:
<body>
<h3 class=“firstitme”>BCA Department</h3>
<p id=“p1”> BCA course is of six semesters, spread across three years<p>
<p class=“firstitem”> BSc course is of six semesters, spread across three years<p>
<p > BSc course is of six semesters, spread across three years<p>
</body>
Example of Id Selector:
Above example,
<!DOCTYPE HTML>
•Sets text color green to element with ID “headerElement”.
<html>
•Sets text color red to element with ID “firstElement”.
<head>
<title> CSS ID Selector</title>
<style>
#headerElement {
color:green;
}
#firstElement {
color:red;
}
</style>
</head>
<body>
<h1 id="headerElement">ID selector</h1>
<p id="firstElement">P element 1</p>
<p>P element 2</p>
</body>
</html>
<!DOCTYPE HTML>
4.Descendant Selector
<html>
Selects all specified descendant child elements under the <head>
parent element. <title> CSS Descendant Selector</title>
<style>
div p { div#divA p {
text-decoration:underline; background-color:lightgreen;
} }
</style>
</head>
Above example sets font background color green to all <body>
decedent P child elements under the DIV parent <div id=“divA”>
element (<div id="divA">) <p>Level1 : Descendant and child element 1</p>
<p>Level1 : Descendant and child element 2</p>
<div>
<p>----Level2 : Descendant element 11</p>
<p>----Level2 : Descendant element 12</p>
</div>
<div>
<p>----Level2 : Descendant element 21</p>
<p>----Level2 : Descendant element 22</p>
</div>
<p>Level1 : Descendant element 3</p>
</div>
</body>
</html>
Descendant Selector
<!DOCTYPE html>
<html>
<head>
<style>
div p {
background-color: yellow;
}
</style>
</head>
<body>
<h2>Descendant Selector</h2>
<div>
<p>Paragraph 1 in the div.</p>
<p>Paragraph 2 in the div.</p>
<section><p>Paragraph 3 in the div.</p></section>
</div>
</body>
</html>
Descendant
➢ A descendant refers to any element that is connected but lower down the document tree - no matter
how many levels lower.
➢ In the diagram below, all elements that are connected below the <div> element are descendants of
that <div>.
Parent and Child
➢ A parent is an element that is directly above and connected to an element in the
document tree. In the diagram below, the <div> is a parent to the <ul>.
➢ A child is an element that is directly below and connected to an element in the document
tree. In the diagram above, the <ul> is a child to the <div>.
Sibling
A sibling is an element that shares the same parent with another element.
In the diagram below, the <li>'s are siblings as they all share the same parent - the <ul>.
5. Child Selector <!DOCTYPE HTML>
➢ The child selector selects all elements that are the children <html>
of a specified element. <head>
<title> CSS Child Selector</title>
➢ The > symbol should be used
<style>
div#divA > p {
div > p { background-color:lightgreen;
color:red; }
} </style>
</head>
Above example sets font background color green to <body>
immediate P child elements under the DIV parent <div id="divA">
element (<div id="divA">). <p>Level1 : Descendant and child element 1</p>
<p>Level1 : Descendant and child element 2</p>
<div>
<p>----Level2 : Descendant element 11</p>
<p>----Level2 : Descendant element 12</p>
</div>
<div>
<p>----Level2 : Descendant element 21</p>
<p>----Level2 : Descendant element 22</p>
</div>
<p>Level1 : Descendant element 3</p>
</div>
</body>
</html>
Child Selector
6. Adjacent Sibling Selector
➢ The adjacent sibling selector is used to select an <!DOCTYPE HTML>
element that is directly after another specific
<html>
element.
➢ Sibling elements must have the same parent <head>
element, and "adjacent" means "immediately <title> CSS Adjacent Sibling Selector </title>
following". <style>
➢ The following example selects the first <p> div#divb + p+p {
element that are placed immediately after <div> background-color:lightgreen;
elements: }
➢ to an adjacent element. </style>
Example: </head>
div + p +p{ <body>
font-size:25px; <div id="divb">
} <p>P element with in DIV element - 1</p>
<p>P element with in DIV element - 2</p>
Above example sets text color light green to P element </div>
which is next to DIV element with ID “divb” (<div <p>Adjacent Sibling Selectors - P element next to DIV</p>
id="divb">).
<p>P element - 4 </p>
</body>
</html>
<html> <head>
<style>
div + p {
background-color: yellow; Adjacent Sibling Selector
} The + selector is used to select an element that is directly
</style>
</head> after another specific element.
<body> The following example selects the first p element that are
<h2>Adjacent Sibling Selector</h2> placed immediately after div elements:
<p>The + selector is used to select an element that is directly after another
Paragraph 1 in the div.
specific element.</p> Paragraph 2 in the div.
<p>The following example selects the first p element that are placed immediately Paragraph 3. After a div.
after div elements:</p> Paragraph 4. After a div.
<div> Paragraph 5 in the div.
<p>Paragraph 1 in the div.</p> Paragraph 6 in the div.
<p>Paragraph 2 in the div.</p> Paragraph 7. After a div.
</div>
Paragraph 8. After a div.
<p>Paragraph 3. After a div.</p>
<p>Paragraph 4. After a div.</p>
<div>
<p>Paragraph 5 in the div.</p>
<p>Paragraph 6 in the div.</p>
</div>
div ~ p {
background-color: yellow;
}
<html>
<head>
<style>
div ~ p {
background-color: yellow;
}
</style>
</head>
<body>
<p>The general sibling selector (~) selects all elements that are
next siblings of a specified element.</p>
<p>Paragraph 1.</p>
<div>
<p>Paragraph 2.</p>
</div>
<p>Paragraph 3.</p>
<p>Paragraph 4.</p>
</body> </html>
CSS [attribute] Selector
➢ The [attribute] selector is used to select elements with a specified attribute.
➢ The following example selects all <a> elements with a target attribute:
<html>
a[target] { <head>
background-color: yellow; <style>
} a[target] {
background-color: yellow;
}
</style>
</head>
<body>
<a href="https://www.w3schools.com">w3schools.com</a>
<a href="http://www.disney.com" target="_blank">disney.com</a>
<a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>
</body> </html>
CSS [attribute="value"] Selector
➢ The [attribute="value"] selector is used to select elements with a specified attribute and value.
➢ The following example selects all <a> elements with a target="_blank" attribute:
a[target="_blank"] {
background-color: yellow; <html>
} <head>
<style>
a[target="_blank"] {
background-color: yellow;
}
</style>
</head>
<body>
<a href="https://www.w3schools.com">w3schools.com</a>
<a href="http://www.disney.com" target="_blank">disney.com</a>
<a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>
</body>
</html>
CSS [attribute ~= "value"] Selector
The [attribute~="value"] selector is used to select elements with an attribute value containing a specified
word.
The following example selects all elements with a title attribute that contains a space-separated list of
words, one of which is "flower":
[title~="flower"] {
border: 5px solid yellow;
}
<html> Example: for [attribute~=“value”]
<head>
<style>
[title~="flower"] {
border: 5px solid yellow;
}
</style>
</head>
<body>
</body> </html>
CSS [attribute|="value"] Selector
➢ The [attribute|="value"] selector is used to select elements with the specified attribute, whose
value can be exactly the specified value, or the specified value followed by a hyphen (-).
➢ Note: The value has to be a whole word, either alone, like class="top", or followed by a
hyphen( - ), like class="top-text".
<html>
<head>
<style>
[class|="top"] {
background: yellow;
}
</style>
</head>
<body>
<h1 class="top-header">Welcome</h1>
<p class="top-text">Hello world!</p>
<p class="topcontent">Are you learning CSS?</p>
</body>
</html>
CSS [attribute^="value"] Selector
➢ The [attribute^="value"] selector is used to select elements with the specified attribute, whose value starts with the
specified value.
➢ The following example selects all elements with a class attribute value that starts with "top":
<!DOCTYPE html>
<html>
<head>
<style>
[class^="top"] {
background: yellow;
}
</style>
</head>
<body>
<h1 class="top-header">Welcome</h1>
<p class="top-text">Hello world!</p>
<p class="topcontent">Are you learning CSS?</p>
</body>
</html>
CSS [attribute*="value"] Selector: end with a word
➢ The [attribute*="value"] selector is used to select elements whose attribute value contains a specified value.
➢ The following example selects all elements with a class attribute value that contains "te":
<!DOCTYPE html>
<html>
<head>
<style>
[class*="te"] {
background: yellow;
}
</style>
</head>
<body>
</body>
</html>
Anchor Pseudo-classes
Links can be displayed in different ways:
/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
/* selected link */
a:active {
color: blue;
}
Try it Yourself »
<html>
<head>
<style>
/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
/* mouse over link */
a:hover {
color: hotpink;
}
/* selected link */
a:active {
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>
</body> </html>
2.The ::first-letter Pseudo-element
➢ The ::first-letter pseudo-element is used to add a special style to the first letter of a text.
The following example formats the first letter of the text in all <p> elements:
Output:
3.CSS - The ::before Pseudo-element:
➢ The ::before pseudo-element can be used to insert some content before the content of an element.
The following example inserts an image before the content of each <h1> element:
4;CSS - The ::after Pseudo-element
The ::after pseudo-element can be used to insert some content after the content of an element.
The following example inserts an image after the content of each <h1> element:
Output:
CSS UNITS OF MEASUREMENT
CSS length Value: CSS Units of measurement
➢ The length is an units in CSS are required to define the measurement such as margin: 20px; in which
the px (or pixel) is the CSS unit.
➢ They are used to set margin, padding, lengths, and so on.
➢ The length unit in CSS is of two types:
✓ Absolute length.
✓ Relative length.
1.Absolute lengths:
These are the fixed-length units, and the length expressed using the absolute units will appear as exactly that size
Unit Name Explanation Example
cm Centimeters It is used to define the measurement in centimetres. P{font-size:1.5cm;}
mm Millimeters It is used to define the measurement in millimetres. P{font-size:5mm;}
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align: center;
}
</style>
</head>
<body>
<h1> Absolute units </h1>
<p style = "font-size: 20px;" > It has a font-size: 20px; </p>
<p style = "font-size: 1.2cm;" > It has a font-size: 1.2cm; </p>
<p style = "font-size: .7in;" > It has a font-size: .7in; </p>
<p style = "font-size: 18pt;" > It has a font-size: 18pt; </p>
<p style = "font-size: 2pc;" > It has a font-size: 2pc; </p>
<p style = "font-size: 10mm;" > It has a font-size: 10mm; </p>
</body>
</html>
2.Relative lengths:
Relative length specify the length, which is relative to another length property .i.e relative to the window size or relative to the
element or parent element and
The relative length units are tabulated as follows:
Units Name Example
em ➢ It is relative to the font-size of the element.(1 em is equal to the current font size). P{font-size:1.5em;}
➢ 2em means 2 time the size of the current font).
➢ if an element is displaying with 12pts then 2em is 24pt.
➢ It is very useful unit in CSS it adopts automatically.
ex ➢ It is relative to the x-height of the font of the element. P{font-size:2ex;}
➢ It is rarely used.
➢ The x-height is determined by the height of the lowercase letter 'x'.
ch It is similar to the unit ex, but instead of using the height of the letter x, it measures the width of the P{font-size:6ch;}
integer "0" (zero).
rem It is the font-size of the root element P{font-size:6rem;}
vh It is relative to the height of the viewport. P{font-size:4vh;}
1vh = 1% or 1/100 of the height of the viewport.
vw It is relative to the width of the viewport. P{font-size:5vw;}
1vw = 1% or 1/100 of the width of viewport
vmin It is relative to the smaller dimension of the viewport. P{font-size:vmin;}
1vmin = 1% or 1/100 of the viewport's smaller dimension.
vmax It is relative to the larger dimension of the viewport. P{font-size:vmax;}
1vmax = 1% or 1/100 of the viewport's larger dimension.
% It is used to define the measurement as a percentage that is relative to another value. P{font-size:30%;}
<html>
<head>
<style>
body{
text-align: center;
}
p{
line-height: 0.1cm;
color: blue;
}
</style>
</head>
<body>
<h1> Relative units </h1>
<p style = "font-size: 2em;" > It has a font-size: 2em; </p>
<p style = "font-size: 8ex;" > It has a font-size: 8ex; </p>
<p style = "font-size: 6ch;" > It has a font-size: 6ch; </p>
<p style = "font-size: 4rem;" > It has a font-size: 4rem; </p>
<p style = "font-size: 4vw;" > It has a font-size: 4vw; </p>
<p style = "font-size: 10vh;" > It has a font-size: 10vh; </p>
<p style = "font-size: 10vmin;" > It has a font-size: 10vmin; </p>
<p style = "font-size: 8vmax;" > It has a font-size: 8vmax; </p>
<p style = "font-size: 400%;" > It has a font-size: 400%; </p>
</body>
</html>
<!DOCTYPE html>
Color values in CSS: <html>
1. Color values using color Keywods: <head>
2. Color values using RGB values <style>
3. Color values in Hexadecimal #p1 {background-color: blue;}
1.Color Keywords: Predefined Color Names #p2 {background-color: red;}
➢ In this method colors will be specified using the #p3 {background-color: coral;}
Predefined Color names called keywords. #p4 {background-color: brown;}
➢ 140 color names are predefined in the HTML and </style>
CSS color specification. </head>
➢ For example: blue, red, coral, brown, etc: <body>
</body>
</html>
2.RGB Colors
➢ An RGB color value is specified with the rgb() function, which has the following syntax:
rgb(red, green, blue)
➢ Each parameter (red, green, and blue) defines the intensity of the color and can be an integer between 0 and 255
or a percentage value (from 0% to 100%).
➢ For example, the rgb(0,0,255) value is rendered as blue, because the blue parameter is set to its highest value (255) and the others
are set to 0.
➢ Also, the following values define equal color: rgb(0,0,255) and rgb(0%,0%,100%).
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-size: 100%;
}
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>
2) CSS Font Family: font-family property
➢ In CSS, we use the font-family property to specify the font of a text.
➢ CSS font family can be divided in two types:
1. Generic family:
➢ A group of family names with uniform appearance
➢ It includes Serif, Sans-serif, and Monospace,Cursive,Fantacy.
2. Font family: It specifies the font family name like Arial, New Times Roman etc.
.p1 {
font-family: "Times New Roman", Times, serif;
}
Generic Font Families
Types of Generic Font Family
Sans-serif Sans-serif fonts have clean lines (no small strokes Arial
attached). They create a modern and Verdana
minimalistic look. Helvetica
Monospace Monospace fonts - here all the letters have the Courier New
same fixed width. They create a mechanical Lucida Console
look. Monaco
Example:
p{
color:red; Example: Font short hand:
font-style : italic;
font-weight : bold; P{ font : red italic bold 30px arial }
font-size : 30px;
font-family : arial;
}
3) CSS Font Size: font-size prpoerty
CSS font size property is used to change the size of the font.
h1 {
color: green;
}
Example:
1.Text Color and Background Color: <html>
<head>
In this example, we define both the background-color property and <style>
the color property: body {
background-color: lightgrey;
body {
color: blue;
background-color: lightgrey;
}
color: blue;
h1 {
}
background-color: black;
h1 {
color: white;
background-color: black;
}
color: white;
}
div {
background-color: blue;
color: white;
}
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p>This page has a grey background color and a
blue text.</p>
<div>This is a div.</div>
</body>
</html>
2.Text Alignment: text-align property
➢ The text-align property is used to set the horizontal alignment of a text.
➢ A text can be left or right aligned, centered, or justified.
➢ left alignment is default
The following Example shows center aligned, and left and right
aligned text:
h1 {
text-align: center;
}
h2 {
text-align: left;
}
h3 { text-align: right; }
<html> Output:
<head> Example
<style>
div {
border: 1px solid black;
padding: 10px;
width: 200px;
height: 200px;
text-align: justify;
}
</style>
</head>
<body>
<h1>Example text-align: justify</h1>
<div>
In my younger and more vulnerable years my father gave me some
advice that I've been turning over in my mind ever since. 'Whenever
you feel like criticizing anyone,' he told me, 'just remember that all
the people in this world haven't had the advantages that you've had.'
</div>
</body> </html>
3.Text Direction: direction property Example:
➢ The direction property specifies the text direction/writing direction <html>
<head>
within a block-level element.
<style>
➢ Set the text direction to "right-to-left“ p.rtl {
➢ Default is left-to-right direction: rtl;
}
</style>
p.rtl { </head>
<body>
direction: rtl;
} <h1>The direction Property</h1>
</body>
</html>
4.Text Decoration: text-decoration-line property
➢ Add a Decoration Line to Text
➢ The text-decoration-line property is used to add a decoration line to text.
➢ Tip: You can combine more than one value, like overline and underline to
display lines both over and under a text.
h1 {
text-decoration-line: overline;
}
h2 {
text-decoration-line: line-through;
}
h3 {
text-decoration-line: underline;
}
p {
text-decoration-line: overline underline;
}
5.Text Transformation: text-transform property
➢ The text-transform property is used to specify uppercase and lowercase letters in a text.
➢ It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word:
p.uppercase {
text-transform: uppercase;
}
p.lowercase {
text-transform: lowercase;
}
p.capitalize {
text-transform: capitalize;
}
<html> Example for text transformation
<head>
<style>
p.uppercase {
text-transform: uppercase;
}
p.lowercase { Output
text-transform: lowercase;
}
p.capitalize {
text-transform: capitalize;
}
</style>
</head>
<body>
</body>
</html>
<html> 6.Text Indentation
<head> The text-indent property is used to specify the indentation of the first line of a text:
<style> Example:
p{ p {
text-indent: 50px;
text-indent: 50px;
}
h1 {
}
text-indent: 50px;
}
p#p2 { output
text-indent: -5px;
}
</style>
</head>
<body>
<h1>Using text-indent</h1>
<p>In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever
since. 'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't had the
advantages that you've had.'</p>
<p id="p2">In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind
ever since. 'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't
had the advantages that you've had.'</p>
</body>
</html>
CSS for Lists
➢ There are various CSS properties that can be used to control lists
➢ Lists can be classified as ordered lists and unordered lists .
➢ In ordered lists, marking of the list items is with alphabet and numbers, whereas in unordered lists, the
list items are marked using bullets.
➢ "list-style-position: inside;" means that the bullet points will be inside the list item. As it is part of the list item, it
will be part of the text and push the text at the start:
List - Shorthand property
➢ The list-style property is a shorthand property.
➢ It is used to set all the list properties in one declaration
▪ list-style-type
▪ list-style-position
▪ list-style-image
ul
{ ul {
list-style-type : square; list-style : square inside url("sqpurple.gif");
list-style-position : inside; }
list-style-image :url(sqpurple.gif”);
}
CSS box model:
➢ Box model is a term referred to the rectangular boxes placed around every element in the web page.
➢ Every element in XHTML can be consider a BOX and all the properties of the box will be applied to the XHTML
element.
➢ Using the Box model we can applies the width, height, border, margin etc
The specific area that an element box may occupy on a web page is measured as follows-
1.Content
➢ The content area is the area containing the real content of the element.
➢ It often has a background, a color or an image and is located inside the content edge;
➢ its dimensions are the content width and the content height.
CSS Code:
This is content
P{width:100px; height:50px;} 50px
area
XHTML Code:
<p> This is content area</p> 100px
2.Padding
➢ The padding area is the space between the content of the element and its border.
➢ Negative values are not allowed.
➢ This property sets the padding space on all sides of an element.
CSS code:
p { padding:30px 20px 30px 20px;}
3.Border Field
➢ It is a region between the padding-box and the margin. Its proportions are determined by the border-
width and border-height of the boundary.
CSS Code:
P{ border: 5px solid blue ;} This is content
XHTML Code: area
<p> This is content area</p>
4.Margin Field
This segment consists of the area between the boundary and the edge of the border.
The proportion of the margin region is equal to the margin-box width and height. It is better to separate the
product from its neighbor nodes.
CSS Code:
P{ margin : 30px} This is content
XHTML Code: area
<p> This is content area</p>
Let’s create a box on the screen and add a border around it:
Adding Padding and Margin
Setting Individual Margins
We can set the specific margin sizes by using these four properties:
margin1
border-style: none | hidden | dotted | dashed | solid | double | groove | ridge | inset |
outset
p{
width: 300px;
height: 100px;
}
p#dot{ border-style: dotted; }
p#sol{ border-style: solid; }
Html code:
<p id="dot">This is a paragraph(dotted)</p>
<p id="sol">This is a paragraph(solid)</p>
<div >and <span> tags
<Div> tag:
➢ Div tag is used for defining a section in the web page.
➢ Div (short for division) divides the contents into individual sections.
➢ Each section can then have its own formatting as specified by the CSS.
➢ Div is a block-level container, meaning that there is line feed after the <div>
➢ Usigning <di> tag we can group the elements togrther and format them with CSS.
➢ Example menu section in one <div> and content section into other <div>
<html>
<head>
<style type=“text/CSS”>
div.menu{ background-color:orange;text-align:right; border:2px solid black;}
div.main{ background-color:orange;text-align:right; border:2px solid black;}
</style>
</head>
<body>
<div class=“menu”>
<a href=“ x1.html”> HOME</a>
<a href=“ x2.html”> CONTACT</a>
<a href=“ x3.html”> ABOUT</a>
</div>
<div class=“main”>
<h5> Contentw Articals</h2>
<p> This paragraph contains the contetns</p>
</div>
</body> </html>
Definition and Usage:
➢ The <span> tag is an inline container used to mark up a part of a text, or a part of a document.
➢ The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute.
➢ The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline
element.
</body>
</html>
Background-image:
➢ The background-image property sets one or more background images for an element.
➢ By default, a background-image is placed at the top-left corner of an element, and repeated both vertically
and horizontally.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("img_tree.gif"), url("paper.gif");
background-color: #cccccc;
}
</style>
</head>
<body>
</body>
</html>
background-repeat
The background-repeat property sets if/how a background image will be repeated.
By default, a background-image is repeated both vertically and horizontally.
</body>
</html>
Repeated the image only horizontally: repeate-x
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("img_tree.gif");
background-repeat: repeat-x;
}
</style>
</head>
<body>
</body>
</html>
Repeated the image both the directions : repeate
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("img_tree.gif");
background-repeat: repeat;
}
</style>
</head>
<body>
</body>
</html>
No Repeated the image : no-repeate
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
}
</style>
</head>
<body>
</body>
</html>
background-position property
➢ The background-position property sets the starting position of a background image.
➢ The values to this property are : [top, center, bottom],[left, center, right]
➢ By default, a background-image is placed at the top-left corner of an element, and repeated
both vertically and horizontally.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
</style>
</head>
<body>
</body></html>
Examples:
background-position property
body {
Value Description
background-image: url('w3css.gif');
left top If you only specify one background-repeat: no-repeat;
left center keyword, the other value will background-position: center top;
left bottom be "center" }
right top
right center body {
right bottom background-image: url('w3css.gif');
center top background-repeat: no-repeat;
center center background-position:left top;
center bottom }
The background-size property:
➢ The background-size property specifies the size of the background images.
➢ There are four different syntaxes you can use with this property: the keyword syntax ("auto", "cover" and
"contain")
<style>
#example1 {
border: 2px solid black;
padding: 25px;
background: url(mountain.jpg);
background-repeat: no-repeat;
background-size: auto;
}
#example2 {
border: 2px solid black;
padding: 25px;
background: url(mountain.jpg);
background-repeat: no-repeat;
background-size: 300px 100px;
}
Background image display size properties