Web Development Notes
Web Development Notes
Content
Objectives
After studying, you will be able to:
Introduction
Responsive web design is a process
of designing and building websites to provide better
accessibility and optimal viewing experience to the user by optimizing it for different devices. With
the growing trend of smart phones and tablets, it has become almost unavoidable to ignore the
optimization of sites for mobile devices. Responsive web design is a preferable alternative and an
efficient way to target a wide range of devices with much less efforts. Responsive layouts
automatically adjust and adapts to any device screen size, whether it is a desktop, a laptop, a
tablet, or a mobile phone. Figure 1 shows the Illustration.
Figure 1
1
Notes
Figure 2
2
Notes
You can also use a free tool, like Google’s Mobile-Friendly Test, to see if pages on your website are
mobile-friendly. While you can achieve mobile-friendliness with other design approaches, such as
adaptive design, responsive web design is the most common because of its advantages.
Figure 3
3
Notes
1. Bad compatibility for the old version of IE browser:If your site users are mostly using the
old version of IE, it is not recommended to do responsive design. That’s a fatal problem
for the older version of IE browser (IE6, IE7, IE8).
2. Slow page loading: Though, responsive websites are easy to maintain, but it sometimes
takes a long time to load the page. It includes some high-resolution images and videos
that sometimes require a lot of time to load.
3. Navigation is tough: Responsive websites are specially designed to fit on small devices.
But maintaining the simplicity of large websites for small devices sometimes becomes
difficult. This is because small devices have less screen size and this turn make it more
difficult to navigate website through small devices.
4. Time-consuming development: Responsive websites are essential but take a lot of time in
the development process as compared to the development time of normal websites.
Figure 4
The CSS classes in the examples could each be assigned to a div within a page's HTML where the
.left, .right, and .middle classes are enclosed within the .content class. The content class could also
be a assigned to a table and the other classes could be assigned to table cells. The fixed width
.content class does not require a defined width since it automatically spans the width of the
enclosed divs or table cells.
So, a fluid layout is a type of webpage design in which layout of the page resizes as the window
size is changed. This is accomplished by defining areas of the page using percentages instead of
fixed pixel widths.In a fluid website layout, also referred to as a liquid layout, the majority of the
components inside have percentage widths, and thus adjust to the user’s screen resolution.It is a
layout in which the width of main container is flexible(in percentage). Whatever the screen-size is,
the layout will remain same. Refer to Figure 5. The image in Figure 5 shows a fluid (liquid) website
4
Notes
layout. While some designers may give set widths to certain elements in fluid layouts, such as
margins, the layout in general uses percentage widths so that the view is adjusted for each user.
Figure 5
Designers may not use fluid page designs for various reasons, but the layout’s benefits are often
overlooked. Below are pros and cons to think about when considering fluid web page design.
Pros
1. Fluid web page design can be more user-friendly, because it adjusts to the user’s set up.
2. The amount of extra white space is similar between all browsers and screen resolutions,
which can be more visually appealing.
3. If designed well, a fluid layout can eliminate horizontal scroll bars in smaller screen
resolutions.
Cons
1. The designer has less control over what the user sees and may overlook problems because
the layout looks fine on their specific screen resolution.
2. Images, video and other types of content with set widths may need to be set at multiple
widths to accommodate different screen resolutions.
3. With incredibly large screen resolutions, a lack of content may create excess white space
that can diminish aesthetic appeal.
<!DOCTYPE html>
<htmllang="en">
<head>
<meta charset="UTF-8">
5
Notes
<style>
*{
margin:0;
box-sizing:border-box;
}
.container{ wi
dth:80%;
margin:auto;
}
header{ padding:10
px;
background:aqua;
}
nav{
padding:10px;
background:gray;
}
main{ display
:flex;
}
aside{ backgr
ound:pink;
flex: 1 0 25%;
padding:10px;
}
section{ background
:yellow;
flex: 1 0 75%;
padding:10px;
}
footer{
padding:10px;
background:#333;
color:#fff;
}
</style>
6
Notes
</head>
<body>
<div class="container">
<header>This is header</header>
<nav>navigation menu</nav>
<main>
<aside>this is left sidebar</aside>
<section>this is right section</section>
</main>
<footer>this is footer</footer>
</div>
</body>
</html>
Figure 6
Task: Develop the following web page using fluid width design
7
Notes
Device Compatibility For devices greater than their Remain Same. Do not
width. compress
Summary
1. Responsive design allows your website content to flow freely across all screen resolutions
and sizes, and renders it to look great on all devices.
2. A fluid design covers the entire browser window by specifying the width in percentages
rather than pixels.
Keywords
RWD
Fluid width
8
Notes
Responsive Web Design
CONTENTS
Objectives
Introduction
Objectives
After studying, you will be able to:
Understand pixels and CSS units
Understand and implement width= the target/context formula
Introduction
Modern content needs to be ready for a variety of viewing environments: smart phones, tablets,
large monitors or even TV screens cover a huge range of sizes, aspect ratios, pixel densities and
viewing distances. A number of tools are available to help developers optimize their layout for the
best experience
em 1 em is the computed value of the For example, the font size <h1> heading elements
font-size on the element on which may be set to 3em and the body kept at 1em,
it is used. making sure that under all display conditions
heading text will be 3 times as large as the body’s.
It must be noted that when used as a font-size
property value, the em unit refers to the font size of
the parent element. Thus, in our example, a <span>
element inside an <h1> with font-size: 2 em would
end up with text 6 times larger than in the body.
ex 1 ex is the current font’s x-height. Rarely used in practice. May be used to size inline
The x-height is usually (but not images to fit the x-height of the current font for
always, e.g., if there is no ‘x’ in the visual harmony.
font) equal to the height of a
lowercase ‘x’
ch 1 ch is the advance of the ‘0’ (zero) Can be used to style monospace text or braille.
glyph in the current font. ‘ch’
stands for character.
rem 1 rem is the computed value of For example, given a root element font-size of
the font-size property for the 20px, setting a 0.5em font-size on <li> elements
document’s root element. would resolve to 10px for first-level <li> but
second-level
This unit is often easier to use
<li> would have a 5px font-size. Setting the font-
than the ‘em’ unit because it is not
size to 0.5rem would result in 10px <li> elements
affected by inheritance as ‘em’
no matter their nesting level.
units are.
vw 1vw is 1% of the width of the Useful to size boxes that adapt to different
viewport. ‘vw’ stands for viewport widths.
‘viewport width’.
vh 1vh is 1% of the height of the Useful to size boxes that adapt to different
viewport. ‘vh’ stands for viewport heights. For example, may be used to set
‘viewport height’. a maximum height on an image so that it does not
exceed the viewport dimensions.
As these values are relative to something, it is important to identify exactly what they are relative
to. For the font relative unit rem then this is always relative to the size of the root element which is
an HTML document is the html element. In the first example below, we have set the html element
to have a font-size of 20 pixels. 1rem is therefore 20 pixels. If we then give an element a width of
10rem, it will become 200 pixels wide (as 20px multiplied by 10 is 200).
Notes
Responsive Web Design
When the other font relative units (em, ex, and ch) are used for the length of an element, they are
relative to the font size as applied to that element. In the second example (the width of the box is
10em), the em unit looks at the font applied to the element which it is sizing and calculates based on
that. So, this box becomes 300 pixels wide as the font-size of the box is 30px.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
html {
font-size: 20px;
.example-rem {
width: 10rem;
font-size: 30px;
.example-em {
width: 10em;
font-size: 30px;
</style>
</head>
<body>
</body>
Notes
Responsive Web Design
</html>
Figure 1
Where font relative units are calculated from font size, the viewport relative units are calculated in
relation to a rectangle known as the initial containing block. On a screen, this has the dimensions
of the viewport. The vw unit is 1/100 of the width of the viewport and vh 1/100 of the height. A
box which has a width of 50vw and a height of 50vh should be half the width and half the height of
the viewport.
The vmin and vmax units are useful because they allow you to size something relative to the larger
or smaller dimension of the viewport. This means that you can make something 50% of the longest
side of the viewport for example. This is especially helpful when someone might hold a device in
landscape or portrait mode. The vmin unit always resolves to the small or vw or vh and vmax to
the larger of vw or vh. Therefore, if you want a width to always be 20% of the longest side of the
device, you can use 20vmax. If the device is held in portrait mode, then 20vmax would be the same
as 20vh. If the device is held in landscape mode, it would be the same as 20vw.
The example below compares a block sized with vw and vh with one sized using vmin and vmax.
On a desktop computer, or a phone in landscape mode, both boxes should appear the same size.
Switch a phone to portrait mode or drag your window so that the width becomes smaller than the
height, and you will see how the second block changes the dimension from which it takes the
calculation. Refer to Figure 2 and Figure 3.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
* { box-sizing: border-box; }
.box {
background-color: rgba(88,104,164,.2);
border-radius: 5px;
Notes
Responsive Web Design
.a {
width: 50vw;
height: 50vh;
.b {
width: 50vmax;
height: 50vmin;
</style>
</head>
<body>
</body>
</html>
Absolute Units
The absolute units map to physical dimensions and do not scale relative to other things on the
screen. Therefore, they are most useful when the output environment is known.The list below
shows the allowed absolute units in CSS:
pc - It is used to define the measurement in picas. 1pc = 12pt so, there 6 picas is equivalent to 1 inch.
Percentage Units
Percentages allow the sizing of elements relative to their containing block. For example, we can set
up the body of a document like so
body {
width: 80%;
max-width: 900px;
Notes
Responsive Web Design
margin-left: auto;
margin-right: auto;
To ensure the body is at most 900px and take 80% of the width of the viewport otherwise. (Note
that CSS pixels are not device pixels)
In most cases, you can use a percentage rather than a length unit for size. This percentage will then
need to be calculated in relation to something, in the same way that a relative length unit is
resolved, and the specification for the layout method you are using will indicate what the
percentage should be a percentage of.
In a specification, where you see <length-percentage> as an allowable value for a length, this
means that the percentage will be resolved to a length before being used. In the below example,
the outer element has a width of 400 pixels, and the first child element a width of 50%. This then
resolves to 200 pixels - 50% of 400.
The second child element has a width which uses calc, to add 50 pixels to 50%, making that block
250 pixels wide. The 50% is therefore resolved to a length and then used in the calculation.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div {
border-radius: 5px;
.wrapper {
width: 400px;
.a {
width: 50%;
}
Notes
Responsive Web Design
.b {
</style>
</head>
<body>
<div class="wrapper">
<div class="a">50%</div>
</div>
</body>
</html>
Figure 4
This is a required step of Responsive Web Design (RWD), which normally takes three steps:
1. Fluid Images - Use CSS Rule img:{max-width:100%;}. This ensures images will fill their
parent element
2. Fluid Grid - Page elements set as relative widths using target ÷ context = result to ensure
they scale appropriately.
3. Media Queries - To create "breakpoints" to enable you to change the layout of the page to
be more suited for larger/smaller screens, rather than just allowing the fluid grid to
continuing scaling the elements to either a ridiculously large or size or an unreadable
small size.
Notes
Responsive Web Design
The two most common instances you would use them are,
Target= 55px
Context= 16px (the default base font size for most browsers)
55 ÷ 16 = 3.4375
Answer = 3.4375em
Lets say you had a image that was 400px wide, your site has a width of 960px and you wanted to
give your image a max width in %.
When working out the % we have to move the decimal point two places to the right to get our
answer.
Result: will therefore be the size of the target expressed as a fraction of the context width.
So in the below image we have a single blue rectangle with a width of 300 pixels. It is surrounded
by nothing other than the page itself, which by default will be 100% the width of the browser
viewport, which in this scenario is 960 pixels. So let’s use the formula on this blue rectangle
element:
Now we need to convert this into a percentage to be able to use it as a relative width, this is simply
done multiply by 100:
Figure 5
So now we change the width of our blue rectangle to 31.25%. Initially we shouldn't see a change,
however when we resize the browser window, we should see that the blue rectangle width
changes taking up 31.25% of the width of the browser viewport, therefore keeping its size
proportional to the original design.
You can also apply this formula to the elements margins (or other positioning properties) so that
its position remains proportional.
Summary
A CSS unit determines the size of a property you're setting for an element or its content.
The various units include relative length, absolute and percentage units
Keywords
CSS units
Notes
Responsive Web Design
Unit 03: HTML5 Structure for Website
Objectives
After studying, you will be able to:
Understand HTML page structure
Understand and implement CSS resets
Introduction
An HTML 5 document mainly consists of a Head and Body. The Head contains the data, which
informs the browser and even web servers that it is an HTML 5 document. On the other hand, the
Body contains content that web browsers actually display. This chapter covers all the major
elements necessary to craft a basic HTML 5 document.
<!Doctype html>
The doctype can be written in lowercase, uppercase, or mixed case. As you noticed, the "5" is
missing from the declaration. Although this web markup is known as "HTML5".
Notes
Responsive Web Design
<!DOCTYPE HTML>
<htmllang="en">
</html>
<meta name="Author">
To define the character encoding for the document, you need to set the charset attribute with the
"utf-8" value in nearly all cases. UTF-8 is the default character encoding for HTML5.
<meta charset="utf-8">
<title>HTML title</title>
Next is the <link> element which sets the relationship between the current document and the
external resource. Generally, it is used to link to the external CSS stylesheet. Required attributes for
the <link> element are rel, href and type.
<head>
<title> HTML title.</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Author">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
2
Notes
Responsive Web Design
...
</body>
Between the body tags, there can be different elements, to which you can give style by using CSS
properties. Just add an id or class selector to your HTML element and in the <style> section
mention your preferred styling options (color, size, font, etc.).
<style>
.header-style {
color: blue;
}
</style>
<body>
<header class="header-style"></header>
</body>
<script src="js/scripts.js"></script>
2
Notes
Responsive Web Design
2
Notes
Responsive Web Design
<head>
<meta charset="utf-8"/>
<title>HTML Page for Testing CSS</title>
<link rel="stylesheet" href="reset.css" media="screen" />
<link rel="stylesheet" href="styles.css" media="screen" />
</head>
2
Notes
Responsive Web Design
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/* End reset styles */
Sprinkled all throughout this, there were plenty of developers who went minimal by just zapping
margin and padding from everything and leaving it at that:
*{
padding: 0;
margin: 0;
}
Normalize stylesheet
If the Meyer's reset seems a bit too much, there is a newer version which takes a slightly different
approach: normalize.css. Instead of trying to eliminate the default browser styles, the
normalize.css instead tries to normalize them to standard values across browsers. This removes
some of the downsides of the Meyer's reset. It is also a newer and actively developed stylesheet, so
it includes more modern HTML elements.
2
Notes
Responsive Web Design
/* Document
========================================================================
== */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
html {
line-height: 1.15; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/* Sections
========================================================================
== */
/**
* Remove the margin in all browsers.
*/
body {
margin: 0;
}
/**
* Render the `main` element consistently in IE.
*/
main {
display: block;
}
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
3
Notes
Responsive Web Design
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content
========================================================================
== */
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
pre {
font-family: monospace, monospace; /* 1
*/ font-size: 1em; /* 2 */
}
/* Text-level semantics
========================================================================
== */
/**
* Remove the gray background on active links in IE 10.
*/
3
Notes
Responsive Web Design
a{
background-color: transparent;
}
/**
* 1. Remove the bottom border in Chrome 57-
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
*/
abbr[title] {
border-bottom: none; /* 1 */
text-decoration: underline; /* 2 */
text-decoration: underline dotted; /* 2 */
}
/**
* Add the correct font weight in Chrome, Edge, and Safari.
*/
b,
strong {
font-weight: bolder;
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp {
font-family: monospace, monospace; /* 1
*/ font-size: 1em; /* 2 */
}
/**
* Add the correct font size in all browsers.
*/
3
Notes
Responsive Web Design
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` elements from affecting the line height in
* all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/* Embedded content
========================================================================
== */
/**
* Remove the border on images inside links in IE 10.
*/
img {
border-style: none;
}
/* Forms
========================================================================
3
Notes
Responsive Web Design
== */
/**
* 1. Change the font styles in all browsers.
* 2. Remove the margin in Firefox and Safari.
*/
button,
input,
optgroup,
select,
textarea {
font-family: inherit; /* 1
*/ font-size: 100%; /* 1 */
line-height: 1.15; /* 1 */
margin: 0; /* 2 */
}
/**
* Show the overflow in IE.
* 1. Show the overflow in Edge.
*/
button,
input { /* 1 */
overflow: visible;
}
/**
* Remove the inheritance of text transform in Edge, Firefox, and IE.
* 1. Remove the inheritance of text transform in Firefox.
*/
button,
select { /* 1 */
text-transform: none;
}
/**
* Correct the inability to style clickable types in iOS and Safari.
3
Notes
Responsive Web Design
*/
button,
[type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button;
}
/**
* Remove the inner border and padding in Firefox.
*/
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0;
}
/**
* Restore the focus styles unset by the previous rule.
*/
button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
outline: 1px dotted ButtonText;
}
/**
* Correct the padding in Firefox.
*/
fieldset {
padding: 0.35em 0.75em 0.625em;
}
3
Notes
Responsive Web Design
/**
* 1. Correct the text wrapping in Edge and IE.
* 2. Correct the color inheritance from `fieldset` elements in IE.
* 3. Remove the padding so developers are not caught out when they zero out
* `fieldset` elements in all browsers.
*/
legend {
box-sizing: border-box; /* 1 */
color: inherit; /* 2 */
display: table; /* 1 */
max-width: 100%; /* 1 */
padding: 0; /* 3 */
white-space: normal; /* 1 */
}
/**
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
*/
progress {
vertical-align: baseline;
}
/**
* Remove the default vertical scrollbar in IE 10+.
*/
textarea {
overflow: auto;
}
/**
* 1. Add the correct box sizing in IE 10.
* 2. Remove the padding in IE 10.
*/
[type="checkbox"],
[type="radio"] {
box-sizing: border-box; /* 1 */
3
Notes
Responsive Web Design
padding: 0; /* 2 */
}
/**
* Correct the cursor style of increment and decrement buttons in Chrome.
*/
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
height: auto;
}
/**
* 1. Correct the odd appearance in Chrome and Safari.
* 2. Correct the outline style in Safari.
*/
[type="search"] {
-webkit-appearance: textfield; /* 1 */
outline-offset: -2px; /* 2 */
}
/**
* Remove the inner padding in Chrome and Safari on macOS.
*/
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* 1. Correct the inability to style clickable types in iOS and Safari.
* 2. Change font properties to `inherit` in Safari.
*/
::-webkit-file-upload-button {
-webkit-appearance: button; /* 1 */
font: inherit; /* 2 */
}
3
Notes
Responsive Web Design
/* Interactive
========================================================================
== */
/*
* Add the correct display in Edge, IE 10+, and Firefox.
*/
details {
display: block;
}
/*
* Add the correct display in all browsers.
*/
summary {
display: list-item;
}
/* Misc
========================================================================
== */
/**
* Add the correct display in IE 10+.
*/
template {
display: none;
}
/**
* Add the correct display in IE 10.
*/
[hidden] {
display: none;
}
3
Notes
Responsive Web Design
Summary
1. HTML is used to design web pages using markup elements or tags. HTML5 is the fifth
version of HTML and includes a number of tags with new functions for formatting and
displaying content.
2. The goal of a reset stylesheet is to reduce browser inconsistencies in things like default line
heights, margins and font sizes of headings, and so on.
Keywords
HTML page structure
CSS reset
Meyer's Reset Code
3
Notes
Objectives
After studying, you will be able to:
Introduction
We will learn about navigation section element and column layouts in HTML and CSS. On a
website, a navigation menu is an organized list of links to other web pages, usually internal pages.
Navigation menus appear most commonly in page headers or sidebars across a website, allowing
visitors to quickly access the most useful pages. Navigation does more than help us move from one
web page to another — it also helps us understand the relationships between individual pages on a
website.In other words, the website’s IA isn’t visible in the navigation interface, but it is the
foundation of that interface. This gives visitors the sense that the content is connected and
categorized to meet their needs and expectations — without actually showing all the spreadsheets
and diagrams that went into identifying and organizing those relationships among your content.
Web development is a playground of innovation and when it appears a new worthy feature, it
usually grows into the soil firmly. It also happened with multi column layout, too. It was adopted
to web development once and now we see how often it is used by modern designers and how fast
it is developing.
<!DOCTYPE html>
<htmllang="en">
<head>
4
Notes
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
nav {
border-bottom: 1px solid black;
}
.navigation ol {
list-style-type: none;
padding: 0;
}
.item {
display: inline-block;
}
</style>
</head>
<body>
<nav class="navigation">
<ol>
<li class="item"><a href="#">Home</a></li>
<li class="item"><a href="#">Products</a></li>
<li class="item"><a href="#">About us</a></li>
</ol>
</nav>
</body>
</html>
Figure 1
4
Notes
If in the above example, display: inline-block property is not used, it leads to a vertical navigation
bar
<!DOCTYPE html>
<htmllang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
nav {
border-bottom: 1px solid black;
}
.navigation ol {
list-style-type: none;
padding: 0;
}
/* .item {
display: inline-block;
} */
</style>
</head>
<body>
<nav class="navigation">
<ol>
<li class="item"><a href="#">Home</a></li>
<li class="item"><a href="#">Products</a></li>
<li class="item"><a href="#">About us</a></li>
</ol>
</nav>
</body>
</html>
4
Notes
Figure 2
The semantics of the nav element is that of providing links. However a nav element doesn't have to
contain a list, it can contain other kinds of content as well. In this navigation block, links are
provided in prose:
<nav>
<h2>Navigation</h2>
<p>
You are on my home page. To the north lies <a href="/blog">my blog</a>, from
whence the sounds of battle can be heard. To the east you can see a large
mountain, upon which many <a href="/school">school papers</a> are littered.
Far up thus mountain you can spy a little figure who appears to be me,
desperately scribbling a <a href="/school/thesis">thesis</a>.
</p>
<p>
To the west are several exits. One fun-looking exit is labeled
<a href="https://games.example.com/">"games"</a>. Another more
boring-looking exit is labeled<a href="https://isp.example.net/">ISP™</a>.
</p>
<p>
To the south lies a dark and dank <a href="/about">contacts page</a>.
Cobwebs cover its disused entrance, and at one point you see a rat run
quickly out of the page.
</p>
</nav>
4
Notes
Figure 3
Since then, CSS has grown, and building columned layouts has become much more accessible and
has much more support than it used to. Moreover, there are many ways to create column layouts
for web pages.
4-column layout
To create a 4-column layout grid with CSS, the code is as follows –
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
*{
box-sizing: border-box;
}
.first, .second, .third, .fourth {
float: left;
width: 25%;
color: white;
padding: 10px;
height: 500px;
text-align: center;
}
.first {
background-color: tomato;
}
4
Notes
.second {
background-color: teal;
}
.third {
background-color: rgb(166, 71, 255);
}
.fourth {
background-color: rgb(255, 71, 194);
}
.container:after {
clear: both;
}
</style>
</head>
<body>
<h1 style="text-align: center;">Four Column grid example</h1>
<div class="container">
<div class="first">
<h1>Some text on the first div</h1>
</div>
<div class="second">
<h1>Some text on the second div</h1>
</div>
<div class="third">
<h1>Some text on the third div</h1>
</div>
<div class="fourth">
<h1>Some text on the fourth div</h1>
</div>
</div>
</body>
</html>
4
Notes
Figure 4
2-column layout
To create a 2-column layout grid with CSS, the code is as follows –
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
.left, .right {
height: 50%;
width: 50%;
position: fixed;
overflow-x: hidden;
padding-top: 20px;
}
.left {
left: 0;
background-color: rgb(36, 0, 95);
}
.right {
right: 0;
background-color: rgb(56, 1, 44);
}
</style>
</head>
<body>
<h1 style="color: black;">Two column layout grid example</h1>
4
Notes
<div class="left">
<h1>Some random text on the left</h1>
</div>
<div class="right">
<h1>Some random text on the right</h1>
</div>
</body>
</html>
Figure 5
<!DOCTYPE html>
<htmllang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multi-column</title>
<style>
.container {
4
Notes
column-count: 4;
}
.first, .second, .third, .fourth {
color: white;
padding: 10px;
height: 500px;
text-align: center;
}
.first {
background-color: tomato;
}
.second {
background-color: teal;
}
.third {
background-color: rgb(166, 71, 255);
}
.fourth {
background-color: rgb(255, 71, 194);
}
</style>
</head>
<body>
<div class="container">
<div class="first">
<h1>Some text on the first div</h1>
</div>
<div class="second">
<h1>Some text on the second div</h1>
</div>
<div class="third">
<h1>Some text on the third div</h1>
</div>
<div class="fourth">
<h1>Some text on the fourth div</h1>
</div>
</div>
</body>
</html>
5
Notes
Figure 6
Similarly, 2-column or 3-column layout can also be created using column-count property in CSS.
You may also modify the above code to include column-gap and column-rule properties. column-
gap is used to specify the gap between the columns while column-ruleproperty sets the width,
style, and color of the rule between the columns of the element
<!DOCTYPE html>
<htmllang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multi-column</title>
<style>
.container {
column-count: 4;
column-gap: 70px;
column-rule: 5px solid black;
}
.first, .second, .third, .fourth {
color: white;
padding: 10px;
height: 500px;
text-align: center;
}
.first {
background-color: tomato;
}
5
Notes
.second {
background-color: teal;
}
.third {
background-color: rgb(166, 71, 255);
}
.fourth {
background-color: rgb(255, 71, 194);
}
</style>
</head>
<body>
<div class="container">
<div class="first">
<h1>Some text on the first div</h1>
</div>
<div class="second">
<h1>Some text on the second div</h1>
</div>
<div class="third">
<h1>Some text on the third div</h1>
</div>
<div class="fourth">
<h1>Some text on the fourth div</h1>
</div>
</div>
</body>
</html>
5
Notes
Figure 7
If you are not using column-rule shorthand property, then column-rule-color, column-rule-style
and column-rule-width can also be used for setting the color, style of border and width of border
respectively.
Summary
1. The <nav> tag is one of the HTML5 elements. It is used to specify a block of navigation
links, either within the current document or to other documents.
2. In web design, columns are often used to separate primary content from secondary and
tertiary content. For example, a common two column layout may include a left column with
navigation links, and a right column for body text.
Keywords
Navigation
Column-layout
2-column layout
4-column layout
5
Notes
Objectives
1. Understand the concept of navigation bars
2. Implement navigation bars with variations
Introduction
GUI includes a navigation system or bar that facilitates information access for users. Links to the
various parts of a website are found in the user interface element of a webpage. Most often, a
navigation bar appears at the top of the page as a horizontal list of links. It can be positioned either
before or below the header, but it must always come before the page's main content. The
navigation of a website must be simple to use. It has a significant impact on the website since it
enables easy access to any part for users.
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
5
Notes
margin: 0;
padding: 0px;
overflow: hidden;
background-color: lightgreen;
}
li {
float: left;
}
li a {
display: block;
color: black;
font-size:20px;
text-align: center;
padding: 10px 20px;
text-decoration: none;
}
.active{
background-color: darkgreen;
color: white;
}
li a:hover {
background-color: yellow;
}
</style>
</head>
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Contact</a></li>
</ul>
</body>
</html>
5
Notes
Figure 1
Border dividers
Using the border-right property, we can place a border between the links in the navigation bar. The
following illustration clarifies it better.
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0px;
overflow: hidden;
background-color: lightgreen;
}
li {
float: left;
border-right: 1px solid darkgreen;
}
li a {
display: block;
color: black;
font-size:20px;
text-align: center;
padding: 10px 20px;
text-decoration: none;
}
.active{
background-color: darkgreen;
5
Notes
color: white;
}
li a:hover {
background-color: yellow;
}
</style>
</head>
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#">Java</a></li>
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
</ul>
</body>
</html>
Figure 2
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
position: fixed;
6
Notes
width:100%;
top:0;
margin: 0;
padding: 0px;
overflow: hidden;
background-color: lightgreen;
}
li {
float: left;
border-right: 1px solid darkgreen;
}
li a {
display: block;
color: black;
font-size:20px;
text-align: center;
padding: 10px 20px;
text-decoration: none;
}
.active{
background-color: darkgreen;
color: white;
}
li a:hover {
background-color: yellow;
color: white;
}
</style>
</head>
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Contact</a></li>
</ul>
<h2 style="padding-top: 200px; text-align: center;">Scroll down the page to see the fixed
navigation bar</h2>
</body>
</html>
6
Notes
Figure 3
In the above image, taking into consideration the position of the scroll bar, it is clear that the
navigation bar is fixed
Sticky Navbar
The element is positioned according to the user's scroll position using the position: sticky;
property. When the scroll reaches a specific position, the items might stick thanks to this CSS
feature. A sticky element switches between fixed and relative property based on the scroll
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
position: sticky;
width:100%;
top:0;
margin: 0;
padding: 0px;
overflow: hidden;
background-color: lightgreen;
}
li {
float: left;
border-right: 1px solid darkgreen;
}
li a {
display: block;
color: black;
position.
6
Notes
font-size:20px;
text-align: center;
padding: 10px 20px;
text-decoration: none;
}
.active{
background-color: darkgreen;
color: white;
}
li a:hover {
background-color: yellow;
}
</style>
</head>
<body>
<h1> Example of sticky navigation bar</h1>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Contact</a></li>
</ul>
<h2 style="padding-top: 200px; padding-bottom:1000px;text-align: center;">Scroll down the page to
see the sticky navigation bar</h2>
</body>
</html>
Figure 5
6
Notes
Figure 6
Dropdown Navbar
Following example explain how to create a dropdown menu inside a navigation bar.
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: lightgreen;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: black;
font-size:20px;
text-align: center;
padding: 10px 20px;
text-decoration: none;
}
.active{
background-color: darkgreen;
6
Notes
color: white;
}
li a:hover , .dropdown:hover
.dropbtn{ background-color: orange;
color: white;
}
.dropdown-content {
display: none;
position: absolute;
background-color: lightblue;
min-width: 160px;
box-shadow: 5px 8px 10px 0px black;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: gray;
color:white;
}
.dropdown:hover .dropdown-content {
display: block;
}
h1,h2,h3{
text-align:center;
color: green;
}
</style>
</head>
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#">About</a></li>
<li class="dropdown">
<a href="#" class="dropbtn">Products</a>
<div class="dropdown-content">
6
Notes
<a href="#">Men</a>
<a href="#">Women</a>
<a href="#">Kids</a>
</div>
</li>
<li><a href="#">Contact</a></li>
</ul>
<h3>To view the dropdown effect, move your mouse over the "Products" section</h3>
</body>
</html>
Figure 7
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 200px;
background-color: lightgreen;
}
li a {
display: block;
6
Notes
color: black;
font-size:20px;
padding: 8px 16px;
text-decoration: none;
}
.active{
background-color: darkgreen;
color: white;
}
li a:hover {
background-color: yellow;
}
</style>
</head>
<body>
<h2>Vertical Navigation Bar</h2>
<ul>
<li><a href="#" class = "active">Home</a></li>
<li><a href = "#">About</a></li>
<li><a href = "#">Products</a></li>
<li><a href = "#">Services</a></li>
<li><a href = "#">Contact</a></li>
</ul>
</body>
</html>
Figure 8
6
Notes
<!DOCTYPE html>
<html>
<head>
<style>
body{
background-color: rgb(184, 250, 184)
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
height:100%;
top:0;
width:150px;
overflow: auto;
background-color: lightgreen;
border: 1px solid darkgreen;
position: fixed;
}
li a {
display: block;
color: black;
font-size:20px;
padding: 10px 20px;
text-decoration: none;
border-bottom: 1px solid black;
}
.active{
background-color: darkgreen;
color: white;
}
li a:hover {
background-color: yellow;
}
</style>
</head>
<body>
6
Notes
<ul>
<li><a href = "#" class = "active">Home</a></li>
<li><a href = "#">About</a></li>
<li><a href = "#">Product</a></li>
<li><a href = "#">Services</a></li>
<li><a href = "#">Contact</a></li>
</ul>
<div style="margin-left:20%;padding-bottom:2000px;">
<h2>Side navigation bar with height: 100%; and position: fixed;</h2>
<h3>Scroll the page, and see how the sidenav sticks to the page</h3>
</div>
</body>
</html>
Figure 9
Summary
1. A navigation bar along X axis is a horizontal navbar.
2. To create a horizontal navbar, float: left can be used for block elements to float next to each
other
3. border-right property can be used to separate the links in a horizontal navigation bar
4. position: fixed is used for a fixed navigation bar
5. position: sticky is used for a sticky navigation bar
6. The difference between position fixed vs sticky is that fixed always positions an element
relative to the viewport, while sticky behaves like a regular element until it reaches the
defined offset and then becomes fixed.
7. height: 100% allows us to create a fixed full-height side navigation bar.
Keywords
Horizontal navbar
Vertical navbar
6
Unit 6: Using CSS
6.1 Header
6.2 Footer
6.3 Example using header, footer and other semantic
elements
6.3
Formatting images in columns
Summary
Keywords
Self Assessment
Answers for Self
Assessment Review
Questions
Objectives
1. Understand and implement header and footer elements
2. Understand and implement the concept of formatting images in columns
Introduction
HTML tags are (primarily) used to format material; they instruct the browser how to present the
content on the page. If you are familiar with HTML in any way, you will be aware of this. They
don't specify the kind of material they include or the function that content serves on the page.By
creating particular tags that make it obvious what function the content those tags contain plays,
Semantic HTML5 tackles this flaw.By including semantic HTML tags on your sites, you can
provide Google and Bing more details about the functions and relative relevance of the various
elements on your website.By using Semantic tags in our code, we can provide additional
information about that document by defining the layout and sections of the webpage.Header and
footer are among the semantic elements in HTML. The material that should be regarded as the
introduction to a page or section is defined by the "header" element.Footer is used at the bottom of
a page or section. Contact details and basic site navigation may be included. Various Semantic tags
are:
Header element – The <header> element defines content that should be considered the
introductory information of a page or section.
Nav element – Main navigation menu links would all be placed in a <nav> tag. But sub navigation
menus elsewhere on the page could also get one.
Main tag – The body of a page should go in the <main> tag – not sidebars and main navigation.
There should be only one per page.
Article element – The <article> element defines self-contained content that could stand
independently of the page or site it’s on. For example, a blog post.
Section element – Using <section> is a way of grouping together nearby content of a similar theme.
A section tag differs to an article tag because it isn’t necessarily self-contained.
Aside element – An <aside> element defines content that’s less important. It’s often used for
sidebars – areas that add complementary but not vital information.
7
Unit 6: Using CSS
Footer element – You would use <footer> at the base of a page or section. It might include contact
information and some site navigation.
6.1Header
The <header>elememt designates introductory information, which is often a collection of
introductions or navigational tools. It could also have a logo, a search form, the author's name, and
other features in addition to certain header components. We can understand this basic header
with the help of following example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
header.page-header {
background-image:url(1.jpg);
background-repeat: no-repeat;
background-size: cover;
display: flex;
height: 150px;
align-items: center;
color: #fff;
}
</style>
</head>
<body>
<header class="page-header">
<h1>This is a header</h1>
</header>
</body>
</html>
7
Unit 6: Using CSS
Figure 1
Another usage
With the exception of when it is nested inside sectioning content, the <header> element has the
same meaning as the site-wide banner landmark function. The header element is not a landmark
in such case. We can understand this with the help of following examples.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<header>
<h1>Main Page Title</h1>
<imgsrc="1.jpg">
</header>
</body>
</html>
7
Unit 6: Using CSS
Figure 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<article>
<header>
<h2>The Planet Earth</h2>
<p>
Posted on Wednesday, <time datetime="2017-10-04">4 October 2017</time> by
Jane Smith
</p>
</header>
<p>
We live on a planet that's blue and green, with so many things still unseen.
</p>
<p><a href="https://example.com/the-planet-earth/">Continue reading…</a></p>
</article>
</body>
</html>
7
Unit 6: Using CSS
Figure 3
6.2Footer
Footer represents data related to the author, data that contains copyright information or some
links related to that data. This author information enclosed within <address> element. This type of
tag known as <footer> tag in HTML. Footer Tag in HTML is defined within <footer>tag.One can use
footer element within <article>, <body>, <aside>, <section>, <nav>, <details>, <fieldset>, or on the
<figure>. It is always placed within the <body> tag. It is included within the individual blocks.
Footer Tag in HTML used to show the footer part of the webpage or any section. <footer> doesn’t
work as sectioning element so it doesn’t create a new section in the outline.
Syntax for <footer> tag:
<body>
<footer>
<p>Some text</p>
</footer>
</body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
footer {
display: flex;
justify-content: center;
padding: 10px;
7
Unit 6: Using CSS
background-color: seagreen;
color: white;
}
</style>
</head>
<body>
<article>
<h1>Companies visited</h1>
<ol>
<li>Amazon.com, Inc.</li>
<li>Wipro Limited</li>
<li>Amdocs</li>
<li>Microsoft Corporation</li>
</ol>
<footer>
<p>Copyright © 2022, ABC Institute of Engineering and Technology</p>
</footer>
</article>
</body>
</html>
Figure 4
<!Doctype Html>
<html>
7
Unit 6: Using CSS
<head>
<title></title>
</head>
<body bgcolor=lightyellow>
<header>
<h1>HTML5 includes new semantics</h1>
<p>It includes semantic tags like header,footer, nav</p>
</header>
<header>
<h1>Example of complete HTML5 Basics</h1>
<h2>The markup of the future under development.</h2>
</header>
<nav>
<h1><p>The nav element represents a section of navigation links. It is suitable for either site
navigation or a table of contents. </p></h1>
<a href=”/”>http://www.gmail.com</a><br>
<a href=”http://www.facebook.com”>Facebook website</a><br>
</nav>
<aside>
<h1>Other education based websites of State</h1>
<a href=”http://mahahsscboard.ac.in”>State Board website</a><br>
<a href=”http://examinfo.mhhsc.ac.in”>Online Exam Website<a/><br>
</aside>
<section>
<h1>Impressive Web Designing</h1>
<p>The aside element is for content that is tangentially related to the content around it, and is
typically useful for marking up sidebars. </p></section><section>
<h1>Articles on:Article tag</h1>
</section>
<article>
<p>The article element represents an independent section of a document, page or site. It is suitable
for content like news or blog articles, forum posts or individual comments.
</p>
</article>
<footer>© 2022 ABC</footer>
</body>
</html>
7
Unit 6: Using CSS
Figure 5
<!DOCTYPE html>
<html>
<style>
*{
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
}
.header {
text-align: center;
padding: 32px;
}
/* Create two equal columns that floats next to each other */
.column {
float: left;
width: 50%;
padding: 10px;
}
.column img {
margin-top: 12px;
}
/* Clear floats after the columns */
8
Unit 6: Using CSS
.row:after {
content: "";
display: table;
clear: both;
}
</style>
<body>
8
Unit 6: Using CSS
<imgsrc="1.jpg" style="width:100%">
</div>
<div class="column">
<imgsrc="1.jpg" style="width:100%">
<imgsrc="1.jpg" style="width:100%">
<imgsrc="1.jpg" style="width:100%">
<imgsrc="1.jpg" style="width:100%">
<imgsrc="1.jpg" style="width:100%">
<imgsrc="1.jpg" style="width:100%">
<imgsrc="1.jpg" style="width:100%">
</div>
</div>
</body>
</html>
Figure 6
8
Unit 6: Using CSS
Figure 7
Summary
1. The <header> element represents a container for introductory content or a set of
navigational links.
2. The <footer> HTML element represents a footer for its nearest ancestor sectioning content
or sectioning root element
Keywords
Header
Footer
Semantic tags
8
Notes
CONTENTS
Objectives
Introduction
Objectives
1. Understand different types of media
2. Understand different types of media outputs
3. Understand and implement media query structure
Introduction
When you wish to alter your website or application based on a device's overall kind (such as print
vs. screen) or particular qualities and attributes (such as screen resolution or browser viewport
width).Without making any changes to your markup, media queries help you alter how your web
pages appear on a variety of devices, including smartphones, tablets, desktop computers, and
more. An expression that matches the type and circumstances of a certain media feature, such as
device width or screen resolution, is included in a media query together with a media type that
represents the media type.A logical expression, media query can be resolved as either true or false.
If the media type supplied in the media query matches the kind of device the document is being
shown on and all media query expressions are met, the query's result will be true. When a media
query returns true, the target device is styled according to the relevant style sheet or style rules.
7.1Media Queries
Different style rules for various media types may be defined thanks to the @media rule, which was
added to CSS2. One set of style guidelines might be used for television-like displays, mobile
devices, printers, computer screens, and so on. Except for print media, these media formats sadly
never received much support from gadgets.CSS3's media queries expanded on the concept of
media types introduced in CSS2 by looking at a device's capabilities rather than its type. Many
items may be checked with media queries, including:
1. dimensions of the viewport
8
Notes
7.2Media types
The different media types include the following:
Value Description
speech Used for screenreaders that "reads" the page out loud
body {
color: black;
background-color: grey;
}
@media print {
body {
background-color: transparent;
}
}
If you don't specify any media type for your CSS, it will automatically have a media type value of
all. These two blocks of CSS are equivalent:
body {
color: black;
background-color: white;
}
@media all {
body {
color: black;
8
Notes
background-color: white;
}
}
Query conditions
You can add conditions to media types. These are called media queries. The CSS is applied only if
the media type matches and the condition is also true. These conditions are called media features.
This is the syntax for media queries:
Let's say you want to apply different styles depending on whether the browser window is in
landscape mode (the viewport width is greater than its height) or portrait mode (the viewport
height is greater than its width). There's a media feature called orientation you can use to test that:
In this case the media type is all. Because that's the default value, you can leave it out if you want:
Example:
<style>
@media screen and (orientation: landscape) {
body::after {
content: "Landscape";
}
}
@media screen and (orientation: portrait) {
body::after {
content: "Portrait";
}
8
Notes
}
body {
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
width: 100vw;
font-size: 10vmax;
}
</style>
The output generated by above example will be Figure 1 if the browser window is of full size
(landscape)
Figure 1
The output changes to Figure 2 once the browser window is reduced to a portrait format,
8
Notes
Figure 2
Use the max-width media feature to apply styles below a certain width:
You can also combine media queries to apply more than one condition. Use the word and to
combine your media queries:
9
Notes
Figure 3
If the media type supplied matches the type of device the document is being shown on and all of
the media query's expressions are true, the result of the query is true. A media query that returns
true applies the associated style sheet or style rules in accordance with the standard cascade rules.
The media type is optional, and the all type will be presumed unless the not or only operators are
used. Additionally, you may use several stylesheets for various media:
9
Notes
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: pink;
}
@media screen and (min-width: 600px) {
body {
background-color: lightgreen;
}
}
</style>
</head>
<body>
</body>
</html>
Figure 4
9
Notes
When the size of the browser window reduces below 600px, following is the output (as in Figure 5).
Figure 5
If the viewport is 600 pixels wide or wider, like in the following example, the menu will float to the
left of the page; otherwise, it will be on top of the content.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.wrapper {overflow: auto;}
#main {margin-left: 4px;}
#leftsidebar {
float: none;
width: auto;
}
#menulist {
margin: 0;
padding: 0;
}
.menuitem {
background: lightgreen;
border: 1px solid #d4d4d4;
9
Notes
border-radius: 4px;
list-style-type: none;
margin: 4px;
padding: 2px;
height: 60px;
}
@media screen and (min-width: 600px) {
#leftsidebar {width: 200px; float: left;}
#main {margin-left: 216px;}
}
</style>
</head>
<body>
<div class="wrapper">
<div id="leftsidebar">
<ul id="menulist">
<li class="menuitem">Menu-item 1</li>
<li class="menuitem">Menu-item 2</li>
<li class="menuitem">Menu-item 3</li>
<li class="menuitem">Menu-item 4</li>
<li class="menuitem">Menu-item 5</li>
</ul>
</div>
<div id="main">
<h1>Resize the browser window to see the effect!</h1>
<p>This example shows a menu that will float to the left of the page if the viewport is 600 pixels
wide or wider. If the viewport is less than 600 pixels, the menu will be on top of the content.</p>
</div>
</div>
</body>
</html>
9
Notes
Figure 6
When the browser window falls below 600px, the following output (Figure 7) is generated.
Figure 7
Summary
1. Different media types include all, print, screen and speech
2. Output using media queries can be achieved on the basis of media type, query conditions
and viewport size
Keywords
Media query
Media
9
Unit 8: Creating responsive websites with media query and
images
Objectives
1. Understand different types of media
2. Understand different types of media outputs
3. Understand and implement media query structure
Introduction
In order to customise a website's layout and the visual appeal dependent on the user's device or
browser, media queries are a crucial component of responsive web design. Developers may
construct websites that offer the best user experience across a variety of devices, from small
smartphones to giant desktop screens, by employing media queries.The theory behind media
inquiries is simple. We can provide certain CSS rules that are activated when predetermined
criteria are satisfied. The dimensions of the screen, its height, its orientation, and its resolution
are frequently part of these requirements. Developers may produce fluid and adaptive designs by
providing several styles and layout characteristics for various circumstances.
99
Unit 8: Creating responsive websites with media query and
images
At around the same moment, each of the three frameworks transitions to the next layout. The one
notable exception to this rule is Semantic UI, which, in contrast to Bootstrap and Tailwind,
implemented bigger layouts sooner (at narrower viewport sizes). Below their smallest
breakpoint, all the frameworks size elements to fill the entire width of the screen.
Here are some common media breakpoints used in responsive web design:
The genuine breakpoints should be chosen based on the particular design objectives and target
market, thus keep in mind that these breakpoints are merely examples. Another common approach
is to set breakpoints for certain sections or elements of a website rather than the entire layout.
10
Unit 8: Creating responsive websites with media query and
images
.container {
width: 100%;
padding: 10px;
}
.menu {
display: none;
}
}
This section defines the styles for small devices with a maximum width of 576 pixels. The
.container element will have a width of 100% (i.e., it will occupy the full width of the parent
container) and a padding of 10 pixels. The .menu element will be hidden (display: none).
This section sets the styles for medium devices with a width between 577 and 992 pixels. The
.container element will have a width of 80% and a padding of 20 pixels. The .menu element will be
displayed as a block (display: block).
This section defines the styles for large devices with a width between 993 and 1200 pixels. The
.container element will have a width of 70% and a padding of 30 pixels. The .menu element will be
displayed as a block.
/* Styles for extra-large devices (above 1200 pixels) */
@media (min-width: 1201px) {
/* Styles for extra-large screens, such as large desktops */
10
Unit 8: Creating responsive websites with media query and
images
.container {
width: 60%;
padding: 40px;
}
.menu {
display: block;
}
}
This section specifies the styles for extra-large devices with a width above 1200 pixels. The
.container element will have a width of 60% and a padding of 40 pixels. The .menu element will be
displayed as a block.
<!DOCTYPE html>
<html>
<head>
<style>
/* Styles for small devices (up to 576 pixels) */
@media (max-width: 576px) {
/* Styles for small screens, such as smartphones */
.container {
width: 100%;
padding: 10px;
background-color: lightblue;
}
.menu {
display: none;
}
}
10
Unit 8: Creating responsive websites with media query and
images
10
Unit 8: Creating responsive websites with media query and
images
In the above code, we have defined media queries with different styles for specific screen widths.
The .container element represents the main content container, and the .menu element represents
a navigation menu.
When you run this code and resize the browser window, you will notice the following changes:
On small screens (up to 576 pixels), the .container element will take up the full width of
the screen with a light blue background. The .menu element will be hidden.
On medium-sized screens (577 to 992 pixels), the .container element will have a width of
80% and a light green background. The .menu element will be displayed as a block.
On large screens (993 to 1200 pixels), the .container element will have a width of 70%
and a light yellow background. The .menu element will be displayed as a block.
On extra-large screens (above 1200 pixels), the .container element will have a width of
60% and a light gray background. The .menu element will be displayed as a block.
By utilizing media breakpoints in this way, you can create a responsive design that adapts to
various screen sizes and provides an optimized user experience across different devices.
The output generated by above example HTML file with Media breakpoint will be in
Figure 1
Figure 2
Figure 3
Using media queries, you can give different image sources or sizes based on the screen
dimensions of the device. This will make the pictures work better on that device. Using CSS media
queries, you can set breakpoints where the source or size of a picture changes. For smaller
screens, you can load smaller images to reduce file size and speed up loading. For larger screens,
you can load bigger or
10
Unit 8: Creating responsive websites with media query and
images
higher-resolution images to make sure the pictures are clear and sharp. This method makes sure
that the picture shown is optimized for each device. This improves performance, speeds up page
loading, and gives the user a better overall experience.
<style>
.responsive-image {
width: 100%;
height: auto;
}
In the CSS code, the.responsive-image class is defined with a width of 100% and a height of auto,
ensuring that the image resizes proportionally.
Inside the media queries, different images are loaded based on the screen width. For screens with
a minimum width of 576px, the content property is used to set the image source to "medium-
image.jpg". Similarly, for screens with a minimum width of 992px, the content property is used to
set the image source to "large-image.jpg".
By using media queries, the appropriate image will be loaded based on the screen size, providing
a responsive image experience. Make sure to adjust the image filenames and paths according to
your actual image files.
Please note that the content property is typically used for pseudo-elements and generated
content, and it may not work as intended for changing the src attribute of an <img> tag. To
dynamically change the image source, you may need to use JavaScript.
<!DOCTYPE html>
<html>
<head>
<title>Image Function Example</title>
<style>
/* Default styles */
img {
display: block;
width: 100%;
height: auto;
10
Unit 8: Creating responsive websites with media query and
images
In the case above, the img element has a basic style with a width of 100% and a height of "auto"
that makes it adaptable.
The content value is used by the different @media searches to set the picture URL based on the
width of the screen. If the width of the screen is less than or equal to 480px, "small-image.jpg"
will be loaded. If the width is less than or equal to 768px, "medium-image.jpg" will be loaded. If
the width is less than or equal to 1024px, "large-image.jpg" will be loaded. Lastly, if the width is
bigger than 1024px, "xlarge-image.jpg" will be loaded.
<!DOCTYPE html>
10
Unit 8: Creating responsive websites with media query and
images
<html>
<head>
<title>Image Function Example</title>
<style>
/* Default styles */
img {
display: block;
width: 100%;
height: auto;
}
10
Unit 8: Creating responsive websites with media query and
images
</html>
Summary
1. Different media types include all, print, screen and speech
2. Output using media queries can be achieved on the basis of media type, query conditions
and viewport size
10
Unit 8: Creating responsive websites with media query and
images
Keywords
Media query
Media
Responsive Images
Handling Images
10
Notes
Summary
Keywords
Self Assessment
Review Questions
Objectives
1. Understand different types of media
2. Understand different types of media outputs
3. Understand and implement media query structure
Introduction
A fluid layout, also called a flexible layout, is a way of designing that lets a website or app's content
change and adapt to fit different screen sizes and devices. Fluid layouts, as opposed to set layouts
with fixed measurements, use relative units and flexible grids to make sure that parts adjust and
move themselves in an equal way, giving users the same experience on all devices. By using media
queries and CSS methods, fluid layouts can adapt to a wide range of screen sizes, from desktop
computers to smartphones. This gives users a design that is easier to use and looks better, as well
as one that fits their needs and preferences.
11
Notes
units, fluid grids, and media queries, you can make a style that works well on a wide range of
devices and screen resolutions and is very flexible and easy to use.
Here's an example of how you can add media queries to a fluid layout:
In this example, the .container class represents the main container element of your fluid layout. By
default, it has a width of 100%, a maximum width of 960 pixels, and some padding. This will
ensure that the layout adjusts fluidly to different screen sizes.
The first media query is defined with @media (min-width: 768px) and targets screens larger than
768 pixels. Within this media query block, you can override the default styles and apply different
styling, such as increasing the padding.
The second media query is defined with @media (min-width: 1200px) and targets screens larger
than 1200 pixels. Here, you can further modify the .container styles, in this case, changing the
maximum width.
You can add more media queries with different breakpoints to fine-tune the layout for various
screen sizes. It's important to consider the needs of your specific design and adjust the styles
accordingly.
Remember to include the appropriate meta tag in the <head> section of your HTML file to ensure
proper viewport scaling:
This tag tells the browser to set the viewport width to the device width and scale the content
accordingly, ensuring that your media queries work as intended on mobile devices.
11
Notes
<!DOCTYPE html>
<html>
<head>
<style>
.navigation-bar {
background-color: #333;
color: #fff;
padding: 10px;
}
@media (max-width: 600px) {
.navigation-bar {
width: 100%;
}
}
</style>
</head>
<body>
<div class="navigation-bar">
<!-- Navigation bar content goes here -->
</div>
</body>
</html>
It's important to create a menu bar that works well on different platforms by making it adaptable.
With so many people using smartphones, tablets, and other devices with different screen sizes, it's
important to make sure the menu bar fits the space without losing usefulness or looks.
Media queries are a key part of flexibility because they let us use different styles depending on the
width of the screen. By using media queries, we can change the style of the menu bar on the fly,
make it fill the width of the device, centre and shrink the name, and adjust the header text
position.
11
Notes
A flexible menu bar that is well-made makes a website or app easier to use and more accessible. It
also makes it easier for users to find their way around. It makes sure that important menu features
are easy to find and are shown in the best way for each screen size, which improves the overall user
experience.
In this chapter, we'll look at real-world cases and explain in detail how to use media queries to
make flexible menu bars. By learning the ideas and methods behind flexible design, you will be
able to make menu bars that fit smoothly on different devices. This will give you a user experience
that works well and looks good.
<!DOCTYPE html>
<html>
<head>
11
Notes
<style>
.navigation-bar {
background-color: #333;
color: #fff;
padding: 10px;
display: flex;
justify-content: center;
}
.logo {
max-width: 100px;
height: auto;
}
.header {
text-align: center;
}
.logo {
max-width: 80px;
margin: auto;
}
}
</style>
</head>
<body>
<div class="navigation-bar">
<imgsrc="lpu1.png" alt="Logo" class="logo">
<h1 class="header">LPU Professional University</h1>
</div>
</body>
</html>
Within the media query, the .logo class has been updated with the margin: auto; property. This
centers the logo horizontally within the navigation bar by setting automatic margins on both the
left and right sides.
11
Notes
By incorporating this change, the logo will be centered and shrunk to a maximum width of 80
pixels when the screen size is 600 pixels or less. The max-width: 80px; property within the media
query allows the logo to adjust and maintain an appropriate size for smaller screens.
Feel free to customize the max-width values and add more styles as needed to achieve your
desired centering and shrinking effect for the logo.
11
Notes
When designing a responsive navigation bar, it is important to ensure that the text alignment of the
header adapts appropriately to different screen sizes. By utilizing media queries, we can target
specific screen widths and adjust the text alignment of the header to provide an optimal user
experience.
In the provided code snippet, a media query with a maximum width of 600 pixels has been
implemented. Within this media query, the text alignment for the header is adjusted using the
.header class and the text-align property.
By default, outside the media query, the header text is centered using text-align: center;, ensuring
it is horizontally centered within the navigation bar.
Within the media query, the .header class is updated with text-align: right;. This change aligns the
header text to the right within the navigation bar when the screen size is 600 pixels or less. This
adjustment allows for better utilization of the available space on smaller devices and ensures a
visually pleasing layout.
You can customize the text alignment styles within the media query to suit your specific design
requirements. By leveraging media queries to adjust the text alignment of the header, you can
create a responsive navigation bar that offers a consistent and user-friendly experience across a
range of devices and screen sizes.
<!DOCTYPE html>
<html>
<head>
<style>
.navigation-bar {
background-color: #784;
color: #fff;
padding: 10px;
display: flex;
justify-content: center;
}
.logo {
max-width: 100px;
height: auto;
}
.header {
text-align: center;
}
.logo {
11
Notes
max-width: 80px;
margin: auto;
}
.header {
text-align: right;
}
}
</style>
</head>
<body>
<div class="navigation-bar">
<imgsrc="lpuonline.png" alt="Logo" class="logo">
<h1 class="header">LPU Online </h1>
</div>
</body>
</html>
Within the media query, the .header class has been updated with the text-align: right; property.
This aligns the header text to the right within the navigation bar on screens with a width of 600
pixels or less.
By incorporating this change, the header text will be aligned to the right when the screen size is
600 pixels or less, allowing for better utilization of the available space on smaller devices.
Feel free to customize the text alignment styles and add more styles as needed to achieve your
desired effect for the header text within the media query.
11
Notes
Summary
Media queries play a crucial role in responsive web design by allowing the adjustment of
styles based on screen size.
The targeted screen width in this example is 600 pixels, which is a common threshold for
smaller devices.
The navigation bar is made to fill the width of the device by setting its width to 100%
within the media query.
Keywords
Media query
Responsive web design
Screen width
Navigation bar
Width adjustment
12
Unit 10: Adding media queries to fluid layout
Objectives
1. Understand different types of media
2. Understand different types of media outputs
3. Understand and implement media query structure
Introduction
A fluid layout, also called a flexible layout, is a way of designing that lets a website or app's content
change and adapt to fit different screen sizes and devices. Fluid layouts, as opposed to set layouts
with fixed measurements, use relative units and flexible grids to make sure that parts adjust and
move themselves in an equal way, giving users the same experience on all devices. By using media
queries and CSS methods, fluid layouts can adapt to a wide range of screen sizes, from desktop
computers to smartphones. This gives users a design that is easier to use and looks better, as well
as one that fits their needs and preferences.
12
Unit 10: Adding media queries to fluid layout
It's important to note that these two types of flexible layouts don't contradict each other and can be
used together to make a more complete and strong adaptable design. By using a mix of relative
units, fluid grids, and media queries, you can make a style that works well on a wide range of
devices and screen resolutions and is very flexible and easy to use.
Here's an example of how you can add media queries to a fluid layout:
In this example, the .container class represents the main container element of your fluid layout. By
default, it has a width of 100%, a maximum width of 960 pixels, and some padding. This will
ensure that the layout adjusts fluidly to different screen sizes.
The first media query is defined with @media (min-width: 768px) and targets screens larger than
768 pixels. Within this media query block, you can override the default styles and apply different
styling, such as increasing the padding.
The second media query is defined with @media (min-width: 1200px) and targets screens larger
than 1200 pixels. Here, you can further modify the .container styles, in this case, changing the
maximum width.
You can add more media queries with different breakpoints to fine-tune the layout for various
screen sizes. It's important to consider the needs of your specific design and adjust the styles
accordingly.
Remember to include the appropriate meta tag in the <head> section of your HTML file to ensure
proper viewport scaling:
This tag tells the browser to set the viewport width to the device width and scale the content
accordingly, ensuring that your media queries work as intended on mobile devices.
12
Unit 10: Adding media queries to fluid layout
<!DOCTYPE html>
<html>
<head>
<style>
.footer {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
12
Unit 10: Adding media queries to fluid layout
<footer class="footer">
<p>© 2023 Lovely Professional University. All rights reserved.</p>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<p>Located in Punjab, India</p>
</footer>
</body>
</html>
The <div class="content"> element represents the website's main content area.
The <h1> heading welcomes users to Lovely Professional University (LPU).
The <img> tag includes the LPU logo (replace "lpu-logo.png" with the actual image file).
The <footer class="footer"> element represents the footer section of the webpage.
CSS styles are applied to the .footer class to provide a visually appealing and consistent design.
The footer includes a <p> tag with a copyright notice mentioning Lovely Professional University
and the current year.
A <nav> element contains an unordered list (<ul>) with links for navigation, such as "Home,"
"About," and "Contact."
A final <p> tag provides additional information, in this case, stating the university's location in
Punjab, India.
By using media queries, the footer's responsiveness is enhanced. In this example, the media query
specifies a maximum screen width of 600 pixels. Inside the media query, the footer layout is
adjusted using flexbox properties. The .footer class is modified to use display: flex; and justify-
content: center;, ensuring the footer content is centered and responsive on smaller devices.
12
Unit 10: Adding media queries to fluid layout
12
Unit 10: Adding media queries to fluid layout
The paragraph content is organized within four columns, typically represented by <div> elements
or any other suitable container. Each column may have its own class, such as <div
class="column">, to facilitate styling and targeting.
Paragraph Content:
Within each column, there are paragraphs of text that provide relevant information, descriptions,
or any desired content. The paragraphs may be written in HTML using <p> tags, allowing for
proper formatting and readability.
Styling and Customization:
The paragraph content can be customized using CSS to match the desired design and layout of the
webpage. We can apply various styles, such as font size, color, margin, or padding, to enhance the
visual appearance of the paragraphs. Additionally, CSS frameworks or libraries like Bootstrap can
be utilized to further streamline the styling process and create responsive column layouts.
By organizing the content into four columns with paragraph elements, you can present
information in a structured and visually pleasing manner. This arrangement allows for better
readability and organization, enabling users to easily comprehend and navigate through the
<!DOCTYPE html>
<html>
<head>
<style>
.column {
width: 25%;
float: left;
padding: 10px;
box-sizing: border-box;
}
12
Unit 10: Adding media queries to fluid layout
</div>
<div class="column">
<p>The university focuses on industry integration, providing students with ample opportunities
for internships, industry exposure, and placements.</p>
</div>
<div class="column">
<p>LPU is committed to holistic development and emphasizes co-curricular activities, cultural
events, and sports to nurture well-rounded individuals.</p>
</div>
</div>
</body>
</html>
In above example, the paragraph content is organized into four columns using <div> elements
with the class column. Each column contains a <p> tag for the respective paragraph content.
The CSS styles define the layout and properties for the columns. By default, the columns are set to
a width of 25% and floated left, allowing them to align horizontally. The padding and box-sizing
properties are used to manage spacing and ensure the box model behaves as expected.
Within the media query, specified with (max-width: 600px), the columns are adjusted to occupy the
full width and the float property is set to none. This ensures that on screens with a width of 600
pixels or less, the columns stack vertically, creating a responsive layout suitable for smaller devices.
12
Unit 10: Adding media queries to fluid layout
<!DOCTYPE html>
<html>
<head>
<style>
.navigation {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #333;
color: #fff;
padding: 10px;
}
13
Unit 10: Adding media queries to fluid layout
.menu {
display: none;
}
In above example, the navigation content is adjusted for visibility on small devices within a media
query targeting a maximum width of 600 pixels. Initially, the navigation is designed as a flex
container (display: flex;) with the logo positioned to the left and an unordered list (ul)
representing the menu positioned to the right. Within the media query, the menu is set to display:
block;, making it visible on small devices. Simultaneously, the unordered list (ul) containing the
navigation links is set to display: none;, hiding it on small devices.
By implementing this approach, the navigation menu is replaced with a menu icon or another
suitable UI element on small devices, ensuring better visibility and usability for users on mobile or
smaller screens. Feel free to customize the styles, layout, and content of the navigation menu to
match your specific design requirements.
13
Unit 10: Adding media queries to fluid layout
Summary
Adjust the footer content to fill the width, hide
the paragraph content in the four columns, adjust the navigation content to make it
more visible on a small deviceThe targeted screen width in this example is 600 pixels,
which is a common threshold for smaller devices.
The navigation bar is made to fill the width of the device by setting its width to 100%
within the media query.
Keywords
Media query
Responsive web
design Paragraph
content Four columns
Adjust navigation
Visibility
Small device
13
Notes
Objectives
Understand the importance of prioritizing content before layout in mobile design to deliver
effective and engaging user experiences.
Comprehend the principles and techniques of responsive design and its significance in ensuring
optimal viewing experiences across various devices and screen sizes.
Identify and utilize appropriate design and prototyping tools for creating mobile interfaces,
enabling efficient and streamlined development processes.
Recognize the key elements of user experience (UX) in the context of mobile and beyond, focusing
on navigation optimization, accessibility, and iterative design for enhanced user satisfaction.
Introduction
In today's world, more and more people are accessing the web on mobile devices. This means that
it's more important than ever to create websites that are responsive to different screen sizes and
orientations. Responsive design is a web design approach that uses fluid grids and flexible layouts
to ensure that a website looks good and functions well on any device. This means that you don't
need to create separate mobile and desktop versions of your website.
There are a number of tools that can help you create responsive websites. Some of the most popular
include:
Bootstrap: Bootstrap is a popular front-end framework that includes a number of responsive CSS
and HTML components.
Foundation: Foundation is another popular front-end framework that offers a wide range of
responsive features.
Semantic UI: Semantic UI is a framework that uses semantic markup to create accessible and
understandable code.
In addition to using the right tools, it's also important to consider the user experience when
designing responsive websites. This means making sure that the content is easy to read and the
navigation is intuitive, regardless of the device being used.
11.1 Creating content before and after use of responsive design tools
Before the advent of responsive design tools, creating content for the web was a bit of a challenge.
If you wanted your website to look good on both desktop and mobile devices, you had to create
two separate versions of your content, one for each device. This was a time-consuming and error-
prone
13
Notes
process. To create content for desktop devices, you would use a fixed-width layout. This meant
that the width of your content would be the same on every device, regardless of the screen size.
This could lead to problems on mobile devices, where the content would be too wide to fit on the
screen.
To create content for mobile devices, you would use a fluid-width layout. This meant that the
width of your content would adjust to the screen size of the device. This was a better solution than
a fixed- width layout, but it still required a lot of manual work to ensure that the content looked
good on all devices.
Creating content after responsive design tools
The introduction of responsive design tools made it much easier to create content that looked
good on all devices. These tools use media queries to dynamically adjust the layout of your content
based on the screen size of the device. This means that you only need to create one version of your
content, and it will automatically look good on all devices.
There are a number of responsive design tools available, including Bootstrap, Foundation, and
Semantic UI. These tools provide a number of features that make it easy to create responsive
content, including:
Fluid grids: Fluid grids allow you to create layouts that adjust to the screen size of the device.
Flexible images: Flexible images resize to fit the width of the container.
Media queries: Media queries allow you to specify different layouts for different screen sizes.
Using responsive design tools makes it easy to create content that looks good on all devices. This is
a major advantage, as it means that you don't have to create separate versions of your content for
each device. This can save you a lot of time and effort, and it can also improve the user experience
for your visitors.
Here are some tips for creating content that looks good on all devices:
Use clear and concise language. This will make your content easier to read on small screens.
Use large fonts. This will also make your content easier to read on small screens.
Use images and videos sparingly. Large images and videos can slow down loading times on mobile
devices.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Responsive Website</title>
</head>
<body>
<h1>This is my responsive website</h1>
<p>This text will look good on all devices, regardless of the screen size.</p>
<imgsrc="image.jpg" alt="Image">
</body>
</html>
In the above example code uses a <meta> tag to set the viewport to the width of the device. This
means that the website will automatically adjust its layout to fit the screen size of the device.
The <p> tag also uses a media query to specify a different font size for mobile devices. This means
that the text will be larger on mobile devices, making it easier to read.
The <img> tag uses a srcset attribute to specify different images for different screen sizes. This
means that the website will automatically load the appropriate image for the device being used.
13
Notes
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Responsive Website</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-
EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>This is my responsive website</h1>
<p class="lead">This text will look good on all devices, regardless of the screen size.</p>
<imgsrc="image.jpg" alt="Image">
</div>
</body>
</html>
This code uses Bootstrap to create a responsive website. Bootstrap is a popular front-end
framework that includes a number of responsive CSS and HTML components.
The <meta> tag sets the viewport to the width of the device. This means that the website will
automatically adjust its layout to fit the screen size of the device.
The <div class="container"> tag creates a container that will be used to hold the content of the
website. This container will be responsive, meaning that it will adjust its width to fit the screen size
of the device.
The <h1> and <p> tags use Bootstrap classes to style the text. These classes will ensure that the text
looks good on all devices, regardless of the screen size.
The <img> tag uses a srcset attribute to specify different images for different screen sizes. This
means that the website will automatically load the appropriate image for the device being used.
<!DOCTYPE html>
<html>
<head>
<title>Lovely Professional University - Responsive Design Example</title>
13
Notes
<style>
/* Default styles for the website */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
.content {
padding: 20px;
text-align: justify;
}
.footer {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
.content {
font-size: 14px;
}
}
</style>
</head>
<body>
13
Notes
<div class="header">
<h1>Lovely Professional University</h1>
</div>
<div class="content">
<h2>About LPU</h2>
<p>Lovely Professional University (LPU) is a private university located in Punjab, India. It is one of
the largest single-campus universities in the country, offering a wide range of undergraduate,
postgraduate, and doctoral programs across various disciplines.</p>
<p>LPU is known for its emphasis on experiential learning, industry collaborations, and global
exposure for students. The university provides state-of-the-art infrastructure, modern facilities,
and a vibrant campus life. It aims to nurture students' talents, foster innovation, and prepare them
for successful careers.</p>
<p>With a focus on holistic development, LPU offers a diverse range of academic, cultural, sports,
and co-curricular activities. The university has a strong commitment to research,
entrepreneurship, and community engagement. </p>
</div>
<div class="footer">
<p>© 2023 Lovely Professional University. All rights reserved. </p>
</div>
</body>
</html>
In the above example, we have a simple webpage layout consisting of a header, content section, and
footer. The CSS styles define the default appearance of the elements. The media query is used to
adjust the styles for small screens (max-width: 600px), providing a responsive design.
In this case, the font sizes are adjusted for smaller screens to improve readability. The header and
footer elements have a larger font size (16px), while the content section has a smaller font size
(14px). This ensures that the text remains legible and the overall layout adapts gracefully to smaller
screens.
By using media queries and adjusting styles based on screen size, we achieve a responsive design
that enhances the user experience. The webpage adapts its layout and typography to different
devices, providing an optimal viewing experience and maintaining readability.
14
Notes
<!DOCTYPE html>
<html>
<head>
<title>Computer Company - Responsive Design Layout Example</title>
<style>
14
Notes
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.container {
max-width: 960px;
margin: 0 auto;
padding: 20px;
}
.header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
.content {
padding: 20px;
text-align: justify;
}
.footer {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
.header, .footer {
font-size: 16px;
}
}
14
Notes
.header, .footer {
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Computer Company</h1>
</div>
<div class="content">
<h2>Welcome to Computer Company!</h2>
<p>Computer Company is a leading provider of cutting-edge computer hardware and software
solutions. We offer a wide range of products, including high-performance desktop computers,
laptops, peripherals, and software applications.</p>
<p>Our team of experts is dedicated to delivering top-quality products that meet the needs of
professionals, businesses, and enthusiasts alike. We strive to provide innovative solutions that
enhance productivity, efficiency, and creativity.</p>
<p>Whether you're a gaming enthusiast, a business professional, or a student, Computer Company
has the perfect technology solutions to empower your work and leisure. Experience the latest
advancements in computer technology with us.</p>
</div>
<div class="footer">
<p>© 2023 Computer Company. All rights reserved.</p>
</div>
</div>
</body>
</html>
In this example, the responsive design layout is customized for a computer-related company. The
HTML structure includes a header, content, and footer sections, contained within a <div> element
with the class "container" to provide a maximum width of 960 pixels and center the layout on the
page.
The CSS styles define the appearance of the elements, including background colors, padding, and
text alignment. Media queries are used to adjust the layout for different screen sizes, with font
sizes decreasing for smaller devices to enhance readability.
14
Notes
You can customize the content within the <div class="content"> section to highlight the unique
offerings, services, or products of your computer-related company. Additionally, feel free to modify
the styling and add relevant images or interactive elements to create a visually appealing and
engaging user experience.
Summary
Prioritize content over layout by understanding user needs and goals. Deliver concise,
well-structured content that engages users effectively.
Implement responsive design techniques to ensure optimal viewing experiences across
different devices and screen sizes. Use CSS media queries to adapt the layout and
elements based on breakpoints.
Utilize design and prototyping tools like Sketch, Figma, or Adobe XD to create mobile
interfaces efficiently. Development frameworks such as React Native or Flutter help build
responsive and cross-platform mobile applications.
Focus on delivering a seamless user experience. Optimize navigation for mobile screens,
ensure fast loading times, implement touch-friendly interactions, personalize content,
and prioritize accessibility.
Iterate and test designs with real users to refine the mobile experience further. Incorporate
user feedback and usability testing to identify areas for improvement and enhance the
overall user experience.
Keywords
Content-first approach
Responsive design
CSS media queries
Design and prototyping tools
Development frameworks
User experience (UX)
14
Unit 12: Working Responsively
Objectives
Understand the importance of prioritizing content before layout in mobile design to deliver
effective and engaging user experiences.
Comprehend the principles and techniques of responsive design and its significance in ensuring
optimal viewing experiences across various devices and screen sizes.
Identify and utilize appropriate design and prototyping tools for creating mobile interfaces,
enabling efficient and streamlined development processes.
Recognize the key elements of user experience (UX) in the context of mobile and beyond, focusing
on navigation optimization, accessibility, and iterative design for enhanced user satisfaction.
Introduction
In today's world, more and more people are accessing the web on mobile devices. This means that
it's more important than ever to create websites that are designed for mobile devices.
Traditionally, websites were designed for desktop computers. This meant that they were often too
large and complex for mobile devices. However, with the rise of mobile devices, it's become
increasingly important to create websites that are designed for mobile first. Mobile-first design is a
web design approach that prioritizes the mobile experience. This means that the website is
designed to be used on mobile devices first, and then adapted for desktop computers. There are a
number of benefits to mobile-first design. First, it ensures that your website is accessible to a
wider audience. Second, it can improve the user experience for mobile users. Third, it can save you
time and money in the long run. In this chapter, we will discuss the importance of mobile-first
design and how to create mobile-friendly websites. We will also discuss some of the tools and
techniques that you can use to create mobile-first websites.
Why is mobile-first design important?
There are a number of reasons why mobile-first design is important. First, as mentioned above,
more and more people are accessing the web on mobile devices. In fact, according to a recent study
by Statista, over 50% of web traffic now comes from mobile devices.
Second, mobile users are different from desktop users. They tend to use their devices in different
ways and have different expectations. For example, mobile users are more likely to use their
devices one-handed, so it's important to make sure that your website is easy to use with one hand.
14
Unit 12: Working Responsively
Third, mobile-first design can improve the user experience for mobile users. This is because mobile-
first websites are designed to be used on mobile devices first, so they are more likely to be
optimized for mobile devices.
12.1 Creating content before and after use of responsive design tools
Before the advent of responsive design tools, creating content for the web was a bit of a challenge.
If you wanted your website to look good on both desktop and mobile devices, you had to create
two separate versions of your content, one for each device. This was a time-consuming and error-
prone process. To create content for desktop devices, you would use a fixed-width layout. This
meant that the width of your content would be the same on every device, regardless of the screen
size. This could lead to problems on mobile devices, where the content would be too wide to fit on
the screen.
To create content for mobile devices, you would use a fluid-width layout. This meant that the
width of your content would adjust to the screen size of the device. This was a better solution than
a fixed- width layout, but it still required a lot of manual work to ensure that the content looked
good on all devices.
Creating content after responsive design tools
The introduction of responsive design tools made it much easier to create content that looked
good on all devices. These tools use media queries to dynamically adjust the layout of your content
based on the screen size of the device. This means that you only need to create one version of your
content, and it will automatically look good on all devices.
There are a number of responsive design tools available, including Bootstrap, Foundation, and
Semantic UI. These tools provide a number of features that make it easy to create responsive
content, including:
Fluid grids: Fluid grids allow you to create layouts that adjust to the screen size of the device.
Flexible images: Flexible images resize to fit the width of the container.
Media queries: Media queries allow you to specify different layouts for different screen sizes.
Using responsive design tools makes it easy to create content that looks good on all devices. This is
a major advantage, as it means that you don't have to create separate versions of your content for
each device. This can save you a lot of time and effort, and it can also improve the user experience
for your visitors.
Here are some tips for creating content that looks good on all devices:
Use clear and concise language. This will make your content easier to read on small screens.
Use large fonts. This will also make your content easier to read on small screens.
Use images and videos sparingly. Large images and videos can slow down loading times on mobile
devices.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Responsive Website</title>
</head>
<body>
<h1>This is my responsive website</h1>
<p>This text will look good on all devices, regardless of the screen size.</p>
<imgsrc="image.jpg" alt="Image">
</body>
</html>
14
Unit 12: Working Responsively
In the above example code uses a <meta> tag to set the viewport to the width of the device. This
means that the website will automatically adjust its layout to fit the screen size of the device.
The <p> tag also uses a media query to specify a different font size for mobile devices. This means
that the text will be larger on mobile devices, making it easier to read.
The <img> tag uses a srcset attribute to specify different images for different screen sizes. This
means that the website will automatically load the appropriate image for the device being used.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Responsive Website</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-
EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>This is my responsive website</h1>
<p class="lead">This text will look good on all devices, regardless of the screen size.</p>
<imgsrc="image.jpg" alt="Image">
</div>
</body>
</html>
This code uses Bootstrap to create a responsive website. Bootstrap is a popular front-end
framework that includes a number of responsive CSS and HTML components.
The <meta> tag sets the viewport to the width of the device. This means that the website will
automatically adjust its layout to fit the screen size of the device.
The <div class="container"> tag creates a container that will be used to hold the content of the
website. This container will be responsive, meaning that it will adjust its width to fit the screen size
of the device.
The <h1> and <p> tags use Bootstrap classes to style the text. These classes will ensure that the text
looks good on all devices, regardless of the screen size.
The <img> tag uses a srcset attribute to specify different images for different screen sizes. This
means that the website will automatically load the appropriate image for the device being used.
14
Unit 12: Working Responsively
capabilities. User experience (UX) focuses on designing interfaces that are intuitive, accessible, and
visually appealing, providing a seamless interaction for users.
<!DOCTYPE html>
<html>
<head>
<title>Lovely Professional University - Responsive Design Example</title>
<style>
/* Default styles for the website */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
.content {
padding: 20px;
text-align: justify;
}
.footer {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
.content {
15
Unit 12: Working Responsively
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="header">
<h1>Lovely Professional University</h1>
</div>
<div class="content">
<h2>About LPU</h2>
<p>Lovely Professional University (LPU) is a private university located in Punjab, India. It is one of
the largest single-campus universities in the country, offering a wide range of undergraduate,
postgraduate, and doctoral programs across various disciplines.</p>
<p>LPU is known for its emphasis on experiential learning, industry collaborations, and global
exposure for students. The university provides state-of-the-art infrastructure, modern facilities,
and a vibrant campus life. It aims to nurture students' talents, foster innovation, and prepare them
for successful careers.</p>
<p>With a focus on holistic development, LPU offers a diverse range of academic, cultural, sports,
and co-curricular activities. The university has a strong commitment to research,
entrepreneurship, and community engagement. </p>
</div>
<div class="footer">
<p>© 2023 Lovely Professional University. All rights reserved. </p>
</div>
</body>
</html>
In the above example, we have a simple webpage layout consisting of a header, content section, and
footer. The CSS styles define the default appearance of the elements. The media query is used to
adjust the styles for small screens (max-width: 600px), providing a responsive design.
In this case, the font sizes are adjusted for smaller screens to improve readability. The header and
footer elements have a larger font size (16px), while the content section has a smaller font size
(14px). This ensures that the text remains legible and the overall layout adapts gracefully to smaller
screens.
By using media queries and adjusting styles based on screen size, we achieve a responsive design
that enhances the user experience. The webpage adapts its layout and typography to different
devices, providing an optimal viewing experience and maintaining readability.
15
Unit 12: Working Responsively
15
Unit 12: Working Responsively
Meanwhile, the unordered list (ul) containing the navigation links is set to display: none;,
effectively hiding it on small devices.
By implementing this approach, the navigation content is adjusted dynamically based on screen
size. On small devices, the regular navigation links are hidden, and a more compact menu
representation becomes visible. This ensures better visibility and usability of the navigation on
smaller screens, enhancing the overall user experience.It's important to note that this is just one
example of adjusting the navigation for small devices. The specific implementation may vary
depending on design preferences and requirements.
<!DOCTYPE html>
<html>
<head>
<title>Computer Company - Responsive Design Layout Example</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.container {
max-width: 960px;
margin: 0 auto;
padding: 20px;
}
.header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
.content {
padding: 20px;
text-align: justify;
}
.footer {
background-color: #333;
color: #fff;
padding: 20px;
15
Unit 12: Working Responsively
text-align: center;
}
.header, .footer {
font-size: 16px;
}
}
.header, .footer {
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Computer Company</h1>
</div>
<div class="content">
<h2>Welcome to Computer Company!</h2>
<p>Computer Company is a leading provider of cutting-edge computer hardware and software
solutions. We offer a wide range of products, including high-performance desktop computers,
laptops, peripherals, and software applications.</p>
<p>Our team of experts is dedicated to delivering top-quality products that meet the needs of
professionals, businesses, and enthusiasts alike. We strive to provide innovative solutions that
enhance productivity, efficiency, and creativity.</p>
<p>Whether you're a gaming enthusiast, a business professional, or a student, Computer Company
has the perfect technology solutions to empower your work and leisure. Experience the latest
advancements in computer technology with us.</p>
</div>
15
Unit 12: Working Responsively
<div class="footer">
<p>© 2023 Computer Company. All rights reserved.</p>
</div>
</div>
</body>
</html>
In this example, the responsive design layout is customized for a computer-related
company. The HTML structure includes a header, content, and footer sections,
contained within a <div> element with the class "container" to provide a maximum
width of 960 pixels and center the layout on the page.
The CSS styles define the appearance of the elements, including background
colors, padding, and text alignment. Media queries are used to adjust the layout for
different screen sizes, with font sizes decreasing for smaller devices to enhance
readability.
You can customize the content within the <div class="content"> section to highlight
the unique offerings, services, or products of your computer-related company.
Additionally, feel free to modify the styling and add relevant images or interactive
elements to create a visually appealing and engaging user experience.
Summary
Prioritize content over layout by understanding user needs and goals.
Deliver concise, well-structured content that engages users effectively.
Implement responsive design techniques to ensure optimal viewing
experiences across different devices and screen sizes. Use CSS media
queries to adapt the layout and elements based on breakpoints.
Utilize design and prototyping tools like Sketch, Figma, or Adobe XD to create
mobile interfaces efficiently. Development frameworks such as React Native
or Flutter help build responsive and cross-platform mobile applications.
Focus on delivering a seamless user experience. Optimize navigation for
mobile screens, ensure fast loading times, implement touch-friendly
interactions, personalize content, and prioritize accessibility.
Iterate and test designs with real users to refine the mobile experience
further. Incorporate user feedback and usability testing to identify areas for
improvement and enhance the overall user experience.
Keywords
Content-first approach
Responsive design
CSS media queries
Design and prototyping tools
Development frameworks
User experience (UX)