A Notes On HTML Css and Javascript

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 61
At a glance
Powered by AI
Some of the key takeaways from the document include CSS being used to style HTML elements, different types of CSS selectors like element, id and class selectors, and the difference between block and inline elements.

The different types of CSS selectors are element selector, id selector, class selector, universal selector and group selector. Each selector selects elements based on their tag name, id, class or other attributes.

Block elements like <p> and <div> stack vertically and take up the full width available, while inline elements like <span> sit next to each other horizontally and only take up as much width as needed.

• The <nav> tag is a new element in HTML5.

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

• CSS stands for Cascading Style Sheets. It is a style sheet


language which is used to describe the look and
formatting of a document written in markup language. It
provides an additional feature to HTML. It is generally
used with HTML to change the style of web pages and user
interfaces. It can also be used with any kind of XML
documents including plain XML, SVG and XUL.
• CSS is used along with HTML and JavaScript in most
websites to create user interfaces for web applications and
user interfaces for many mobile applications.
What does CSS do

• You can add new looks to your old HTML


documents.
• You can completely change the look of your
website with only a few changes in CSS code.
CSS Syntax
• Selector: Selector indicates the HTML element you want to style.
It could be any tag like <h1>, <title> etc.
• Declaration Block: The declaration block can contain one or more
declarations separated by a semicolon. For the above example,
there are two declarations:
• color: yellow;
• font-size: 11 px;
• Each declaration contains a property name and value, separated
by a colon.
• Property: A Property is a type of attribute of HTML element. It
could be color, border etc.
• Value: Values are assigned to CSS properties. In the above
example, value "yellow" is assigned to color property.

• 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

• CSS is added to HTML pages to format the


document according to information in the
style sheet. There are three ways to insert CSS
in HTML documents.
• Inline CSS
• Internal CSS
• External CSS
Inline CSS

• Inline CSS is used to apply CSS on a single line


or element.
• For example:
• <p style="color:blue">Hello CSS</p>  
Internal CSS
 
• Internal CSS is used to apply CSS on a single
document or page. It can affect all the elements of
the page. It is written inside the style tag within
head section of html.
• For example:
• <style>  
• p{color:blue}  
• </style>  
External CSS

• External CSS is used to apply CSS on multiple pages


or all pages. Here, we write all the CSS code in a css
file. Its extension must be .css for example style.css.
• You need to link this style.css file to your html pages
like this:
• <link rel="stylesheet" type="text/css" href="style.css
">  
• The link tag must be used inside head section of
html.
style.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

• CSS font color is a standalone attribute in CSS


although it seems that it is a part of CSS fonts.
It is used to change the color of the text.
• There are three different formats to define a
color:
• By a color name
• By hexadecimal value
• By RGB
• <!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>  
CSS Font Family

• CSS font family can be divided in two types:


• Generic family: It includes Serif, Sans-serif, and Monospace.
• Font family: It specifies the font family name like Arial, New
Times Roman etc.
• Serif: Serif fonts include small lines at the end of
characters. Example of serif: Times new roman, Georgia
etc.
• Sans-serif: A sans-serif font doesn't include the small lines
at the end of characters. Example of Sans-serif: Arial,
Verdana etc.
• <!DOCTYPE html>  
• <html>  
• <head>  
• <style>  
• body {  
• font-size: 100%;  
• }  
• h1 { font-family: sans-serif; }  
• h2 { font-family: serif; }   
• p { font-family: monospace; }   
• }  
• </style>  
• </head>  
• <body>  
• <h1>This heading is shown in sans-serif.</h1>  
• <h2>This heading is shown in serif.</h2>  
• <p>This paragraph is written in monospace.</p>  
• </body>  
• </html>  
Font Size Value Description

xx-small used to display the extremely small text size.

x-small used to display the extra small text size.

small used to display small text size.

medium used to display medium text size.

large used to display large text size.

x-large used to display extra large text size.

xx-large used to display extremely large text size.

smaller used to display comparatively smaller text size.

larger used to display comparatively larger text size.

size in pixels or % used to set value in percentage or in pixels.


