Responsive Web Design
Responsive Web Design
Responsive Web Design
Latest Browsers
IDE for designing RWD pages in websites preferably
Visual Studio 2012
HTML5 semantic tags
In-built styles using CSS3
Client side scripting using Java Script
References of Bootstrap 3.3.6
JQuery UI responsive library for animation and events
Single page application using Angular JS
What is HTML5?
<!DOCTYPE html>
<meta charset="UTF-8">
The viewport is the user's visible area of a web page. The viewport
varies with the device, and will be smaller on a mobile phone
than on a computer screen.
The initial-scale=1.0 part sets the initial zoom level when the
page is first loaded by the browser.
Html5 Forms
There are the new input types in HTML5 which we can use as form elements.
color Gives the end user a native color picker to choose a color.
date Offers a datepicker.
email A field for entering e-mail address(es).
month Choose a full month.
number Picking a number.
range Offers a slider to set to a certain value/position.
phone Choosing a telephone number.
time Input a certain time.
url Entering a URL.
week Picking a specific week.
HTML5 New Attributes
The canvas element provides the context for creating dynamic drawing
and images that can be designed with the support of java script.
<canvas id="my-first-canvas" width="360" height="240">
</canvas>
Now we can start drawing on the two-dimensional surface of the canvas element
using the API.
context.strokeRect(20,30,100,50);
Html5 Audio
Embedding an audio file in an HTML5 document is simple:
<audio autoplay=“autoplay” loop=“loop”>
<source src=“mysong.mp3" type="audio/mpeg">
</audio>
Giving users control over the playback of an audio file is a sensible idea that is
easily accomplished using the boolean attribute controls:
The presence of the controls attribute prompts the browser to provide native
controls for playing and pausing the audio, as well as adjusting the volume
FIG 3.05: Use controls to display play, pause, and volume controls for your audio.
Html5 Video
The Html5 video element works like the audio element. It has the optional
autoplay, loop, and preload attributes. We can specify the location of the
video file by either using the src attribute on the video element or by using
source elements nested within the opening and closing <video>tags.
We can choose a representative image for the video and tell the browser to
display it using the poster attribute .
a> The selector, which locates the elements in the HTML document,
Example:
body {
background-color: white; color: gray;
}
Creating an inline style
Example:
We can use the <style> element to create an embedded style sheet within our
HTML document.
<!DOCTYPE html>
<html>
<head>
<title>5555555</title>
<style>
body { background-color: white; color: gray; }
</style>
</head>
<body>
</body>
</html>
Creating an external style sheet
<!DOCTYPE html>
<html>
<head>
<title>ABCD</title>
<link rel='stylesheet' type='text/css' href='Content/default.css' />
</head>
<body> </body>
</html>
The <link> element contains the rel attribute, which specifies the relationship
between the current HTML document and the external file as a style sheet.
The href attribute specifies the relative location of the external CSS file “default.css”.
body { background-color: white; color: gray; }
Element and id selector
Creating an id selector
A class selector is a style with a class name of our choice, prefixed with
the period (.) symbol. This is also called a named style.
The class name can be assigned to any element through the class attribute.
Using descendant selector we can change the style of elements only if the elements are
descendants of another element. For example, we might want to remove the underline
from hyperlinks if they are descendant element of a list item.
li a { text-decoration: none; }
Using child selector we can change the style of elements, if the elements are direct children
of another element. For example, we might want to remove the underline from hyperlinks if
they are children of a list item.
We can group selectors when we will be applying the same style by separating
each selector with a comma.
With CSS, colors can be specified by color names, RGB color values, and RGBA color
values. We can also set the transparency or opacity.
The RGB value is a six character field that represents a two-character hexadecimal
value for the amount of red, then green, and then blue, and is prefixed with the
pound (#) symbol.
h1 { background-color: rgb(255,0,0); }
h1 { background-color: rgb(-100,500,0); } /*interpreted as 0,255,0 */
h1 { background-color: rgb(20%,150%,0%); } /*interpreted as 20%,100%,0% */
rgba function
The rgba function is similar to the rgb function except it has an alpha parameter,
which represents the amount of transparency to use. The alpha parameter value
must be between 0.0 and 1.0, where 0.0 is invisible and 1.0 is fully opaque.
h1 {
background-color: rgba(255,0,0,0.5);
}
h1 {
background-color: rgba(0,255,0,1);
}
h1 {
background-color: rgba(20%,50%,0%, 0.2);
}
p{
border-bottom: 10px;
border-right: 5px;
border-left: 1px;
border-top: 0px;
padding: 1px 2px 3px 4px ;
margin: 15px;
background-color: yellow;
border-style: solid;
border-color: green;
}
Positioning elements
The element can be offset from where it normally appears in the HTML
flow.
#div2 {
background-color: cyan;
position: relative;
top: 15px; left: 30px;
}
With the top set to 15 pixels, div2 and its contents will be pushed down 15
pixels from its normal location. The left setting of 30 pixels will push
div2 and its contents to the right by 30 pixels.
Using the absolute position
The element is removed from the HTML flow and positioned within the first non-
static element. If all parent elements are static (the default), then the element is
positioned within the browser window.
With the top set to 15 pixels, div2 and its contents will be pushed down 15 pixels,
not from its normal location, but from the top of the browser window. The left
setting of 30 will push div2 and its contents to the right by 30 pixels, also not
from its normal location, but from the left side of the browser window.
jQuery is a simplified java script library
consisting of in-built functions that allows us
to develop a client side programming using
“write less and use more features”.
The jQuery support the following action:
HTML/DOM manipulation
CSS manipulation
HTML event methods
Effects and animations
AJAX
Adding to our web pages
We can:
<head>
<script src="jquery-1.11.1.min.js"></script>
</head>
Content Delivery Network
If we don't want to download and host jQuery, we can include it from a CDN
(Content Delivery Network).
• Google CDN:
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
</head>
Microsoft CDN:
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js">
</script>
</head>
Syntax
Examples:
• $(document).ready(function(){
// jQuery methods go here...
});
The element Selector
Example
When a user clicks on a button, all <p> elements will be hidden:
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
The #id Selector
The jQuery #id selector uses the id attribute of an HTML tag to find the
specific element. An id should be unique within a page, so we should use
the #id selector when we want to find a single, unique element.
$("#test")
Example
When a user clicks on a button, the element with id="test" will be hidden:
$(document).ready(function(){
$("button").click(function(){
$("#test").hide();
});
});
The .class selector
$(document).ready(function(){
$("button").click(function(){
$(".test").hide();
});
});
More examples of selectors
Syntax Description
The next step is to define what should happen when the event fires.
We must pass a function to the event:
$("p").click(function(){
// action goes here!!
});
hover()
The hover() method takes two functions and is a combination of the mouseenter()
and mouseleave() methods. The first function is executed when the mouse enters the
HTML element, and the second function is executed when the mouse leaves the
HTML element:
$("#p1").hover(function(){
alert("You entered p1!");
},
function(){
alert("Bye! You now leave p1!");
});
focus()
The focus() method attaches an event handler function to an HTML form
field. The function is executed when the form field gets focus:
• $("input").focus(function(){
$(this).css("background-color","#cccccc");
});
blur()
The blur() method attaches an event handler function to an HTML form
field. The function is executed when the form field loses focus:
• $("input").blur(function(){
$(this).css("background-color","#ffffff");
});
Effects - Hide and Show
With jQuery, we can hide and show HTML elements with the hide()
and show() methods:
$(selector).hide(speed,callback);
$(selector).show(speed,callback);
$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){ $("p").show(); });
Effects - Toggle
– fadeIn()
– fadeOut()
– fadeToggle()
– fadeTo()
jQuery fadeIn() method
Syntax:
$(selector).fadeToggle(speed,callback);
Syntax:
$(selector).fadeTo(speed,opacity,callback);
slideDown()
slideUp()
slideToggle()
Callback Functions
• $("button").click(function(){
$("p").hide("slow", function(){
alert("The paragraph is now hidden");
});
});
Chaining
Example
$("#p1").css("color","red").slideUp(2000).slideDown(2000);
OR
$("#p1").css("color","red")
.slideUp(2000)
.slideDown(2000);
Get Content and Attributes
jQuery DOM Manipulation
jQuery comes with a bunch of DOM related methods that make it easy
to access and manipulate elements and attributes.
Example
$("#btn1").click(function(){
alert("Text: " + $("#test").text());
});
$("#btn2").click(function(){
alert("HTML: " + $("#test").html());
});
The following example demonstrates how to get the value of an input field
with the jQuery val() method:
Example
$("#btn1").click(function(){
alert("Value: " + $("#test").val());
});
Example
$("button").click(function(){
alert($("#w3s").attr("href"));
});
Set Content and Attributes
$("#btn1").click(function(){
$("#test1").text("Hello world!");
});
$("#btn2").click(function(){
$("#test2").html("<b>Hello world!</b>");
});
$("#btn3").click(function(){
$("#test3").val("Dolly Duck");
});
Set Attributes - attr()
The following example demonstrates how to set both the href and title attributes at
the same time:
Example
$("button").click(function(){
$("#w3s").attr({
"href" : "http://www.jQuery.com/jquery",
"title" : "jQuery Tutorial"
});
});
- Get and Set CSS Classes
jQuery has several methods for CSS manipulation.
Syntax:
• $(selector).load(URL, data, callback);
• The required URL parameter specifies the URL we wish to load.
• The optional data parameter specifies a set of query string
key/value pairs to send along with the request.
• The optional callback parameter is the name of a function to be
executed after the load() method is completed.
jQuery $.get() Method
The $.get() method requests data from the server with an HTTP GET request.
Syntax:
• $.get(URL,callback);
Example
• $("button").click(function(){
$.get("demo_test.asp",function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
What is Angular JS?
Angular JS Module and Controller
Use of ng-repeat in Angular JS