HTML-CSS-JS
HTML-CSS-JS
Introduction to HTML
Definitions:
WWW – World Wide Web.
HTML – Hyper Text Markup Language – The Language of Web Pages on the
World Wide Web. HTML is a text formatting language, defines the semantic
of the page.
Tags: Codes enclosed in brackets, HTML Like XML syntax use specific tags to
describe page structure.
<HTML>
<HEAD>
<TITLE>Site Title</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>
The HEAD of your document point to above window part. The TITLE of your
document appears in the very top line of the user’s browser. If the user chooses
The text in your TITLE should be as descriptive as possible because this is what
many search engines, on the internet, use for indexing your site.
Head Tag contains one or more <meta> tags, meta tags use to describe the page
content, author, character set, ..etc. this also help search engines to classify the
page.
The BODY tag is most important tag in the page because it is contain the visible
pat of the page, body tag contain some attribute to control the design of entire
page like text=#RRGGBB, background image, background color, but it is good
practice to leave all design stuff to CSS.
Inside the BODY element, heading elements H1 through H6 are generally used for
major divisions of the document. Headings are permitted to appear in any order, but
you will obtain the best results when your documents are displayed in a browser if
you follow these guidelines:
1. H1: should be used as the highest level of heading, H2 as the next highest, and so
forth.
2. You should not skip heading levels: e.g., an H3 should not appear after an H1,
unless there is an H2 between them.
Paragraphs <p></p>:
Paragraphs allow you to add text to a document in such a way that it will automatically
adjust the end of line to suite the window size of the browser in which it is being
displayed. Each line of text will stretch the entire length of the window.
Output
Heading 1
Paragraph 1,….
Heading 2
Paragraph 2,….
Heading 3
Paragraph 3,….
Heading 4
Paragraph 4,….
Heading 5
Paragraph 5,….
Heading 6
Paragraph 6,….
Break, <BR>
Line breaks allow you to decide where the text will break on a line or continue to
the end of the window.
A <BR> is an empty Element, meaning that it may contain attributes but it does
not contain content.
The <HR> element causes the browser to display a horizontal line (rule) in your
document.
The next table represents some of the more commonly used special characters. For
a comprehensive listing, visit the W3C’s section on special characters.
Lists:
HTML supplies several list elements. Most list elements are composed of one or
more <LI> (List Item) elements.
Unordered List <ul>: Items in this list start with a list mark such as a bullet.
Browsers will usually change the list mark in nested lists.
You have the choice of three bullet types: disc(default), circle, square.
These are controlled in Netscape Navigator by the “TYPE” attribute for the <UL>
element.
<UL TYPE=“square”>
</UL>
List item …
List item …
List item …
Ordered List <ol>: Items in this list are numbered automatically by the browser.
You have the choice of setting the TYPE Attribute to one of five numbering styles.
a Lower alpha a, b, c, ……
A Upper alpha A, B, C, ……
</OL>
Image File (SRC:source): This value will be a URL (location of the image) E.g.
http://www.domain.com/dir/file.ext
Alternate Text (ALT): This is a text field that describes an image or acts as a label.
It is displayed when they position the cursor over a graphic image.
Anchor <a>:
The tags used to produce links are the <A> and </A>. The <A> tells where the link
should start and the </A> indicates where the link ends. Everything between these
two will work as a link.
The example below shows how to make the word Here work as a link to yahoo.
Click <A HREF="http://www.yahoo.com">here</A> to go to yahoo.
Tables <table></table>:
1. Table Row<TR></TR>.
The table row elements usually contain table header elements or table data
elements
Table Data cells are represented by the TD element. Cells can also be TH (Table
Header) elements which results in the contents of the table header cells appearing
centered and in bold text.
Colspan: Specifies how many cell columns of the table this cell should span.
Rowspan: Specifies how many cell rows of the table this cell should span.
Row 1 Col 1
Row 3 Col 2
Forms:
Forms add the ability to web pages to not only provide the person viewing the
document with dynamic information but also to obtain information from the person
viewing it, and process the information.
To insert a form we use the <FORM></FORM> tags. The rest of the form
elements must be inserted in between the form tags.
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR=“FFFFFF”>
</FORM>
</BODY>
</HTML>
Form Attribute:
ACTION: is the URL of the CGI (Common Gateway Interface) program that is going
to accept the data from the form, process it, and send a response back to the
browser.
METHOD: GET (default) or POST specifies which HTTP method will be used to
send the form’s contents to the web server. The CGI application should be written
to accept the data from either method.
Form Elements:
The properties are specified in the TYPE Attribute of the HTML element
<INPUT></INPUT>.
VALUE= The data associated with the variable name to be passed to the THHP
Request
Text boxes: Used to provide input fields for text, phone numbers, dates, etc.
TYPE: text.
MAXLENGHT : determines the maximum number of characters that the field will
accept.
TYPE: password.
Hidden: Used to send data to the CGI application that you don’t want the web surfer to
see, change or have to enter but is necessary for the application to process the form
correctly.
<INPUT TYPE=“HIDDEN”>
TYPE: hidden.
Check Box: Check boxes allow the users to select more than one option.
<INPUT TYPE=“CHECKBOX”>
TYPE: checkbox.
Radio Button: Radio buttons allow the users to select only one option.
<INPUT TYPE=“RADIO”>
TYPE: radio.
CHECKED: is blank or CHECKED as the initial status. Only one radio button can be
checked
Push Button: This element would be used with JavaScript to cause an action to take
place.
<INPUT TYPE=“BUTTON”>
TYPE: button.
Submit: Every set of Form tags requires a Submit button. This is the element causes the
browser to send the names and values of the other elements to the CGI Application
specified by the ACTION attribute of the FORM element.
<INPUT TYPE=“SUBMIT”>
TYPE: submit.
VALUE: determines the text label on the button, usually Submit Query.
Reset: It is a good idea to include one of these for each form where users are entering
data. It allows the surfer to clear all the input in the form.
<INPUT TYPE=“RESET”>
• TYPE: reset.
File Upload: You can use a file upload to allow surfers to upload files to your web
server.
<INPUT TYPE=“FILE”>
• TYPE: file.
<SELECT></SELECT> elements,
A home page could normally be split into sections for introduction, content, and
contact information.
An article should make sense on its own, and it should be possible to read it
independently from the rest of the web site.
Forum post
Blog post
Newspaper article
Notice that NOT all links of a document should be inside a <nav> element. The <nav>
element is intended only for major block of navigation links.
The <aside> element defines some content aside from the content it is placed in (like a
sidebar).
1. Required.
2. Max.
3. Min.
Introduction to CSS
Creating Style Sheets
Like HTML, CSS is an interpreted language. When a Web page request is processed by a
Web server, the server’s response can include style sheets, which are simply collections
of CSS instructions. The style sheets can be included in the servers’ response in three
different ways: through external style sheet files, internal style sheets embedded
directly in the Web page, or inline styles sheets.
Inline Styles
Inline styles are CSS styles that are applied directly to an individual HTML element using
the element’s Style attribute which is available on most HTML elements.
CSS Syntax
Css Syntax consists of Selector and properties with its value. This is called CSS Rule.
Css Selectors
The Selector is the portion of the rule that dictates exactly how the Web browser should
select the elements to apply the style to. CSS includes a variety of types of selectors,
each of which defines a different element selection technique.
Universal Selectors
The Universal Selector indicates that the style should apply to any element in the Web
page. The sample that follows shows a Universal Selector, which would change the font
of any element that supports the font-family property to Arial.
*{
font-family : Arial;
Type Selectors
The Type Selector allows you to create a style that applies to a specific type of HTML
element. The style will then be applied to all elements of that type in the Web page. The
following sample shows a Type Selector configured for the HTM paragraph tag, which
will change the font family of all <p> tags in the Web page to Arial.
P{
font-family: Arial;
Descendant Selectors
Descendant Selectors allow you to create styles that target HTML elements that are
descendants of a specific type of element. The following sample demonstrates a style
that will be applied to any <span> tag that is a descendant of a <div>.
div span {
font-family: Arial;
Child Selectors
The Child Selector is similar to the Descendant Selector except unlike the Descendant
Selector, which searches the entire descendant hierarchy of an element, the Child
Selector restricts its element search to only those elements who are direct children of
the parent element. The following code shows a modification of the Descendant
Selector, making it a Child Selector.
font-family: Arial;
Attribute Selectors
An Attribute Selector allows you to define a style that is applied to elements based on
the existence of element attributes rather than the actual element name. For example,
the following sample creates a style that is applied to any element in the Web page that
has the href attribute set.
*[href] {
font-family: Arial;
Class Selectors
Class Selectors are a special type of CSS selector that allows you to apply a style to any
element with a specific Class name. The Class name is defined in HTML using the Class
attribute, which is present on almost every element. Class Selectors are distinguished
from other Selector types by prefixing them with a single period (.).
.title{
font-size: larger;
font-weight: bold;
ID Selectors
ID Selectors are another special type of CSS Selector that allows you to create styles that
target elements with specific ID values. ID Selectors are distinguished from other
Selector types by prefixing them with a hash mark (#).
#title {
font-size: larger;
font-weight: bold;
Pseudo Classes
CSS also includes a series of pseudo class selectors that give you additional options in
creating Style rules. Pseudo classes can be added to other selectors to allow you to
create more complex rules.
The dynamic pseudo classes are special CSS classes that are applied by the browser
based on actions performed by the end user such as hovering over an element,
activating an element, or giving an element focus.
a:hover{
color: Maroon;
a:active{
color: Silver;
a:focus{
color: Olive;
Selector Grouping
When creating CSS rules, CSS allows you group several selectors together into a single
rule. The following sample demonstrates a single rule that combines three type
selectors:
h1, h2, h3
color: Maroon;
CSS - Backgrounds
This chapter teaches you how to set backgrounds of various HTML elements. You can
set the following background properties of an element −
CSS - Fonts
This chapter teaches you how to set fonts of a content, available in an HTML element.
You can set following font properties of an element −
The font-weight property is used to increase or decrease how bold or light a font
appears. The font-weight property provides the functionality to specify how bold a font is. Possible
values could be normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, and 900 .
The font-size property is used to increase or decrease the size of a font. The font-size
property is used to control the size of fonts. Possible values could be xx-small, x-small, small, medium,
large, x-large, xx-large, smaller, larger, size in pixels or in %.
CSS - Text
The letter-spacing property is used to add or subtract space between the letters
that make up a word.
The word-spacing property is used to add or subtract space between the words of
a sentence.
The white-space property is used to control the flow and formatting of text.
The text-shadow property is used to set the text shadow around a text.
CSS - Links
The :hover signifies an element that currently has the user's mouse pointer
hovering over it.
CSS - Tables
The border-spacing specifies the width that should appear between table cells.
The empty-cells specifies whether the border should be shown if a cell is empty.
CSS - Lists
The list-style-type allows you to control the shape or appearance of the marker.
The list-style-position specifies whether a long point that wraps to a second line
should align with the first line or start underneath the start of the marker.
The list-style-image specifies an image for the marker rather than a bullet point
or number.
The marker-offset specifies the distance between a marker and the text in the
list.
CSS - Visibility
CSS is useful not only for styling elements in a page, but also for positioning elements as
well. CSS actually gives you a much more flexible system for positioning elements than
HTML itself. CSS bases the positioning of elements in a Web page on something called
the box model. Once an element’s box behavior has been determined, it can be
positioned using several different techniques.
A core element of positioning in CSS is the box model. The box model defines how every
element in HTML is treated by the browser as a rectangular box. The box comprises
different parts, including margins, padding, borders, and content. Figure 18-7 shows
how all of these elements are combined to form the box.
CSS provides you with three primary positioning mechanisms: Normal, Absolute, and
Relative. Each type offers a different behavior you can use to lay out the elements in your
page. To specify the type of layout behavior you want an element use, you can set the
CSS position property. Each element can have its own position property set, allowing
you to use multiple positioning schemes within the same Web page.
Normal Positioning
Using Normal positioning, block items flow vertically, and inline items flow horizontally,
left to right. This is the default behavior, and is used when no other value is provided for
the position property.
Relative Positioning
Using Relative positioning, elements are initially positioned using Normal layout. The
surrounding boxes are positioned and then the box is moved based on its offset
properties: top, bottom, left, and right.
Absolute Positioning
Absolute positioning works much like relative positioning, except instead of an element
calculating its offset position based on its position in the normal positioning scheme, the
offsets are calculated based on the position of its closest absolutely positioned ancestor. If
no element exists, then the ancestor is the browser window itself.
Floating Elements
Another option for controlling the position of elements using CSS is the float property.
The float property allows you to float an element to the left or right side of a block. The
floating block is positioned vertically as it would normally be in normal position, but
horizontally shifted as far left or right as possible.
Introduction to JavaScript
Understanding JavaScript
JavaScript is not related to Java, although it is a curly-brace language like Java, C#, C++,
and many other programming languages.
JavaScript is untyped, which means that when you create a variable, you don’t need to
specify its type. This might seem like a feature because you declare a variable with the
var keyword and assign a string to the variable, and later, you can assign a number to
the same variable.
Using variables
One way to store the results of an expression is to assign the results to a variable. A
variable is a named reference to a location in memory for storing data. To create a
variable, use the JavaScript keyword var, as in the following example:
In this example, a variable named totalCost is created, and the result of 3 * 21.15 is
assigned to the totalCost variable. After this variable is created, it can be an operand in
other expressions, such as the following:
A function can be declared by using the function keyword and then providing a name
(also known as an identifier), the optional list of parameters enclosed in parentheses, and
a set of curly braces with the grouping of statements, as follows:
function Add(x, y) {
return x + y;
Introducing jQuery
jQuery is a library of helper functions that are cross browser–compatible. If you feel
comfortable working with JavaScript, you might think that you don’t need jQuery, but
you do. You can minimize the amount of browser-specific code you must write by using
jQuery, an opensource add-in that provides an easy, browser-agnostic means for writing
JavaScript.
jQuery is written in JavaScript, so it is JavaScript. You can read the jQuery source code
to understand how jQuery works. Probably millions of developers use jQuery. It’s easy to
use, it’s stable, it’s fully documented, and it works well with other frameworks.