• <html>  
• <head>  
• <title>Practice CSS font-size property</title>  
• </head>  
• <body>  
• <p style="font-size:xx-small;">  This font size is extremely small.</p>    
• <p style="font-size:x-small;">  This font size is extra small</p>    
• <p style="font-size:small;">  This font size is small</p>    
• <p style="font-size:medium;">  This font size is medium. </p>    
• <p style="font-size:large;">  This font size is large. </p>    
• <p style="font-size:20px;">  This font size is 20 pixels.  </p>    
• </body>  
• </html>  
• CSS Font Style
• CSS Font style property defines what type of font you want to display. It may be italic, oblique, or normal.
• <!DOCTYPE html>  
• <html>  
• <head>  
• <style>  
• body {  
• font-size: 100%;  
• }  
• h2 { font-style: italic; }  
• h3 { font-style: oblique; }  
• h4 { font-style: normal; }   
• }  
• </style>  
• </head>  
• <body>  
• <h2>This heading is shown in italic font.</h2>  
• <h3>This heading is shown in oblique font.</h3>  
• <h4>This heading is shown in normal font.</h4>  
• </body>  
• </html>  
• CSS Font Variant
• CSS font variant property specifies how to set font variant of an element. It may be
normal and small-caps.
• <!DOCTYPE html>  
• <html>  
• <head>  
• <style>  
• p { font-variant: small-caps; }  
• h3 { font-variant: normal; }  
• </style>  
• </head>  
• <body>  
• <h3>This heading is shown in normal font.</h3>  
• <p>This paragraph is shown in small font.</p>  
• </body>  
• </html>  
• CSS Font Weight
• CSS font weight property defines the weight of the font and specify
that how bold a font is. The possible values of font weight may be
normal, bold, bolder, lighter or number (100, 200..... upto 900).
• <!DOCTYPE html>  
• <html>  
• <body>  
• <p style="font-weight:bold;">This font is bold.</p>  
• <p style="font-weight:bolder;">This font is bolder.</p>  
• <p style="font-weight:lighter;">This font is lighter.</p>  
• <p style="font-weight:100;">This font is 100 weight.</p>  
• <p style="font-weight:900;">This font is 900 weight.</p>  
• </body>  
• </html>  
CSS background-image

• The background-image property is used to set an image as a background of an element.


By default the image covers the entire element. You can set the background image for a
page like this.
• <!DOCTYPE html>  
• <html>  
• <head>  
• <style>  
• body {  
• background-image: url("paper1.gif");  
• margin-left:100px;  
• }  
• </style>  
• </head>  
• <body>  
• <h1>Hello Javatpoint.com</h1>  
• </body>  
• </html>       
Css lists
• 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;
• }
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

list-style Sets all the properties for a list in one declaration

list-style-image Specifies an image as the list-item marker

list-style-position Specifies the position of the list-item markers (bullet points)

list-style-type Specifies the type of list-item marker


Css color
• <!DOCTYPE html>
• <html>
• <head>
• <style>
• body {
• color: red;
• }

• h1 {
• color: #00ff00;
• }

• p.ex {
• color: rgb(0,0,255);
• }
• </style>
• </head>
• <body>

• <h1>This is heading 1</h1>

• <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>

• <p class="ex">This is a paragraph with class="ex". This text is blue.</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

• 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.
• Eg: img{float:right} //adjust image and text
• h1 {
    text-align: center;
}

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

• The letter-spacing property is used to specify


the space between the characters in a text.
• h1 {
    letter-spacing: 3px;
}

h2 {
    letter-spacing: -3px;
}
Line Height

• The line-height property is used to specify the space


between lines:
• Example
• p.small {
    line-height: 0.8;
}

p.big {
    line-height: 1.8;
}
Text Direction

• The direction property is used to change the


text direction of an element:
• Rtl-right to left.
• Ltr-left to right.
• Example
• p {
    direction: rtl;
}
Word Spacing

• The word-spacing property is used to specify the space between


the words in a text.
• The following example demonstrates how to increase or decrease
the space between words: 
• Example
• h1 {
    word-spacing: 10px;
}

h2 {
    word-spacing: -5px;
}
Text Shadow

• The text-shadow property adds shadow to text.


• The following example specifies the position of
the horizontal shadow (3px), the position of the
vertical shadow (2px) and the color of the
shadow (red):
• Example
• h1 {
    text-shadow: 3px 2px red;
}
Span and div
• The HTML tags div and span hold no
presentational value by themselves. This
means that if you put then in your HTML, they
will not actually display anything.
• These tags are primarily used as "hooks" for
your CSS. You use them to divide or label your
HTML (when another, more semantic tag will
not work) and use CSS selectors to target
them.
Block versus Inline HTML Elements

• HTML tags fall into two broad categories in respect to


the way they display on the page: block and inline.
• Block level elements such as headings <h1> through
<h6> and paragraphs <p> will obligingly stack down
the page with no line breaks required. They even have
preset margins to create space between them.
• Inline elements have no such margins, and sit side by
side across the page, only wrapping to the next line if
there is not enough room for them to sit next to each
other. (p. 18)
Div Tag

• The div tag is a block level HTML element. It is


used to divide or section of other HTML tags
in to meaningful groups.
• <!DOCTYPE html>
• <html>
• <body>

• <div>Hello</div>
• <div>World</div>

• <p>The DIV element is a block element, and will start on a new


line.</p>

• </body>
• </html>
Span Tag

• The span tag is an inline HTML element that is


used to group a set of inline elements.
• Generally speaking, you use span to hook text
or a group of tags that you want to style
differently.
• <!DOCTYPE html>
• <html>
• <body>

• <h1>My <span style="color:red">Important</span>


Heading</h1>

• </body>
• </html>
• <!DOCTYPE html>
• <html>
• <body>

• <h1>My <div style="color:red">Important</div>


Heading</h1>

• </body>
• </html>
• Span output:
My Important Heading

• Div output:
My 
Important 
Heading

You might also like