HTML Notes (2 Files Merged)
HTML Notes (2 Files Merged)
Level 1
HTML
Hyper Text Markup Language
HTML Tag
A container for some content or other HTML tags
Element
</html>
Quick Points
Html tag is parent of head & body tag
Most of html elements have opening & closing tags
with content in between
Comments in HTML
This is part of code that should not be parsed.
<html lang="en">
Heading Tag
Used to display headings in HTML
h1 ( most important )
h2
h3
h4
h5
h6 least important
( )
Paragraph Tag
Used to add paragraphs in HTML
Anchor Tag
Used to add links to your page
Image Tag
relative url
Br Tag
Used to add next line(line breaks) to your page
< br>
b Bold </b>
< >
i Italic </i>
< >
hr>
<
HO 2
An + B
Pre Tag
Used to display text as it is (without ignoring spaces & next line)
<pre> This
is a sample
text.
</ pre>
Level 3
<header>
<main>
<footer>
clickable pic
set height
set width
Div Tag
Div is a container used for other HTML elements
Block Element (takes full width)
List : Div Tags
<address> <fieldset> <nav>
<figcaption> <noscript>
<article>
<figure> <ol>
<aside>
<footer> <p>
<blockquote>
<form> <pre>
<canvas>
<h1>-<h6> <section>
<dd>
<header> <table>
<div>
<hr> <tfoot>
<dl>
<li> <ul>
<dt>
<main> <video>
Span Tag
Span is also a container used for other HTML elements
Inline Element (takes width as per size)
<code>
<output>
<em>
<a> <samp>
<i>
<abbr> <script>
<img>
<acronym> <select>
<input>
<b> <small>
<kbd>
<bdo> <span>
<label>
<big> <strong>
<map>
<br> <sub>
<object>
<button> <sup>
<tt>
<cite> <textarea>
<var>
<time>
Level Pro
List in HTML
Lists are used to represent real life list data.
unordered ordered
<u > l <ol>
<li> Apple </li> <li> Apple </li>
Tables in HTML
Tables are used to represent real life table data.
<tr> used to display table row
d
<t > used to display table data
<tr>
<th> Name </th>
<th> Roll No </th>
</tr>
<tr>
<td> Shradha </th>
<th> 1664 </th>
</tr>
</table>
Caption in Tables
<caption> Student Data </caption>
Student Data
Name Roll No
Shradha 1664
Data
Shradha 1664
Aman 1890
Form in HTML
Forms are used to collect data from the user
Eg- sign up/login/help requests/contact me
<form>
form content
</form>
Action in Form
Action attribute is used to define what action needs to be
performed when a form is submitted
Label
<label for="id1">
</label>
<label for="id2">
</label>
Class & Id
<div id="id1" class="group1">
</div>
</div>
Checkbox
<label for="id1">
<label for="id2">
Textarea
<textarea name="feedback" id="feedback" placeholder="Please add Feedback">
</textarea>
Select
<select name="city" id="city">
Video Tag
<v ideo src="myVid.mp4"> My Video </video>
Attributes
- controls
- height
- width
- loop
- autoplay
APNA
COLLEGE
Structure/layout Style Logic
Level 1
APNA
COLLEGE
Basics of CSS
CSS
Cascading Style Sheet
APNA
It is a language that is used to describe the style of a document.
COLLEGE
makeup
not a programming language, but a stying language
But for styling there should be some content, and that's why
we studied html before css
APNA
Selector
COLLEGE
h1 {
color: red;
}
Property Value
Including Style
Inline
APNA
<h1 style="color: red"> Apna College </h1>
Including Style
External Stylesheet
APNA
Writing CSS in a separate document & linking it with HTML file
COLLEGE
best way
color: green;
background-color: green;
Color Systems
RGB
color: rgb(255, 0, 0);
APNA
COLLEGE
color: rgb(0, 255, 0);
Selectors
Universal Selector Class Selector
*{}
APNA .myClass { }
Element Selector
h1 { }
COLLEGE
Id Selector
#myId { }
Practice Set 1
Q1: Create a simple div with an id "box".
APNA
Add some text content inside the div.
Set its background color to blue.
COLLEGE
Q2: Create 3 headings with h1, h2 & h3.
Give them all a class "heading" & set color of "heading" to red.
APNA
text-align : left / right / center
COLLEGE
text alignement doesn't mean align according to the page; i.e.
right does not mean on the page's right side
but the parent's right side
in css3, latest css -> start and end are introduced for language
support like arabic
Text Properties
text-decoration
APNA
text-decoration : underline / overline / line-through
COLLEGE
Text Properties
font-weight
APNA
font-weight : normal / bold / bolder / lighter
font-weight : 100-900
COLLEGE
APNA
COLLEGE
Units in CSS
Absolute
APNA
pixels (px)
COLLEGE
96px = 1 inch
font-size: 2px;
Text Properties
text-transform
APNA
text-tranform : uppercase / lowercase / capitalize / none
COLLEGE
Practice Set 2
Q1: Create a heading centred on the page with all of its text capitalized by default.
APNA
Q2: Set the font family of all the content in the document to "Times New Roman".
COLLEGE
Q3: Create one div inside another div.
Set id & text "outer" for the first one & "inner" for the second one.
Set the outer div text size to 25px & inner div text size to 10px.
Level 2
APNA
COLLEGE
Box Model in
css
Margin
Height
content
Height
Border
COLLEGE
Padding
Margin
Height
Height
content
By default, it sets the content area height of the element
APNA
COLLEGE
div {
height: 50px;
}
Width
Width
content
By default, it sets the content area width of the element
APNA
COLLEGE
div {
width: 50px;
}
Border
content
Used to set an element's border
COLLEGE
border-style : solid / dotted / dashed
border-color : black;
Border
Shorthand
Padding
content
padding-left
APNA
Padding
padding-right
padding-top
padding-bottom
COLLEGE
Padding
Shorthand
margin-right
margin-left APNA
margin-top
margin-bottom
COLLEGE
Margin
Shorthand
Practice Set 3
Q1: Create a div with height & width of 100px.
APNA
Set its background color to green & the border radius to 50%.
COLLEGE
Q2: Create the following navbar.
60px
200px (height)
(gap)
25px
(text) #f08804
#0f1111
anchor tags (yellow)
APNA
(black)
(links)
COLLEGE
Display Property
display: inline / block / inline-block / none
APNA
inline - Takes only the space required by the element. (no margin/ padding)
COLLEGE
block - Takes full space available in width.
Visibility
visibility: hidden;
APNA
COLLEGE
Note : When visibility is set to none, space for the element is reserved.
But for display set to none, no space is reserved or blocked for the
element.
Alpha Channel
opacity (0 to 1)
RGBA
APNA
COLLEGE
color: rgba(255, 0, 0, 0.5);
Practice Set 4
Q1: Create a webpage layout with a header, a footer & a content area containing 3 divs.
APNA
Set the height & width of divs to 100px.
(add the previous navbar in the header)
COLLEGE
Q2: Add borders to all the divs.
Q3: Add a different background color to each div with an opacity of 0.5
Level 3
APNA
COLLEGE
position
Units in CSS
Relative
% APNA
em COLLEGE
rem
Percentage (%)
It is often used to define a size as relative to an element's parent object.
APNA
COLLEGE
width : 33% ;
margin-left : 50% ;
Em
APNA
COLLEGE
font size of child will be half of parent for 0.5em
for padding & margin it's relative to same element's font size
APNA
COLLEGE
font size of child will be half of parent for 0.5em
for padding & margin it's relative to same element's font size
Others
vh: relative to 1% viewport height
APNA
vw : relative to 1% viewport width
COLLEGE
Position
The position CSS property sets how an element is positioned in a document.
APNA
position : static / relative / absolute / fixed
COLLEGE
Position
static - default position (The top, right, bottom, left, and z-index properties have no effect)
APNA
relative - element is relative to itself. (The top, right, bottom, left, and z-index will work)
COLLEGE
absolute - positioned relative to its closest positioned ancestor. (removed from the flow)
z-index
It decides the stack level of elements
APNA
Overlapping elements with a larger z-index cover those with a smaller one.
COLLEGE
z-index : auto (0)
z-index : 1 / 2 / ...
z-index : -1 / -2 / ...
show 3d space
Background Image
Used to set an image as background
APNA
COLLEGE
background-image : url("image.jpeg");
Background Size
APNA
background-size : cover / contain / auto
COLLEGE
Practice Set 5
Qs: Create the following layout using the given html.
APNA
Give the div a height, width & some background image.
Use the appropriate position property for the div element to place it at the
COLLEGE
right end of the page. (The div should not move even on scroll)
Level 4
APNA
COLLEGE
Basics of CSS
Flexbox
Flexible Box Layout
APNA
It is a one-dimensional layout method for arranging items in rows or columns.
COLLEGE
APNA
COLLEGE main axis
flex item
cross axis
Flexbox Direction
It sets how flex items are placed in the flex container, along which axis and direction.
APNA
flex-direction : row; (default)
COLLEGE
flex-direction : row-reverse;
flex-direction : column;
flex-direction : column-reverse;
Flex Properties
for Flex Container
APNA
justify-content : alignment along the main axis.
COLLEGE
flex-wrap : nowrap / wrap / wrap-reverse
align-content : alignment of space between & around the content along cross-axis
Flex Properties
for Flex Item
APNA
align-self : alignment of individual along the cross axis.
COLLEGE
flex-grow : how much a flex item will grow relative to the rest of the flex items if
space is available
flex-shrink : how much a flex item will shrink relative to the rest of the flex items if
space is available
Practice Set 6
Qs: Create a navbar with 4 options in the form of anchor tags inside list items.
APNA
Now, use flexbox to place them all spaced equally in a single line.
COLLEGE
Qs: Use flexbox to center one div inside another div.
APNA
@media (width : 600px) {
div {
background-color : red;
COLLEGE
}
}
Media Queries
APNA
@media (min-width : 200px) and (min-width : 300px) {
div {
COLLEGE
background-color : red;
}
}
Practice Set 7
Qs: Add a media query to implement the following:
APNA
the color of a div changes to green for viewport width less than 300px
the color of a div changes to pink for width between 300px & 400px
COLLEGE
the color of a div changes to red for width between 400px & 600px
Transitions
Transitions enable you to define the transition between two states of an element.
APNA
transition-property : property you want to transition (font-size, width etc.)
COLLEGE
transition-duration : 2s / 4ms ..
transition-delay : 2s / 4ms ..
Transition Shorthand
property name | duration | timing-function | delay
APNA
transition: font-size 2s ease-in-out 0.2s;
COLLEGE
APNA
rotate
COLLEGE
transform: rotate(45deg);
CSS Transform
scale
transform: scale(2);
transform: scaleY(0.5);
CSS Transform
translate
transform: translate(20px);
APNA
transform: translate(20px, 50px);
COLLEGE
transform: translateX(20px);
transform: translateY(20px);
Animation
To animate CSS elements
@keyframe myName {
APNA
COLLEGE
from { font-size : 20px; }
to { font-size : 40px; }
}
Animation Properties
animation-name
animation-duration
APNA
COLLEGE
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
Animation Shorthand
APNA
animation : myName 2s linear 3s infinite normal
COLLEGE
% in Animation
@keyframe myName {
APNA
COLLEGE
0% { font-size : 20px; }
50% { font-size : 30px; }
100% { font-size : 40px; }
}
Practice Set 8
Qs: Create a simple loader using CSS
APNA
Step1 : create a div with circular shape & a thick border from one end
(top/bottom/left/right)
COLLEGE
Step2 : To make it spin create an animation which transforms it from 0deg to 360deg
Step3 : Add the animation property to the loader with infinite duration