ch4 Css-Bootstrap
ch4 Css-Bootstrap
History of HTML
1995 HTML 2.0 After HTML 4.01 was released, focus shifted
to XHTML and its stricter standards.
1997 HTML 3.2
1999 HTML 4.01 XHTML 2.0 had even stricter standards than
1.0, rejecting web pages that did not comply.
It fell out of favor gradually and was
2000 XHTML 1.0
abandoned completely in 2009.
2002
HTML5 is much more tolerant and can handle
- XHTML 2.0
2009 markup from all the prior versions.
• In HTML video and audio are not supported whereas in HTML5, video, and
audio are integrated into it.
• HTML is compatible with almost all the browsers whereas HTML5 is
supported by most of the modern browsers such as Firefox, Mozilla, and
Chrome etc.
• In HTML, JavaScript and browser interface will run in the same thread
whereas in HTML5 we can run JavaScript in the background with help of web
worker API can run in different threads.
• In HTML, vector graphics is supported with help of other tools such as Silver
light, Flash etc. whereas in HTML5 vector graphics is supported by default it
has canvas and SVG inbuilt.
• In HTML5 applet tag was removed which is used for displaying applets and
object tag was introduced whereas, in HTML, applet tag is being used.
Working with
Cascading Style Sheets (CSS)
5
XP
What is CSS?
• Selector
– HTML element tags
(examples: p, h2, body, img, table)
– class and ID names
• Property (examples: color, font-size)
• Value (examples: red, 14pt)
Example:
p { font-size: 8pt; color: red }
property names
declarations
p{
font-size: x-large ;
background-color: yellow
}
• Type selector:
– Element type, such as body, p, hr, etc.
• See previous example
– Multiple element types using the same style are separated by comma
• h1, h2, h3, h4, h5, h6 {background-color:purple}
• ID selector:
– #p1, #s1 {background-color: blue}
– <p id=“p1”> … </p>
– <span id=“s1”>…</span>
– id values are case-sensitive
Working with CSS 10
Prepared by: C. Hueckstaedt
XP
Sector Strings
• Class selector:
– .myitalic {font-style: italic}
– .myred {color: red}
– <span class=“myitalic myred”> … </span>
– class values are case sensitive
– multiple classes can be applied, separated by space
– All but a few elements, such as html, head, and elements that
appear as content of head, have the class attribute
1. Local (Inline)
2. Global (Embedded, or Internal)
3. Linked (External)
• Example
<p style="font-size: 10pt; color: red; font-weight: bold;
font-family: Arial, Helvetica, sans-serif">
This is a local stylesheet declaration. </p>
On the browser:
• Example:
<html>
<head>
<title>Title</title>
<style type="text/css">
<!--[STYLE INFORMATION GOES HERE] -->
</style>
</head>
<body>
[DOCUMENT BODY GOES HERE]
</body>
</html>
Working with CSS 16
Prepared by: C. Hueckstaedt
XP
3. Linked
• Example
Save this text
In TextPad,Notepad, etc.…
file as
p {font-family: verdana, sans- whatever.css
serif; font-size: 12pt; color: red}
• Example (continued)
The way styles will be used when there is more than one style
specified for an HTML element:
1. Browser default
2. External Style Sheet (Linked) (in an external .css file)
3. Internal Style Sheet (Global, or embedded) (inside the <head> tag)
4. Inline Style (Local) (inside HTML element)
• With a class selector you can define different styles for the
same type of HTML element
• Examples:
First define the class:
p.right {text-align: right; color: red; font-style: italic}
p.blue {text-align: center; color:blue}
Then use the class in your HTML code :
<p class="right"> This paragraph will be right-aligned, italic, and red.
</p>
<p class=“blue"> This paragraph will be center-aligned and blue. </p>
• Example:
.poem {text-align: center; font-style:italic}
• Example (continued)
Both elements below will follow the rules in the
".poem“ class:
<style>
p {font-family: sans-serif; font-size: 10pt}
h1 {font-family: serif; font-size: 30pt}
h2 {font-family: serif; font-size: 24pt}
.boldred {color: red; font-weight: bold}
.green {color: green}
.tinyblue {color: blue; font-size: 8pt}
</style>
• <div>
– A division tag: to “package” a block of document into
one unit. It defines a block element.
– Causes a line break, like <br> and <p>.
• <span>
– “Wraps” a portion of text into a unit, but doesn't cause a
line break. Allows styles to be applied to an 'elemental'
region (such as a portion of a paragraph).
<div class="foo">
<p>The "foo" style will be applied to this text, and
to <a href="page.html">this text</a> as well.
</div>
• In CSS:
div.classname a:link { color: #123456; }
div.classname a:hover { color: #123; }
div.classname a:visited { color: #654321; }
• In HTML:
<div class="classname">
<a href="#link">link</a>
</div>
Working with CSS 34
Prepared by: C. Hueckstaedt
XP
Using Font Families
This figure shows the impact of such a style definition on boldface text in a Web page.
The style has the same impact within a heading, since the heading is the parent
element, and the boldface text is increased to 150% of the surrounding heading text.
This figure shows the text-decoration attribute can be used to underline your text
or place a line over or through your text. You can also make your text blink
on and off using the text-decoration: blink attribute.
• Almost any element on the page can also be displayed with its
own background image.
• The background image has four attributes:
– the source of the image file
– how the image is repeated in the background
– where the image is placed on the background
– whether the image scrolls with the display window
• To specify which file to use for a background, use the syntax:
background-image: url(URL)
– URL is the location of the image file
Use contextual selectors to create an outline style for several levels of nested lists.
This figure shows a set of contextual selectors used to create an outline style
for different outline levels.
This figure shows that the labels for the list items can be placed either outside or inside the box.
The figure
summarizes the
various border
attributes.
Responsive Web
Design with
Bootstrap
XP
What is Responsive Web Design?
• You must include the following Bootstrap’s CSS from MaxCDN into your web page.
<!-- Latest compiled and minified Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" >
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
</html>
XP
Create Web Page with Bootstrap (2)
• Bootstrap is mobile-first
– Bootstrap 3/4 is designed to be responsive to mobile devices. Mobile-first
styles are part of the core framework.
– To ensure proper rendering and touch zooming, add the
following <meta> tag inside the <head> element:
– The width=device-width part sets the width of the page to follow the
screen-width of the device (which will vary depending on the device).
– The initial-scale=1 part sets the initial zoom level when the page is first
loaded by the browser.
XP
Create Web Page with Bootstrap (3)
• Containers
– Bootstrap also requires a containing element to wrap
site contents.
– There are two container classes to choose from:
• The .container class provides a responsive fixed width
container. (See Sample)
• The .container-fluid class provides a full width container,
spanning the entire width of the viewport. (See Sample)
• Note: Containers are not nestable (you cannot put
a container inside another container).
XP
Bootstrap Grids
<div class="row">
<div class="col-*-*"></div>
</div>
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
...
</div>
• A basic Bootstrap table has a light padding and only horizontal dividers.
– The .table class adds basic styling to a table:
• Striped Rows
– The .table-striped class adds zebra-stripes to a table:
• Bordered Table
– The .table-bordered class adds borders on all sides of the table and cells:
• Hover Rows
– The .table-hover class enables a hover state on table rows:
• Responsive Tables
– The .table-responsive class creates a responsive table. The table will then scroll
horizontally on small devices (under 768px). When viewing on anything larger than
768px wide, there is no difference:
XP
Bootstrap Images
• Rounded Corners
– The .rounded class adds rounded corners to an image (IE8 does not support rounded
corners):
• Circle
– The .rounded-circle class shapes the image to a circle (IE8 does not support rounded
corners):
• Thumbnail
– The .img-thumbnail class shapes the image to a thumbnail:
• Responsive Images
– Images comes in all sizes. So do screens. Responsive images automatically adjust to fit
the size of the screen.
– Create responsive images by adding an .img-responsive class to the <img> tag. The
image will then scale nicely to the parent element.
– The .img-responsive class applies display: block; and max-width: 100%; and height:
auto; to the image:
XP
Bootstrap Buttons
• Button Styles
– Bootstrap provides seven styles of buttons with the following
classes:
.btn-default
.btn-primary
.btn-success
.btn-info
.btn-warning
.btn-danger
.btn-link
XP
Bootstrap Button Elements