A Notes On HTML Css and Javascript
A Notes On HTML Css and Javascript
A Notes On HTML Css and Javascript
It is
used to define a block of navigation links,
either within the current document or to
other documents. Examples of navigation
blocks are menus, tables of contents, and
indexes.
What is CSS
• Selector{Property1: value1; Property2: value2; ..........;}
• CSS Selector
• CSS selectors are used to select the content you want to style.
Selectors are the part of CSS rule set. CSS selectors select
HTML elements according to its id, class, type, attribute etc.
• There are several different types of selectors in CSS.
• CSS Element Selector
• CSS Id Selector
• CSS Class Selector
• CSS Universal Selector
• CSS Group Selector
CSS Element Selector
• <!DOCTYPE html>
• <html>
• <head>
• <style>
• p{
• text-align: center;
• color: blue;
• }
• </style>
• </head>
• <body>
• <p>This style will be applied on every paragraph.</p>
• <p>And me!</p>
• </body>
• </html>
CSS Id Selector
-> The id selector selects the id attribute of an HTML element to select a specific element. An id is
always unique within the page so it is chosen to select a single, unique element.
->It is written with the hash character (#), followed by the id of the element.
• <!DOCTYPE html>
• <html>
• <head>
• <style>
• #para1 {
• text-align: center;
• color: blue;
• }
• </style>
• </head>
• <body>
• <p id=“para1” >Hello Javatpoint.com</p>
• <p>This paragraph will not be affected.</p>
• </body>
• </html>
CSS Class(generic) Selector
• The class selector selects HTML elements with a specific class attribute. It is used with a period character . (full
stop symbol) followed by the class name.
• Note: A class name should not be started with a number.
• Difference between class and generic selector is selector is added before .classname in class selector where not
added in generic selector.
• Eg: p.center{…} <!..only for p tag..>
• .center{..}<!...for any tag…>
Let's take an example with a class "center".
• <!DOCTYPE html>
• <html>
• <head>
• <style>
• .center {
• text-align: center;
• color: blue;
• }
• </style>
• </head>
• <body>
• <h1 class="center">This heading is blue and center-aligned.</h1>
• <p class="center">This paragraph is blue and center-aligned.</p>
• </body>
• </html>
CSS Universal Selector
• The universal selector is used as a wildcard character. It selects all the elements on the pages.
• <!DOCTYPE html>
• <html>
• <head>
• <style>
• * {
• color: green;
• font-size: 20px;
• }
• </style>
• </head>
• <body>
• <h2>This is heading</h2>
• <p>This style will be applied on every paragraph.</p>
• <p>And me!</p>
• </body>
Group selector
• <html>
• <head>
• <style>
• h1, h2, p {
• text-align: center;
• color: blue;
• }
• </style>
• </head>
• <body>
• <h1>Hello Javatpoint.com</h1>
• <h2>Hello Javatpoint.com (In smaller font)</h2>
• <p>This is a paragraph.</p>
• </body>
• </html>
How to add CSS
For example:
• p{color:blue}
• body {
• background-color: lightblue;
• }
• h1 {
• color: navy;
• margin-left: 20px;
• }
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.
• These are some important font attributes:
• CSS Font color: This property is used to change the color of the text. (standalone
attribute)
• CSS Font family: This property is used to change the face of the font.
• CSS Font size: This property is used to increase or decrease the size of the font.
• CSS Font style: This property is used to make the font bold, italic or oblique.
• CSS Font variant: This property creates a small-caps effect.
• CSS Font weight: This property is used to increase or decrease the boldness and
lightness of the font.
CSS Font Color
• ul.b {
• list-style-type: square;
• }
• ol.c {
• list-style-type: upper-roman;
• }
• ol.d {
• list-style-type: lower-alpha;
• }
An Image as The List Item Marker
• <style>
• ul {
• list-style-image: url('sqpurple.gif');
• }
• </style>
Styling List With Colors
• ol {
background: #ff9999;
padding: 20px;
}
ul {
background: #3399ff;
padding: 20px;
}
ol li {
background: #ffe5e5;
padding: 5px;
margin-left: 35px;
}
ul li {
background: #cce5ff;
margin: 5px;
}
All CSS List Properties
Property Description
• h1 {
• color: #00ff00;
• }
• p.ex {
• color: rgb(0,0,255);
• }
• </style>
• </head>
• <body>
• <p>This is an ordinary paragraph. Notice that this text is red. The default text-color for a page is defined in the body selector.</p>
• </body>
• </html>
• Set the text color with a HEX value:
body {color: #92a8d1;}
• Set the text color with an RGB value:
body {color: rgb(201, 76, 76);}
• Rgb values range(0-255).
• Set the text color with an RGBA value:
body {color: rgba(201, 76, 76, 0.6);}
Css text
• body {
color: blue;
}
h1 {
color: green;
}
Text Alignment
h2 {
text-align: left;
}
h3 {
text-align: right;
}
• When the text-align property is set to "justify",
each line is stretched so that every line has
equal width, and the left and right margins are
straight (like in magazines and newspapers):
• Example
• div {
text-align: justify;
}
• The text-decoration property is used to set or
remove decorations from text.
• The value text-decoration: none; is often used
to remove underlines from links:
• Example
• a {
text-decoration: none;
}
• h1 {
text-decoration: overline;
}
h2 {
text-decoration: line-through; /upon the text
}
h3 {
text-decoration: underline;
}
text-transform
• The text-transform property is used to specify uppercase and
lowercase letters in a text.
• p.uppercase {
text-transform: uppercase;
}
p.lowercase {
text-transform: lowercase;
}
p.capitalize {
text-transform: capitalize;
}
• The text-indent property is used to specify the
indentation of the first line of a text:
• Example
• p {
text-indent: 50px;
}
Letter Spacing
h2 {
letter-spacing: -3px;
}
Line Height
p.big {
line-height: 1.8;
}
Text Direction
h2 {
word-spacing: -5px;
}
Text Shadow
• <div>Hello</div>
• <div>World</div>
• </body>
• </html>
Span Tag
• </body>
• </html>
• <!DOCTYPE html>
• <html>
• <body>
• </body>
• </html>
• Span output:
My Important Heading
• Div output:
My
Important
Heading