Imp Final Unit 1
Imp Final Unit 1
Web 2.0: Basics-RIA Rich Internet Applications - Collaborations tools - Understanding websites and web servers:
Understanding Internet – Difference between websites and web server- Internet technologies Overview –Understanding the
difference between internet and intranet; HTML and CSS: HTML 5.0 , XHTML, CSS 3.
Web 1.0
• Web 1.0 refers to the first stage in the World Wide Web.
• Entirely made up of web pages connected by hyperlinks.
• A set of static web sites that were not yet providing interactive content.
• Used as “Information portal”.
Examples: Amazon,Yahoo,Personal web pages
Web 2.0
• Web 2.0 is the term used to describe a variety of websites and applications that
allow anyone to create and share online information or material they have created.
• It allows people to create, share, collaborate & communicate.
• Allows everyone to produce their content.
• Gives the users the possibility to control their data.
• Web 2.0 allows groups of people to work on a document or spreadsheet
simultaneously.
• In the background a computer keeps track of whom and what changes where and
when.
• Web-based applications can be accessed from anywhere.
• Web 2.0 Examples
• Web applications(GoogleDocs,Flickr)
• Video sharing sites(YouTube)
• Wikis(MediaWiki)
• Blogs(WordPress)
• Social networking(Facebook)
• Micro blogging(Twitter)
• Hosted services(Google Maps)
Advantages and disadvantages of Web 2.0
Dynamic content. Web 2.0 showcases dynamic content that users can interact with and modify, unlike the
restricted, read-only format of Web 1.0.
Increased social networking. Web 2.0 enables people to participate in discussions, share information with friends and
family, and stay in touch with people all around the globe.
Ease of use and information sharing. With Web 2.0, users can easily use, update and share information with a few
clicks. Any editing done on the internet can also be tracked.
Improved marketability. Web 2.0 enables business owners to improve user experience by creating responsive websites.
They can also promote their products online and increase their marketability through interactive advertisement
campaigns.
Improved quality of education. Web 2.0 opens doors to interactive learning and virtual classrooms. For example,
students can extend their range of learning by using online calculators while solving math problems.
Cybersecurity risks. The increased online collaboration that comes with Web 2.0 puts users at increased risk of
downloading malicious viruses and adware and getting afflicted by various cyber attacks, such as spam and phishing
attacks.
Information overload. Web 2.0 is a sea of information that grows incessantly. This can confuse readers and affect the
reliability of the content, as the variety and volume of the information are vast.
Ethics and credibility. Critics of Web 2.0 maintain that it makes it too easy for the average person to affect online
content, which can impact the credibility, ethics and even legality of web content. The extent of data sharing and
gathering also raises concerns about privacy and security.
What is RIA?
• Rich Internet Applications(RIAs) are web applications that have the features and
functionality of traditional desktop applications.
• RIAs typically provide a“no-refresh”look to the user interface.
• RIA provides HDu X–HighDefinition UsereXperience.
RIA Tools
• AdobeFlexa highly productive, open source application framework for
building and maintaining expressive web applications that deploy consistently
on all major browsers, desktops and devices.
• OpenLaszloa open source platform for the development and delivery of Rich
Internet Applications, consists of the LZX programming language and the
OpenLaszlo Server.
• Microsoft Silverlight a powerful development tool for creating engaging,
interactive user experiences for Web and mobile applications.
• JavaFXa software platform for creating and delivering desktop applications,
as well as Rich Internet Applications(RIAs) that can run a cross a wide variety
of devices.
• The logos of RIA tools are shown in figure1.3.
Platforms of RIA
• AdobeFlash
• Java
• MicrosoftSilverlight
• AJAX
Adobe Flash
• Manipulates vector and raster graphics to provide animation of text,drawings,and still
images.
• Supports bidirectional streaming of audio and video.
• It can capture user input via mouse, keyboard, microphone and camera.
• Flash contains an object-oriented language called ActionScript and supports automation
via the JavaScriptFlash language(JSFL).
• Flash content may be displayed on various computer systems and devices, using
AdobeFlashPlayer, some mobile phones and a few other electronic devices (using
FlashLite).
Java
• Java applets are used to create interactive visualization.
• To present video, three dimensional objects and other media.Java applets are more
appropriate for complex visualizations that require significant programming effort in
high level language or communications between applet and originating server.
• JavaFX is considered as another competitor for Rich Internet Applications.
Microsoft Silverlight
• It has emerged as a potential competitor to Flash.
• To provide video streaming for many high profile events, including the 2008 Summer
Olympics in Beijing, the 2010 Winter Olympics in Vancouver, and the 2008
conventions for both major political parties in the United States.
• Silverlight is also used by Netflixforits instant video streaming service.
Characteristics of RIA
• Rich user experience
• Interactive- An RIA can use a wider range of controls that allow greater efficiency and
enhance the user experience.
– Users can interact directly with page elements through editing or drag-and-drop
tools.
– They can also do things like pan a cross a map or other image.
• Responsive
• Low maintenance
• Is plastic(changing,transforming)
• Breaks walled gardens
• Partial-page updating: RIAs incorporate additional technologies, such as real-time
streaming, high-performance client-side virtual machines, and local caching
mechanisms that reduce latency (wait times) and increase responsiveness.
• Better feedback: Because of their ability to change parts of pages without reloading,
RIAs can provide the user with fast and accurate feedback, real-time confirmation of
actions and choices, and informative and detailed error messages.
• Consistency of look and feel: With RIA tools, the user interface and experience with
different browsers and operating systems can be more carefully controlled and made
consistent.
• Offline use: When connectivity is unavailable, it might still be possible to use an RIA if
the app is designed to retain its state locally on the client machine.
• Caching
RIA client has the ability of keeping the server information during a period of time
improving application performance and UI responsiveness.
• Security
RIAs should be as secure as any other web application, and the framework should be
well equipped to enforce limitations appropriately when the user lacks there quired
privileges, especially when running with in a constrained environment such as a
sandbox.
• Advanced Communication
Sophisticated communications with supporting servers through optimized network
protocols can considerably enhance the user experience.
• Rapid Development
An RIA Framework should facilitate rapid development of a rich user experience
through hits easy-to-use interfaces in ways that help developers.
• Improved Features
RIA allow programmers to embed various functionalities in graphics-based web pages
that look fascinating and engaging like desktop applications.
RIA provide complex application screens on which various mixed media, including
different fonts, vector graphic and bitmap files online conferencing etc. are paused by
using different modern development tools.
Advantages of RIA
• Remotely accessed application – The basic principle of RIA is the ability to have any
new user connect and run the application from any location as long as they are
connected to the network.
• Full interactive experience– Unlike Web applications that provide page-by-page
interaction and feedback, RIA provides a full interactive end-user experience.
Application Benefits:
A typical Rich Internet Application is decomposed into three layers is shown in Figure
1.7.
• Presentation layer - contains UI and presentation logic components
• Business layer - contains business logic, business work flow and business entities
components
• Data layer – Contains data access and service agent components.
• It is common in RIAs to move some of business processing and even the data access code
to the client.
• The client may in fact contain some or all of the functionality of the business and data
layers, depending on the application scenario.
UI components
Application façade
- Eases maintenance
- Promotes reusability
- Improves testability
• Extract business rules and other tasks not related to the interface.
• Reuse common presentation logic – (Libraries that contain templates, generalized client-
side validation functions and helper classes)
• Loose couple your client from any remote services it uses.
- Use a message-based interface to communicate with services located on separate
physical tiers.
• Avoid tight coupling to objects in other layers – Use the abstract base classes or
messaging when communicating with other layers of the application.
• Reduce round trips when accessing remote layers – Use coarse grained methods and
execute them asynchronously to avoid blocking or freezing the UI.
• Sensitive business rules should still be executed on the server, because the client logic
can be circumvented.
– synchronous
– asynchronous.
Synchronous web collaboration allows the workers situated at different or same locations work together in real-time or
same time on a project by using online collaboration software. In this type of web collaboration more than two people
are allowed to see and amend the document or information at the same time even if their locations are different. They can
use whiteboard of the web based platform they are using for communication for sharing graphic designs and publishing
applications to solve any problem related to their business
Asynchronous web collaboration allows the people participating on the same project, but at different times, to
collaborate with each other by using web collaboration tools. One of the commonly used means of asynchronous web
collaboration these days is email. Today you can also attach various types of files, forward message and generate groups
through an email message.
Web Page
The Web page is a space of information on the Internet that presents information about a particular person, business, or
organization or cause.
– The Web consists of files, called Web pages (documents).
– It is containing links to resources (text, images, audios, videos, and other data), throughout the Internet
Web Site
Web site can be defined as a collection of web pages which are grouped together and usually connected together in
various ways. Often called a "web site" or simply a "site." The web site usually presents information about a particular
person, business, organization or cause.
Generally there are two types of website styles, Static and Dynamic website:
– A static Website is one that has web pages stored on the server in the same form as the user will view them.
– A dynamic Website is one that does not have web pages stored on the server in the same form as the user will
view them. Instead, the web page content changes automatically and/or frequently based on certain criteria. There
are two meaning for dynamic website. The first is that the web page code is constructed dynamically, piece by
piece. The second one is that the web page content displayed varies based on certain criteria. The criteria may be
pre-defined rules or may be based on variable user input.
Web hosting
After we create a website, it is necessary to store it in a place where it is always available for users. We use Web hosting
services/companies for this purpose. They own web servers that have the ability to store content.
Search engine
Search engines allow us to search in the Internet for information, images and other types of files stored in various
locations available throughout the network. Search engines work according to certain algorithms that show the user
relevant, requested search results. At first, information from the various websites is collected and stored and then
analyzed to organize and save them in the database for future use. When a user enters an inquiry into the search engine,
the database is organized by an index and the user is presented with results that match best the entered search terms.
Therefore, it is important to understand that by using the search engine one does not search the entire Internet but the
search engine’s database. Therefore, we might get different results each time we use different web engines.
4. Internet protocols
– TCP/IP protocol: TCP / IP: This protocol is the main protocol for Internet communication. It defines the rules
that computers need to follow to communicate with other computers via a network.
– HTTP (Hypertext Transfer protocol): is a network protocol that ensures the exchange of almost all types of
resources on the web. With resources, we mean files, pages, images, search results, etc. It is basically, the web
browsers language to send requests to the server. There is also the HTTPS version, which is a secure and
encrypted version for HTTP communications.
Two methods that are mostly used are the GET and POST:
The GET Method
• It is used to retrieve information from a specified URI and is assumed to be a safe,
repeatable operation by browsers, caches and other HTTP aware components
• Operations have no side effects and GET requests can be re-issued.
• For example, displaying the balance of a bank account has no effect on the account and can
be safely repeated.
• Most browsers will allow a user to refresh a page that resulted from a GET, without
displaying any kind of warning
• Proxies may automatically retry GET requests if they encounter a temporary network
connection problem.
• GET requests is that they can only supply data in the form of parameters encoded in the
URI (known as a Query String) – [downside]
• Cannot be unused for uploading files or other operations that require large amounts of data to
be sent to the server.
– FTP(File Transfer Protocol): is used to load (upload) or retrieve (download) files between the client and server
communication, or between two computers on the Internet. In other words, this protocol is responsible for file
transfer on the Internet.
– Internet Service Provider (ISP): Is an organization that provides individuals and other companies’ access to the
Internet and other related services such as e-mail.
Web Server
A Web Server is a computer purposed to runs special serving software. That software "serves" HTML pages and the files
associated with those pages when requested by a client, usually a Web browser. The computer is secured so that only
authorized people can access it to make changes to the data, so, If a person is on the same network as the Web Server, he
or she may be able to save the data directly onto the Web Server computer (if authorized).
Server-side:
– JSP (Java Server Pages)
– ASP (Active Server Pages)
– ASP.NET (next generation of ASP)
– PHP
– Phython
Types of Web Sites There are many types of Web sites, each catering to a particular type of content or use. Hence, few
illustrative but not exhaustive cases are given below:
1) Blog (Web Log): site generally used to post online diaries which may include discussion forums.
2) Social Networking Site: where users could communicate with one another and share media, such as pictures, videos,
music and blogs with other users. These may include games and Web applications.
3) Wiki Site: which users collaboratively edit (such as Wikipedia and Wikihow).
4) Web Portal: that provides a starting point or a gateway to other resources on the Internet.
5) Search Engine Site: a site that provides general information and is intended as a gateway or lookup for other sites like
Google, Yahoo, Bing search engines.
6) Education Site: where teachers, students, or administrators can post information about current events at or involving
their school.
What is the difference between website and web server?
A website is a collection of linked web pages (plus their associated resources) that share a unique domain name. Each
web page of a given website provides explicit links—most of the time in the form of clickable portions of text—that
allow the user to move from one page of the website to another.
A web server is a computer hosting one or more websites. "Hosting" means that all the web pages and their supporting
files are available on that computer. The web server will send any web page from the website it is hosting to any user's
browser, per user request.
HTML 5
HTML is the main markup language for describing the structure of web pages.
HTML stands for HyperText Markup Language. HTML is the basic building block of World Wide Web.
Hypertext is text displayed on a computer or other electronic device with references to other text that
the user can immediately access, usually by a mouse click or key press.
Apart from text, hypertext may contain tables, lists, forms, images, and other presentational elements. It
is an easy-to-use and flexible format to share information over the Internet.
Markup languages use sets of markup tags to characterize text elements within a document, which
gives instructions to the web browsers on how the document should appear.
Example
Try this code »
<img src="kites.jpg" alt="Flying Kites">
<img src="sky.jpg" alt="Cloudy Sky">
<img src="balloons.jpg" alt="Balloons">
Each image must carry at least two attributes: the src attribute, and an alt attribute.
The src attribute tells the browser where to find the image. Its value is the URL of the image file.
Whereas, the alt attribute provides an alternative text for the image, if it is unavailable or cannot
be displayed for some reason. Its value should be a meaningful substitute for the image.
HTML Tables
Creating Tables in HTML
HTML table allows you to arrange data into rows and columns. They are commonly used to
display tabular data like product listings, customer's details, financial reports, and so on.
You can create a table using the <table> element. Inside the <table> element, you can use
the <tr> elements to create rows, and to create columns inside a row you can use the <td>
elements. You can also define a cell as a header for a group of table cells using the <th> element.
The following example demonstrates the most basic structure of a table.
<table>
<tr>
<th>No.</th>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>1</td>
<td>Peter Parker</td>
<td>16</td>
</tr>
<tr>
<td>2</td>
<td>Clark Kent</td>
<td>34</td>
</tr>
</table>
Tables do not have any borders by default. You can use the CSS border property to add borders
to the tables. Also, table cells are sized just large enough to fit the contents by default. To add
more space around the content in the table cells you can use the CSS padding property.
Example
<table>
<thead>
<tr>
<th>Items</th>
<th>Expenditure</th>
</tr>
</thread>
<tbody>
<tr>
<td>Stationary</td>
<td>2,000</td>
</tr>
<tr>
<td>Furniture</td>
<td>10,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Total</th>
<td>12,000</t d
</tfoot>
</table>
HTML Lists
HTML lists are used to present list of information in well formed and semantic way. There are
three different types of list in HTML and each one has a specific purpose and meaning.
Unordered list — Used to create a list of related items, in no particular order.
Ordered list — Used to create a list of related items, in a specific order.
Description list — Used to create a list of terms and their descriptions.
Chocolate Cake
Black Forest Cake
Pineapple Cake
You can also change the bullet type in your unordered list using the CSS list-style-type property.
The following style rule changes the type of bullet from the default disc to square:
Example,
ul {
list-style-type: square;
}
Please check out the tutorial on CSS lists to learn about styling HTML lists in details.
HTML5 Image
The <img> tag is empty, it contains attributes only, and does not have a closing tag.
The src attribute specifies the URL (web address) of the image:
<img src="url">
EXAMPLE
<!DOCTYPE html>
<html>
<body>
<h2>HTML Image</h2>
</body>
</body>
</html>
HTML Form
HTML Forms are required to collect different kinds of user inputs, such as contact details
like name, email address, phone numbers, or details like credit card information, etc.
Forms contain special elements called controls like input box, check boxes, radio-buttons,
submit buttons, etc. Users generally complete a form by modifying its controls e.g. entering text,
selecting items, etc. and submitting this form to a web server for further processing.
The <form> tag is used to create an HTML form. Here's a simple example of a login form:
<form>
<label>Username: <input type="text"></label>
<label>Password: <input type="password"></label>
<input type="submit" value="Submit">
</form>
The following section describes different types of controls that you can use in your form.
Input Element
This is the most commonly used element within HTML forms.
It allows you to specify various types of user input fields, depending on the type attribute. An
input element can be of type text field, password field, checkbox, radio button, submit button,
reset button, file select box, as well as several new input types introduced in HTML5.
The most frequently used input types are described below.
Text Fields
Text fields are one line areas that allow the user to input text.
Single-line text input controls are created using an <input> element, whose type attribute has a
value of text. Here's an example of a single-line text input used to take username:
<form>
<label for="username">Username:</label>
<input type="text" name="username" id="username">
</form>
Password Field
Password fields are similar to text fields. The only difference is; characters in a password field
are masked, i.e. they are shown as asterisks or dots. This is to prevent someone else from
reading the password on the screen. This is also a single-line text input controls created using
an <input> element whose type attribute has a value of password.
<form>
<label for="user-pwd">Password:</label>
<input type="password" name="user-password" id="user-pwd">
</form>
— The output of the above example will look something like this:
Radio Buttons
Radio buttons are used to let the user select exactly one option from a pre-defined set of options.
It is created using an <input> element whose type attribute has a value of radio. For example,
<form>
<input type="radio" name="gender" id="male">
<label for="male">Male</label>
<input type="radio" name="gender" id="female">
<label for="female">Female</label>
</form>
— The output of the above example will look something like this:
Checkboxes
Checkboxes allows the user to select one or more option from a pre-defined set of options. It is
created using an <input> element whose type attribute has a value of checkbox. For example,
<form>
<input type="checkbox" name="sports" id="soccer">
<label for="soccer">Soccer</label>
<input type="checkbox" name="sports" id="baseball">
<label for="baseball">Baseball</label>
</form>
— The output of the above example will look something like this:
Text area
Text area is a multiple-line text input control that allows a user to enter more than one line of
text. Multi-line text input controls are created using an <textarea> element. For example,
<form>
<label for="address">Address:</label>
<textarea rows="3" cols="30" name="address" id="address"></textarea>
</form>
— The output of the above example will look something like this:
Select Boxes
A select box is a dropdown list of options that allows user to select one or more option from a
pull- down list of options. Select box is created using the <select> element and <option> element.
<form>
<label for="city">City:</label>
<select name="city" id="city">
<option value="sydney">Sydney</option>
<option value="melbourne">Melbourne</option>
<option value="cromwell">Cromwell</option>
</select>
</form>
— The output of the above example will look something like this:
Tomato
Orange
DodgerBlue
MediumSeaGreen
Gray
SlateBlue
Violet
<input type="reset" value="Reset">
</form>
HTML5 Colors
<!DOCTYPE html>
<html>
<body>
<h1 style="background-color:Tomato;">Tomato</h1>
<h1 style="background-color:Orange;">Orange</h1>
<h1 style= "background
color:DodgerBlue;">DodgerBlue</h1>
<h1 style="background-color:Gray;">Gray</h1>
<h1 style="background-color:SlateBlue;">SlateBlue</h1>
<h1 style="background-color:Violet;">Violet</h1>
<h1 style="background-color:LightGray;">LightGray</h1>
</body>
</html>
OUTPUT
HTML5 Audio
Example
HTML5 Video
New attributes of form elements like number, date, time, calendar, and range.
A semantic element clearly describes its meaning to both the browser and the developer.
Examples of non-semantic elements: <div> and <span> - Tells nothing about its content.
Examples of semantic elements: <form>, <table>, and <article> - Clearly defines its content.
HTML5 offers new semantic elements to define different parts of a web page:
<article>
<aside>
<details>
<figcaption>
<figure>
<footer>
<header>
<main>
<mark>
<nav>
<section>
<summary>
<time>
According to W3C's HTML5 documentation: "A section is a thematic grouping of content, typically with a
heading."
A home page could normally be split into sections for introduction, content, and contact information.
<section>
<h1>WWF</h1>
<p>The World Wide Fund for Nature (WWF) is. . .</p>
</section>
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
<article>
<header>
<h1>What Does WWF Do?</h1>
<p>WWF's mission:</p>
</header>
<p>WWF's mission is to stop the degradation of our planet's natural environment,
and build a future in which humans live in harmony with nature.</p>
</article>
HTML5 <footer> Element
A footer typically contains the author of the document, copyright information, links to terms of use, contact
information, etc.
<footer>
<p>Posted by: Hege Refsnes</p>
<p>Contact information: <a href="mailto:someone@example.com">
someone@example.com</a>.</p>
</footer>
Example
<figure>
<img src="pic_trulli.jpg" alt="Trulli">
<fig caption>Fig1. - Trulli, Puglia, Italy.</fig caption>
</figure>
Tag Description
<details> Defines additional details that the user can view or hide
To help build highly interactive online pages, CSS3 is invariably used due to its importance in providing
greater options in the design process. When marketing products and services, web design plays a vital part; a
site should be created in a manner that will draw potential customers to explore and revisit a website more
often. Many web design firms are developing and enhancing websites through the use of CSS3 as this is a
great form of web development. This article will help define CSS3 and will point out its advantages.
Definition
The acronym CSS stands for Cascading Style Sheets which is used to augment the functionality, versatility.
and efficient performance of site content. It allows for the creation of content-rich websites that do not
require much weight or codes; this translates into more interactive graphics and animation, superior user-
interface, and significantly more organization and rapid download time.
It is used with HTML to create content structure, with CSS3 being used to format structured content. It is
responsible for font properties, colors, text alignments, graphics, background images, tables and other
components. This tool provides extra capabilities such as absolute, fixed and relative positioning of various
elements. The increasing popularity of CSS3 when used by web design firms stimulates major browsers
such as Google Chrome, Firefox, Safari, and IE9 to adopt and embrace this programming language.
Advantages
Although CSS3 is not the only web development solution, it does allow provide greater advantages for
several reasons.
Customization – A web page can be customized and alterations created in the design by simply
changing a modular file.
Bandwidth Requirements – It decreases server bandwidth requirements, giving rapid download time
when a site is accessed with desktop or hand-held devices, providing an improved user experience.
Consistency – It delivers consistent and accurate positioning of navigational elements on the website.
Appealing – It makes the site more appealing with adding videos and graphics easier.
Viewing – It allows online videos to be viewed without the use of third-party plug-ins.
Visibility – It delivers the opportunity to improve brand visibility by designing effective online pages.
Cost Effective – It is cost-effective, time-saving, and supported by most browsers.
Since the introduction of CSS3, there is greater control of the presentation of content and various elements
on a website; however it is not really responsible for overall design as it only specifies the structure and
content presentation of certain web pages.
Cascading Style Sheets (CSS) are files with styling rules that govern how your website is presented on
screen. CSS rules can be applied to your website’s HTML files in various ways. You can use
an external stylesheet, an internal stylesheet, or an inline style. Each method has advantages that suit
particular uses.
An external stylesheet is a standalone .css file that is linked from a web page. The advantage of external
stylesheets is that it can be created once and the rules applied to multiple web pages. Should you need to
make widespread changes to your site design, you can make a single change in the stylesheet and it will be
applied to all linked pages, saving time and effort.
An internal stylesheet holds CSS rules for the page in the head section of the HTML file. The rules only
apply to that page, but you can configure CSS classes and IDs that can be used to style multiple elements in
the page code. Again, a single change to the CSS rule will apply to all tagged elements on the page.
Inline styles relate to a specific HTML tag, using a style attribute with a CSS rule to style a specific page
element. They’re useful for quick, permanent changes, but are less flexible than external and internal
stylesheets as each inline style you create must be separately edited should you decide to make a design
change.
An HTML page styled by an external CSS stylesheet must reference the .css file in the document head. Once
created, the CSS file must be uploaded to your server and linked in the HTML file with code such as:
You can name your stylesheet whatever you wish, but it should have a .css file extension.
Using internal CSS stylesheets
Rather than linking an external .css file, HTML files using an internal stylesheet include a set of rules in
their head section. CSS rules are wrapped in <style> tags, like this:
<head>
<style type="text/css">
h1
{ color:#fff
margin-left: 20px;
}
p{
font-family: Arial, Helvetica, Sans
Serif;
}
</style>
</head>
Inline styles are applied directly to an element in your HTML code. They use the style attribute, followed by
regular CSS properties.
For example:
Rule Cascading
CSS stands for Cascading Style Sheets, and that first word cascading is incredibly important to understand
— the way that the cascade behaves is key to understanding CSS.
At some point, we will find that the CSS have created two rules which could potentially apply to the same
element. The cascade, and the closely-related concept of specificity, are mechanisms that control which
rule applies when there is such a conflict. Which rule is styling your element may not be the one you
expect, so you need to understand how these mechanisms work.
Also significant here is the concept of inheritance, which means that some CSS properties by default inherit
values set on the current element's parent element, and some don't. This can also cause some behavior that
you might not expect.
CASCADE:
Stylesheets cascade — at a very simple level this means that the order of CSS rules matter; when two rules
apply that have equal specificity the one that comes last in the CSS is the one that will be used.
EXAMPLE
In the below example, we have two rules that could apply to the h1. The h1 ends up being colored blue
— these rules have an identical selector and therefore carry the same specificity, so the last one in the
source order wins.
h1 {
} color: red;
h1 {
[Type text]
color: blue;
<h1>This is my heading.</h1>
Inheritance
Inheritance also needs to be understood in this context — some CSS property values set on parent
elements are inherited by their child elements, and some aren't.
For example, if you set a color and font-family on an element, every element inside it will also be styled
with that color and font, unless you've applied different color and font values directly to them.
Some properties do not inherit — for example if you set a width of 50% on an element, all of its
descendants do not get a width of 50% of their parent's width. If this was the case, CSS would be very
frustrating to use!
body {
color: blue;
}
span {
color: black;
}
p>As the body has been set to have a color of blue this is inherited through the descendants.</p>
<p>We can change the color by targetting the element with a selector, such as this
<span>span</span>.</p>
With CSS3 you can create two types of shadows: text-shadow (adds shadow to text) and box-shadow (adds
shadow to other elements).
Examples:
[Type text]
Normal text shadow
h1 {
text-shadow: 2px 2px 5px crimson;
h1 {
text-shadow: 0 0 4px #00FF9C;
Examples:
.first-div {
box-shadow: 1px 1px 5px 3px grey;
}
[Type text]
CSS Animations
You can change as many CSS properties you want, as many times you
want.
To use CSS animation, you must first specify some keyframes for the animation.
Keyframes hold what styles the element will have at certain times.
When you specify CSS styles inside the @keyframes rule, the animation will gradually change from the
current style to the new style at certain times.
The following example binds the "example" animation to the <div> element. The animation will last for
4 seconds, and it will gradually change the background-color of the <div> element from "red" to
"yellow":
Example
/* The animation code */
@keyframes example {
[Type text]
to {background-color: yellow;}
}
Note: The animation-duration property defines how long time an animation should take to complete. If
the animation-duration property is not specified, no animation will occur, because the default value is 0s (0
seconds).
In the example above we have specified when the style will change by using the keywords "from" and "to"
(which represents 0% (start) and 100% (complete)).
It is also possible to use percent. By using percent, you can add as many style changes as you like.
The following example will change the background-color of the <div> element when the animation is 25%
complete, 50% complete, and again when the animation is 100% complete:
Example
/* The animation code */
@keyframes example {
0% {background-color: red;}
25% {background-color: yellow;}
50% {background-color: blue;}
100% {background-color: green;}
}
The following table lists the @keyframes rule and all the CSS animation properties:
Property Description
[Type text]
animation-direction Specifies whether an animation should be played forwards,
backwards or in alternate cycles
animation-fill-mode Specifies a style for the element when the animation is not
playing (before it starts, after it ends, or both)
CSS Transitions
CSS Transitions is a module of CSS that lets you create gradual transitions between the values of specific
CSS properties. The behavior of these transitions can be controlled by specifying their timing function,
duration, and other attributes.
Properties
transition
transition-delay
transition-duration
transition-property
transition-timing-function
The transition CSS property is a shorthand property for transition-property, transition-duration,
transition-timing-function, and transition-delay.
Example
Hover over a <div> element to gradually change the width from 100px to 300px:
div {
width: 100px;
transition: width 2s;
}
div:hover {
width: 300px;
}
Definition and Usage
transition-property
transition-duration
transition-timing-function
Property Values
Value Description
transition-property Specifies the name of the CSS property the transition effect is for
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit
Example
When an <input type="text"> gets focus, gradually change the width from
100px to 250px:
input[type=text] {
width: 100px;
transition: width .35s ease-in-out;
}
input[type=text]:focus {
}
OUTPUT
Set the width of the input field to 100 pixels. However, when the input field gets focus, make it 250 pixels
wide:
Search:
CSS background-color
Example
The background color of a page is set like this:
body {
background-color: lightblue;
}
CSS background-image
The background-image property specifies an image to use as the background of an element. By default, the
Example
The background image for a page can be set like this:
body {
background-image: url("paper.gif");
}
CSS background - Shorthand property
To shorten the code, it is also possible to specify all the background properties in one single property.
This is called a shorthand property.
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
As you can see from the examples above, there are many properties to
consider when dealing with borders.
To shorten the code, it is also possible to specify all the individual border
properties in one property.
The border property is a shorthand property for the following individual border
properties:
border-width
border-style (required)
border-color
Example
p{
border: 5px solid red;
}
Result:
Some text