HTML and Css
HTML and Css
HTML and Css
Hyper Text: Hyper Text simply means "Text within Text". A text has a
link within it, is a hypertext. Every time when you click on a word which
brings you to a new webpage, you have clicked on a hypertext.
Basic tags
<H1> H1 Header</H1>
<H2> H2 Header</H2>
<H3> H3 Header</H3>
<H4> H4 Header</H4>
<H5> H5 Header</H5>
<H6> H6 Header</H6>
Sample Programming
<!DOCTYPE html>
<html>
<head>
<title>This is my title</title>
</head>
<body>
<H1> H1 Header</H1>
<H2> H2 Header</H2>
<H3> H3 Header</H3>
<H4> H4 Header</H4>
<H5> H5 Header</H5>
<H6> H6 Header</H6>
<p>My first paragraph.</p>
</body>
</html>
HTML Element
HTML Attributes
HTML links are defined with the <a> tag. The link address is specified in the
“ href” attribute
They can contain all sorts of HTML elements; text, images, lists,
other tables, etc.
Ex:
<h2>HTML</h2>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
HTML List Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<li>Tea</li>
<li>Milk</li>
</ol>
Block-level Elements
A block-level element always starts on a new line and takes up the full width
available (stretches out to the left and right as far as it can).
The <div> element is a block-level element.
<div>Hello</div>
<div>World</div>
HTML IFRAMES
Use the height and width attributes to specify the size of the iframe.
The attribute values are specified in pixels by default, but they can also be in
percent (like "80%").
When making responsive web pages, add the following <meta> element in
all your web pages:
EX:
The HTML <FORM>element defines a form that is used to collect user input.
<article>
<aside>
<details>
<figcaption>
<figure>
<footer>
<header>
<main>
<mark>
<nav>
<section>
<summary>
<time>
HTML Canvas
The graphic to the left is created with <canvas>. It shows four elements: a
red rectangle, a gradient rectangle, a multicolor rectangle, and a multicolor
text.
The HTML <canvas> element is used to draw graphics, on the fly, via
JavaScript.
The <canvas> element is only a container for graphics. You must use
JavaScript to actually draw the graphics.
SVG
Before HTML5, a video could only be played in a browser with a plug-in (like
flash).
Before HTML5, audio files could only be played in a browser with a plug-in
(like flash)The HTML5 <audio> element specifies a standard way to embed
audio in a web page.
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
CSS (Cascading Style Sheets)
CSS is used to define styles for your web pages, including the design, layout
and variations in display for different devices and screen sizes.
HTML was NEVER intended to contain tags for formatting a web page!
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
When tags like <font>, and color attributes were added to the
HTML 3.2 specification, it started a nightmare for web developers.
Development of large websites, where fonts and color information
were added to every single page, became a long and expensive
process.
With an external stylesheet file, you can change the look of an entire
website by changing just one file!
Three Ways to Insert CSS
With an external style sheet, you can change the look of an entire website
by changing just one file!
Each page must include a reference to the external style sheet file inside
the <link> element. The <link> element goes inside the <head> section:
CSS Selectors
An external style sheet can be written in any text editor. The file should not
contain any html tags. The style sheet file must be saved with a .css
extension.
CSS selectors are used to "find" (or select) HTML elements based on their
element name, id, class, attribute, and more.
An internal style sheet may be used if one single page has a unique style.
Internal styles are defined within the <style> element, inside the <head>
section of an HTML page:
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
Inline Styles
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style attribute to the relevant element. The style attribute
can contain any CSS property.
If some properties have been defined for the same selector (element) in
different style sheets, the value from the last read style sheet will be used.
h1 {
color: navy;
}
CSS Backgrounds
The CSS background properties are used to define the background effects
for elements.
background-color
background-image
background-repeat
background-attachment
background-position
Border Style
The border-style property can have from one to four values (for the top
border, right border, bottom border, and the left border).
Ex:
p.dotted {border-style: dotted;}
p.dashed {border-style: dashed;}
p.solid {border-style: solid;}
p.double {border-style: double;}
p.groove {border-style: groove;}
p.ridge {border-style: ridge;}
p.inset {border-style: inset;}
p.outset {border-style: outset;}
p.none {border-style: none;}
p.hidden {border-style: hidden;}
p.mix {border-style: dotted dashed solid double;}
CSS Margins
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 has properties for specifying the margin for each side of an element:
margin-top
margin-right
margin-bottom
margin-left
Individual Sides
CSS has properties for specifying the margin for each side of an element:
margin-top
margin-right
margin-bottom
margin-left
The element Selector
Padding
CSS has properties for specifying the padding for each side of an element:
padding-top
padding-right
padding-bottom
padding-left
You can select all <p> elements on a page like this (in this case, all <p>
elements will be center-aligned, with a red text color):
p {
text-align: center;
color: red;
}
The id Selector
To select an element with a specific id, write a hash (#) character, followed
by the id of the element.
#hai {
text-align: center;
color: red;
}
.center {
text-align: center;
color: red;
}
We can also specify that only specific HTML elements should be affected by
a class.
In the example below, only <p> elements with class="center" will be center-
aligned:
Every HTML element has a default display value depending on what type
of element it is. The default display value for most elements is block or
inline.
Using width
Also, with display: inline-block, the top and bottom margins/paddings are
respected, but with display: inline they are not.
CSS Combinators
A CSS selector can contain more than one simple selector. Between the
simple selectors, we can include a combinator.
Basic validation
<script>
<script>
First program
<!DOCTYPE html>
<html>
<body>
<p id="demo">
</p>
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
</body>
</html>
Variables
JavaScript variables are containers for storing data values. In this example,
x, y, and z, are variables:
<script>
var x = 5;
var y = 6;
var z = x + y;
</script>
Datatypes
JavaScript variables can hold many data types: numbers, strings, objects
and more:
<script>
var x = 16 + "Volvo";
document.getElementById("demo").innerHTML = x; //16Volvo
</script>
Functions
<script>
The code inside the function will execute when "something" invokes (calls)
the function:
When an event occurs (when a user clicks a button)
When it is invoked (called) from JavaScript code
Automatically (self invoked)
Conditional Statements
Very often when you write code, you want to perform different actions for
different decisions.
You can use conditional statements in your code to do this. In JavaScript we
have the following conditional statements: Use if to specify a block of code
to be executed, if a specified condition is true
Use else to specify a block of code to be executed, if the same condition is
false Use else if to specify a new condition to test, if the first condition is
false Use switch to specify many alternative blocks of code to be executed