Web Design and Development Lecture 4
Web Design and Development Lecture 4
development
Lecture 4
Course Instructor: Wardah Mahmood
Email Id: wardah.mahmood@riphah.edu.pk
<div>, <float> and <clear>
• The div tag is used to separate the content in multiple partitions.
• It is used to group relevant content in one section.
• Float is used to align and execute multiple divs in parallel.
• Clear is used to clear the right, left or both sides of the partition.
• Let’s practice an example.
HTML CSS
• What is CSS?
• Styling with Cascading Stylesheets (CSS)
• Selectors and style definitions
• Linking HTML and CSS
• Fonts, Backgrounds, Borders
• The Box Model
• Alignment, Z-Index, Margin, Padding
• Positioning and Floating Elements
• Visibility, Display, Overflow
• CSS Development Tools
CSS: A new philosophy
• Separate content from presentation!
Content Presentation
(HTML document) (CSS Document)
Title
Bold
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit.
Suspendisse at pede ut purus Italics
malesuada dictum. Donec vitae
neque non magna aliquam dictum. Indent
• Vestibulum et odio et ipsum
• accumsan accumsan. Morbi at
• arcu vel elit ultricies porta. Proin
tortor purus, luctus non, aliquam
nec, interdum vel, mi. Sed nec
quam nec odio lacinia molestie.
Praesent augue tortor, convallis
eget, euismod nonummy, lacinia
ut, risus.
HTML CSS
• Cascading Style Sheets (CSS)
• Used to describe the presentation of documents.
• Define sizes, spacing, fonts, colors, layout, etc.
• Improve content accessibility.
• Improve flexibility.
• Designed to separate presentation from content.
• Due to CSS, all HTML presentation tags and attributes are deprecated, e.g. font, center,
etc.
Cascading Style Sheets (CSS)
• CSS is a language that describes the style of an HTML document.
• CSS describes how HTML elements should be displayed.
• A cascading style sheet (CSS) is a Web page derived from multiple sources with
a defined order of precedence where the definitions of any style element conflict.
• CSS saves a lot of work. It can control the layout of multiple web pages all at once
• External stylesheets are stored in CSS files
CSS Syntax
• A CSS rule-set consists of a selector and a declaration block
https://www.w3schools.com/css/default.asp
Linking HTML and CSS
• HTML (content) and CSS (presentation) can be linked in three ways:
• Inline: the CSS rules in the style attribute
• No selectors are needed
• Embedded: in the <head> in a <style> tag
• External: CSS rules in separate file (best)
• Usually a file with .css extension
• Linked via <link rel="stylesheet" href=…> tag or @import directive in embedded
CSS block
1. Inline
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Inline Styles</title>
</head>
<body>
<p>Here is some text</p>
<!--Separate multiple styles with a semicolon-->
<p style="font-size: 20pt">Here is some
more text</p>
<p style="font-size: 20pt;color:
#0000FF" >Even more text</p>
</body>
</html>
2. Internal / Embedded
• Embedded in the HTML in the <style> tag.
<head>
<title>Style Sheets</title>
<style type="text/css">
em {background-color:#8000FF; color:white}
h1 {font-family:Arial, sans-serif}
p {font-size:18pt}
.blue {color:blue}
</style>
<head>
2. Internal / Embedded
<body>
<h1 class="blue">A Heading</h1>
<p>Here is some text. Here is some text. Here
is some text. Here is some text. Here is some
text.</p>
<h1>Another Heading</h1>
<p class="blue">Here is some more text.
Here is some more text.</p>
<p class="blue">Here is some <em>more</em>
text. Here is some more text.</p>
</body>
</html>
3. External
• Separate pages can all use a shared style sheet.
• Only modify a single file to change the styles across your entire Web site.
<style type="text/css">
@import url("styles.css");
/* same as */
@import "styles.css";
</style>
Benefits of using CSS
• More powerful formatting than using presentation tags
• Your pages load faster, because browsers cache the .css files
• Increased accessibility, because rules can be defined according given media
• Pages are easier to maintain and update
HTML Navigation Bars
• A navigation bar (or navigation system) is a section of a graphical user interface
intended to aid visitors in accessing information. Navigation bars are
implemented in file browsers, web browsers and as a design element of some
web sites.
<ul>
<li><a href="default.asp">Home</a></li>
<li><a href="news.asp">News</a></li>
<li><a href="contact.asp">Contact</a></li>
<li><a href="about.asp">About</a></li>
</ul>
HTML Navigation Bars
• A navigation bar (or navigation system) is a section of a graphical user interface
intended to aid visitors in accessing information. Navigation bars are
implemented in file browsers, web browsers and as a design element of some
web sites.
• A navigation bar needs standard HTML as a base.
• These menu bars can be horizontal as well as vertical.