Creating Responsive Websites Using HTML5 and CSS3: A Perfect Reference for Web Designers Varun Gor download
Creating Responsive Websites Using HTML5 and CSS3: A Perfect Reference for Web Designers Varun Gor download
or textbooks at https://ebookmass.com
https://ebookmass.com/product/creating-responsive-websites-
using-html5-and-css3-a-perfect-reference-for-web-designers-
varun-gor/
https://ebookmass.com/product/website-design-and-development-with-
html5-and-css3-hassen-ben-rebah/
https://ebookmass.com/product/new-perspectives-html5-and-
css3-comprehensive-7th-edition-patrick-m-carey/
https://ebookmass.com/product/new-perspectives-on-html5-css3-and-
javascript-6th-edition-patrick-carey/
https://ebookmass.com/product/python-graphics-a-reference-for-
creating-2d-and-3d-images-2e-2nd-edition-bernard-korites/
blogdown: Creating Websites with R Markdown Yihui Xie
https://ebookmass.com/product/blogdown-creating-websites-with-r-
markdown-yihui-xie/
https://ebookmass.com/product/python-graphics-a-reference-for-
creating-2d-and-3d-images-2nd-edition-bernard-korites/
https://ebookmass.com/product/basics-of-web-design-html5-css-6th-
edition-terry-felke-morris/
https://ebookmass.com/product/basics-of-web-design-html5-css-5th-
edition-terry-felke-morris/
https://ebookmass.com/product/etextbook-978-1305578166-web-design-
with-html-css3-comprehensive-shelly-cashman-series/
Varun Gor
This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.
The publisher, the authors, and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
HTML Elements
HTML elements are the building blocks of web pages, and they define
the structure and content of the page. Each HTML element is
surrounded by opening and closing tags, which tell the browser how to
display the content. Though almost all of the tags have opening and
closing tags, e.g., <tag_name></tag_name>, some tags have just the
opening tag like <img>, <hr/>, etc. We are going to take a look at
various HTML elements that are used to create web pages.
HTML elements can be categorized into several groups based on
their function. Some of the most common categories include structural
elements, text elements, multimedia elements, form elements, and
scripting elements.
Structural Elements
Structural elements are used to define the overall structure of the web
page. They include elements such as the <html>, <head>, <title>, and
<body> tags. The <html> tag is used to define the document type, while
the <head> tag contains information about the document, such as the
title, author, and description. The <body> tag contains the main content
of the web page.
Text Elements
Text elements are used to add text content to the web page. They
include elements such as the <p>, <h1>–<h6>, and <em> tags. The <p>
tag is used to create paragraphs, while the <h1>–<h6> tags are used to
create headings of different sizes. The <em> tag is used to emphasize
text, while the <strong> tag is used to highlight important text.
Here is an example of a heading tag:
<html>
<body>
<h1>This text is Heading 1.</h1>
<h2>This text is Heading 2.</h2>
<h3>This text is Heading 3.</h3>
<h4>This text is Heading 4.</h4>
<h5>This text is Heading 5.</h5>
<h6>This text is Heading 6.</h6>
</body>
</html>
Figure 1-3 shows an HTML file containing heading tag elements.
<html>
<body>
<p>
This paragraph is written inside <p>
element. It will be displayed as continous text in
the browser.
Let us see how does it look on the
browser.
</p>
</body>
</html>
Figure 1-4 shows how it looks in a browser.
Multimedia Elements
Multimedia elements are used to add multimedia content to the web
page, such as images and videos. They include elements such as the
<img> and <video> tags. The <img> tag is used to display images, while
the <video> tag is used to display videos.
Here is a code example for <img>:
<html>
<body>
<img src="../../../html dom.jpg" alt="dom
image">
</body>
</html>
Form Elements
Form elements are used to create forms on the web page, which allow
users to input information. They include elements such as the <form>,
<input>, and <button> tags. The <form> tag is used to create the form,
while the <input> tag is used to create input fields for the user to enter
information. The <button> tag is used to create buttons that the user
can click to submit the form. We are going to take a deeper look at the
form elements later in this book.
Scripting Elements
Scripting elements are used to add interactivity to the web page, such
as animations and user interface elements. They include elements such
as the <script> and <canvas> tags. The <script> tag is used to add
JavaScript code to the web page, while the <canvas> tag is used to
create graphics and animations. We will learn about scripts and
animation in later chapters.
In addition to these categories, there are many other HTML
elements that can be used to create web pages. Some of these elements
are used for more specialized purposes, such as the <audio> tag for
playing audio files or the <iframe> tag for embedding external web
pages within the current page.
It’s important to note that HTML elements are not the only
component of a web page. Cascading Style Sheets and JavaScript are
also used to define the visual appearance and interactivity of the page,
respectively. However, HTML elements provide the foundation for the
page and define its overall structure and content.
In conclusion, HTML elements are the building blocks of web pages.
They define the structure and content of the page, and they are used to
create everything from text to multimedia to forms and interactivity. By
understanding the different types of HTML elements and how they are
used, web developers can create rich and engaging web pages that are
easy to navigate and interact with.
p {
font-family: Arial;
font-size: 22px;
color: #bb0d10;
}
HTML Code:
<html>
<body>
<p>
The properties font-family, font-size,
and color are then defined, which set the font,
font size,
and color of the text within the
paragraph element.
</p>
<link rel="stylesheet"
href="../../css/example.css">
</body>
</html>
Figure 1-6 shows what this code looks like in a browser.
Figure 1-6 CSS applied the font color for the <p> element
In this example, the p selector targets all <p> elements in the HTML
file. The properties font-family, font-size, and color are then defined,
which set the font, font size, and color of the text within the paragraph
element.
CSS works by flowing styles down from the parent element to its
children. This means that if a style is defined for a parent element, it
will be inherited by its child elements unless a different style is
explicitly defined. For example, if a style is defined for the <body>
element of a page, all elements within the body will inherit that style
unless a different style is specified.
In addition to being cascading, CSS uses specificity to determine
which styles should be applied to an element. Specificity refers to the
weight or importance of a style rule. Styles with a higher specificity will
override styles with a lower specificity. Specificity is determined by a
combination of selectors, with more specific selectors taking
precedence over less specific ones.
For example, a style rule that targets a specific ID will have a higher
specificity than a rule that targets a class or element. The following
example demonstrates this:
#header {
background-color: blue;
}
.header {
background-color: red;
}
Here’s the HTML code:
<html>
<body>
<h1 id="header" class="header">This text
is Heading 1.</h1>
<link rel="stylesheet"
href="../../css/example.css">
</body>
</html>
As shown in Figure 1-7, the style rule that targets the #header ID
will be applied, even though the .header class rule comes later in the
file.
CSS Selectors
CSS selectors are a powerful feature of Cascading Style Sheets that
allow developers to target specific elements on a web page and apply
styles to them. CSS selectors make it possible to create unique and
complex styles for different elements and are an essential tool for
creating effective and engaging web designs. In this section, we will
explore the basics of CSS selectors and how they work.
CSS selectors are used to target specific elements on a web page,
such as headings, paragraphs, links, and images. Selectors can be used
to apply styles to individual elements or to groups of elements. There
are several types of CSS selectors; each has its own syntax and
functionality.
Type selectors: Type selectors target elements based on their HTML
tag name. For example, the selector h1 would target all heading level
1 elements on the page. Type selectors are the simplest type of
selector and are often used to apply global styles to all elements of a
particular type.
Class selectors: Class selectors target elements based on their class
attribute. The class attribute is used to assign a name to an element,
which can then be targeted with a selector. For example, the selector
.my-class would target all elements that have the class my-class
assigned to them. Class selectors are often used to apply styles to
specific groups of elements, such as navigation menus or buttons.
ID selectors: ID selectors target elements based on their ID attribute.
The ID attribute is used to assign a unique identifier to an element,
which can then be targeted with a selector. For example, the selector
#my-id would target the element that has the ID my-id assigned to it.
ID selectors are often used to apply styles to specific elements, such
as headers or footer sections.
Attribute selectors: Attribute selectors target elements based on their
attributes, such as the src attribute for images or the href attribute
for links. Attribute selectors can be used to target elements based on
specific attribute values or to target elements that have a particular
attribute assigned to them.
Pseudo-classes and pseudo-elements: Pseudo-classes and pseudo-
elements are used to target elements based on their state or position
within the document. Pseudo-classes are used to target elements
based on user interactions, such as hovering over a link or clicking a
button. Pseudo-elements are used to target specific parts of an
element, such as the first letter of a paragraph or the content of a
link.
CSS selectors are an essential tool for web developers, as they allow
for precise targeting of specific elements on a web page. By using a
combination of type selectors, class selectors, ID selectors, attribute
selectors, pseudo-classes, and pseudo-elements, developers can create
unique and complex styles for different elements on a web page.
Understanding CSS selectors is a fundamental aspect of web
development and is essential for creating effective and engaging web
designs. All these selectors will be covered as part of later chapters.
Summary
This chapter covered the technologies used in web development. It also
covered how HTML is rendered by a browser and its DOM tree, the
different HTML elements, and the way it is being displayed by the
browser using pseudo-code. It covered HTML page structure and how it
can be defined in multiple ways. We also looked at how CSS works
along with HTML and what kinds of problems can be solved using CSS
and different CSS selectors.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
V. Gor, Creating Responsive Websites Using HTML5 and CSS3
https://doi.org/10.1007/978-1-4842-9783-4_2
This chapter covers HTML5 and responsive web design by describing the features
that are supported by modern-day browsers. It covers how to create an HTML5
page and explains why it is easier to write pages with HTML5 than its older
versions. The chapter also covers semantic elements and shows the code to make
it easier to understand the practical usage. Additionally, the chapter explains text-
level semantics in detail, followed by the audio and video capabilities. All these
concepts are supported by code examples and browser screenshots displaying
how a modern-day browser renders the code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=UTF-8" />
Save the previous code with an .html extension, and you have written your
first HTML5 page according to the W3C validator
(http://validator.w3.org)!
The first line of the code declares the new HTML5 doctype; remember,
<!DOCTYPE html> and <!doctype html> are the same; the case does not make any
difference.
The second tag is the first <html> tag, which mentions the language.
<html lang="en">
The <head> tag follows, with character encoding specified using <meta> (this
is a void element and will not require a closing tag). The value for the character
encoding will be UTF-8 (almost every time you create a HTML page) unless there
is a specific requirement otherwise.
HTML5 does not require so many details; it will just work fine with the
following declaration:
If you look closely, there is no ending tag or closing slash, there are no quotes
surrounding attribute values, and there is no type declaration either. Here both
the examples are valid and would work just fine.
In addition to CSS and JavaScript elements, this kind of lenient syntax is
applicable for all HTML tags. A <div> element could be defined as follows:
<div id=wrapper>
This HTML code is a valid <img> tag without an end tag or a slash, without
quotes, and with mixing upper and lowercase. HTML even lets developers write
code without specifying <html>, <body>, and <head> tags, and it still validates.
Although HTML5 is flexible, I still recommend writing a few extra lines of code
to maintain best practices for better code maintainability and ease of
understanding. Hence, writing code in the old style is beneficial. The CSS
declaration shown earlier, for example, can be written as follows:
The quotes and closing slash are in the stylesheet declaration, but the type
attribute is omitted here. This HTML code would not be flagged.
The anchor tag has been revised and can do a few things that the prior version
of HTML didn’t support. The older HTML version needed each element to have its
own anchor tag.
For example, look at the following code snippet:
HTML5 now allows us to group all the elements under the anchor tag, and it
doesn’t require each element to have its own anchor tag. See the following code
snippet:
<a>
<div class="container"> Home </div>
<p> This paragraph is actually a link tagged by
anchor. </p>
<h1> Navigate to Home Page </h1>
</a>
The only restriction here with the anchor tag is that it cannot be grouped with
another anchor tag, and form elements are not allowed to be grouped within the
anchor tag.
There are some features of HTML5 that are obsolete; it won’t complain if you
use them, but you should avoid using them if you can. The HTML5 validator will
generate warnings for these elements.
There are two types of obsolete features: conforming and nonconforming. The
prior definition was for the conforming obsolete feature, whereas a
nonconforming obsolete feature doesn’t guarantee that it will work on all the
browsers. It may work on a few but not others, so you should implement those
types at your own risk. Here is where you can find a list of nonconforming
obsolete features: https://html.spec.whatwg.org/#non-conforming-
features.
<header></header>
<section>
<article>
<figure>
<img>
<figcaption></figcaption>
</figure>
</article>
</section>
<footer></footer>
The following code uses nonsemantic elements:
<div id="header"></div>
<div class="section">
<div class="article">
<div class="figure">
<img>
<div class="figcaption"></div>
</div>
</div>
</div>
<div id="footer"></div>
.superheros {
margin: 0;
padding: 5px;
background-color: lightgray;
}
.superhero {
background: white;
}
.superheros > h2, p {
margin: 4px;
font-size: 90%;
}
</style>
<article class="superheros">
<h1>Most Liked Superheros</h1>
<article class="superhero">
<h2> Batman </h2>
<p>Batman is a superhero appearing in American
comic books published by DC Comics. <br/>
The character was created by artist Bob Kane and
writer Bill Finger, and debuted in the 27th issue of the
comic book</p>
</article>
<article class="superhero">
<h2> Iron Man</h2>
<p>Iron Man is a superhero appearing in American
comic books published by Marvel Comics. <br/>
The character was co-created by writer and
editor Stan Lee, developed by scripter Larry Lieber,
and designed by artists Don Heck and Jack
Kirby</p>
</article>
</article-->>
Figure 2-2 shows what it looks like in a browser (the paragraph in the code is
taken from Wikipedia).
Figure 2-1 Google Chrome displaying the new semantic tags
aside {
width: 30%;
padding-left: 15px;
margin-left: 15px;
float: right;
font-style: italic;
background-color: lightgray;
}
</style>
<p>
Marvel Comics is an American comic book publisher
and the flagship property of Marvel Entertainment,
a division of The Walt Disney Company since
September 1, 2009. Evolving from Timely Comics in 1939,
Magazine Management/Atlas Comics in 1951 and its
predecessor, Marvel Mystery Comics, the Marvel Comics
title/name/brand
was first used in June 1961.
"En ole varma siitä, näkikö hän minut", sanoi Mountain, "mutta
hän tuijotti minuun päin kuten epätoivoinen, ja silloin rohkeus virtasi
minusta kuin rommi pullosta." Kun master kohta sen jälkeen katsoi
toisaalle ja näytti jälleen painuvan ajatuksiinsa, hiipi Mountain pois ja
kääntyi hakemaan apua tovereiltaan.
Nyt seurasi sarja yllätyksiä, sillä vakooja oli tuskin ehtinyt ilmoittaa
toisille keksintönsä, ja he eivät olleet vielä varustautuneet käymään
pakolaisen kimppuun, kun mies jo olikin heidän keskellänsä; hän
käveli aivan rauhallisena kädet selän takana.
"Minkä valitsette?"
Aikaisin yöllä tuli leiriin tieto, että hän oli kipeä, ja heti seuraavana
aamuna hän käski kutsua luokseen Hastien, ja kyseli häneltä kovin
innokkaasti osasiko hän yhtään lääketaitoa. Täten master todellakin
viekkaasti osasi koskettaa entisen teologin turhamaisuuteen. Hastie
tutki häntä; häntä miellytti toisaalta osoittaa tietojansa, toisaalta ei
hänellä niitä ollut, ja kun hän sitäpaitsi oli erittäin epäluuloinen, niin
hän seisoi siinä aivan ällistyneenä, tietämättä, oliko master kipeä vai
oliko hän vain olevinaan. Tässä tilassa palasi hän kumppaniensa luo
ja kertoi heille, että sairas on aivan lähellä kuolemaa (joka
tapauksessa oli hänelle eduksi esittää asiat tällä tavalla).
"Mutta sama se", lisäsi hän kiroten, "vaikka hän siihen hajoaisikin,
on hänen vietävä meidät aarrepaikalle tänä aamuhetkenä."
"Sinä uskot, hän olla mennyt aivan pois?" kysyi hän, kun he
heräsivät elossa kahden.
Matka erämaahan.
(Jatkoa.)
"Käskenkö siis ottaa hänet kiinni ja sitoa?" kysyi Sir William. "Teen
sen, jos vain te suostutte. Jos hänen juttunsa on pelkkää
mielipuolenlorua, niin se on varmaan viisainta."
"Sir William", sanoin minä vihdoin. "En pidä lordia oikein viisaana,
enkä ole pitänyt enää pitkiin aikoihin. Mutta hulluudessakin on
asteita, ja olisiko hänelle tehtävä väkivaltaa — sitä, Sir William, en
minä ole mies päättämään", sanoin minä.
"Entäs tuo toinen?" kysyi hän. "Tietysti minä kuulin mitä lordi
sanoi; mutta kun hänen palvelijansa osoittaa niin suurta
uskollisuutta, täytynee minun otaksua hänessä olleen hienojakin
ominaisuuksia."
"Sir William", virkoin minä, "sanon teille kuinka asia on. Te ette nyt
näe isäntääni edullisessa valossa; teistä näyttänee omituiselta, että
minäkin voin hänestä pitää, mutta sen teen, enkä aivan yksinäni. Jos
hänen pitää takaisin Albanyyn, täytyy sen tapahtua väkivalloin ja
silloin on mennyttä hänen järkensä, ehkäpä henkensäkin. Tämä on
vakaa uskoni, mutta minä olen vallassanne ja valmis tottelemaan, jos
otatte kantaaksenne vastuunalaisuuden."
"No niin, te tulla, te auttaa —" yritti hän sanoa. Mutta nyt oli lordi
astunut Sir Williamin viereen. Kuuvalo lankesi suoraan hänen
kasvoilleen, eikä Secundra ollut vielä saanut sanoja suustaan, kun
hän jo näki ja tunsi herransa vihamiehen. "Hän!" kiljaisi hindu, löi
kätensä yhteen ja vaipui väristen maahan.
"No, no!" sanoi Sir William. "Ei kukaan meistä tee sinulle pahaa,
jos olet viaton; jos taas olet syypää, ei auta yrittääkään paeta.
Annappas kuulua, mitä sinulla on tekemistä täällä hautojen ja
hautaamattomain ruumiitten keskellä."
"Kyllä minä puolustan sinua, jos olet syytön", vastasi Sir William.
"Sen olen sanonut, enkä ymmärrä, miksi sitä epäilet."
"Kaikki murhaajat", huusi Secundra, "sentähden! Hän tappaa —
murhaaja", osoittaen Mountainia; "ne kaksi vuokramurhaajaa",
osoittaen lordia ja minua — "kaikki hirsipuumurhaajia. Oo! Minä
näen kaikki nuorassa. Nyt minä mennä pelastaa sahib; hän näkee te
nuorassa. Sahib", jatkoi hän, hautaa osoittaen, "hän ei kuollut. Hän
haudassa, hän ei kuollut."
"Te hyvä mies", sanoi Secundra. "Nyt minä kaivaa sahib ylös."
"Jumalani!" huusi Mountain, "hän oli sileä kuin lapsi, kun hänet
hautasimme!"
J. D.
H. D.
Hänen veljensä.
Kuoli, kärsittyään eläessään alituisen ja ansaitsemattoman
kovan onnen iskuja,
Melkein samalla hetkellä,
Ja nyt lepää yhdessä haudassa
Veljensä ja vihamiehensä kanssa.
ebookmasss.com