HTML CSS Bootstrap2
HTML CSS Bootstrap2
Bootstrap
What Is HTML
• HTML stands for Hyper Text Markup Language
• It is used to design web pages using a markup language.
• HTML is used to create the structure of web pages and
website that are displayed on the Internet. HTML
basically contains Tags and Attributes that are used to
design the web pages.
• Project1, Project2(http://localhost/ischool/index.php)
• Project3
• The markup language is used to define the text document
within the tag which defines the structure of web pages.
• HTML 5 is the fifth and current version of HTML.
HTML Basic Structure of Web Page
HTML Basic Tags
• <body>
• <!--This is heading Tag, It wont be displayed by the browser -->
•
• <h1>Hello </h1>
• </body>
• </html>
• Web Browsers
• The purpose of a web browser (Chrome, Edge,
Firefox, Safari) is to read HTML documents and
display them correctly.
• A browser does not display the HTML tags, but
uses them to determine how to display the
document:
HTML Head
• <!DOCTYPE html> • OUTPUT
• <html>
• <body> • This is heading 1
• <h1>This is heading 1</h1> • This is heading 2
• <h2>This is heading 2</h2>
• <h3>This is heading 3</h3> • This is heading 3
• <h4>This is heading 4</h4>
•
• This is heading 4
<h5>This is heading 5</h5>
• <h6>This is heading 6</h6>
• This is heading 5
• This is heading 6
• </body>
• </html>
• HTML Pragraph:These tags help us to write
paragraph statements on a webpage. They
start with the <p> tag and ends with </p>.
• HTML Break: – These tags are used for
inserting a single line type break. It does not
have any closing tag. In HTML the break tag is
written as <br>.
Example 2
<!DOCTYPE html>
<html>
<head>
<title>Full Stack Web Development</title>
</head>
<body>
<h1>Praghraph without Break </h1>
<p> A Computer Science portal for Full Stack Web Develpment <br>
A Computer Science portal for geeks Stack Web Develpment <br>
A Computer Science portal for geeks Stack Web Develpment <br>
</p>
</body>
</html>
OUTPUT
• Praghraph without Break
• A Computer Science portal for Full Stack Web Development
A Computer Science portal for geeks Stack Web
Development A Computer Science portal for geeks Stack
Web Development
• Praghraph with Break
• A Computer Science portal for Full Stack Web Development
A Computer Science portal for geeks Stack Web
Development
A Computer Science portal for geeks Stack Web
Development
Horizantal Line <HR>
• The <hr> tag is used to break the page into
various parts, creating horizontal margins with
help of a horizontal line running from the left
to right-hand side of the page.
• This is also an empty tag and doesn’t take any
additional statements.
Example 3
<!DOCTYPE html>
<html>
<head>
<title>Full Stack Web Developmwnr </title>
</head>
<body>
<h1>Hello Full Stack Web Development </h1>
<p>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
</p>
<hr>
<p>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
</p>
<hr>
<p>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
</p>
<hr>
</body>
</html>
Output:
Hello Full Stack Web Development
A Computer Science portal for SPU
A Computer Science portal for SPU
A Computer Science portal for SPU
</body>
</html>
• Explain
• The <html> element is the root element and it defines the whole HTML document.
• It has a start tag <html> and an end tag </html>.
• Then, inside the <html> element there is a <body> element:
Empty HTML Elements
• Example
• I am Red
• I am Blue
• I am Big
• Example1
• Set the background color for a page to powderblue:
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
EXample2:
<body>
</body>
• Text Color
• The CSS color property defines the text color for an HTML element:
• Example
• <h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
• Fonts
• The CSS font-family property defines the font to be used for an HTML element:
• Example
• <h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
• Text Size
• The CSS font-size property defines the text size for an HTML element:
• Example
• <h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>
• Text Alignment
• The CSS text-align property defines the horizontal text alignment for an HTML element:
• Example
• <h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered paragraph.</p>
HTML Text Formatting
</body>
</html>
• Images in Another Folder
• <img src="/images/html5.gif" alt="HTML5
Icon" style="width:128px;height:128px;">
• Animated Images
• <img src="programming.gif" alt="Computer
Man" style="width:48px;height:48px;">
• Image as a Link
• To use an image as a link, put the <img> tag inside the <a> tag:
• <a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;">
</a>
• Image Floating
• Use the CSS float property to let the image float to the right or to the left of a text:
• <p><img src="smiley.gif" alt="Smiley
face" style="float:right;width:42px;height:42px;">
The image will float to the right of the text.</p>
• With HTML image maps, you can create clickable areas on an image.
• The HTML <map> tag defines an image map
• Example
• <img src="workplace.jpg" alt="Workplace" usemap="#workmap">
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer" href="
computer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="p
hone.htm">
<area shape="circle" coords="337,300,44" alt="Coffee" href="coffee
.htm">
</map>
Background Image on a Page
• <style>
body {
background-image: url('img_girl.jpg');
}
</style>
HTML Links
<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
<p><a href="/css/default.asp">CSS Tutorial</a></p
• HTML Links - Use an Image as a Link
• To use an image as a link, just put the <img> tag inside the <a> tag:
• Example
• <a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;">
</a>
• Link to an Email Address
• Use mailto: inside the href attribute to create a link that opens the user's email program (to let them send a new
email):
• Example
• <a href="mailto:[email protected]">Send email</a>
• Button as a Link
• To use an HTML button as a link, you have to add some JavaScript code.
• JavaScript allows you to specify what happens at certain events, such as a click of a button:
• Example
• <button onclick="document.location='default.asp'">HTML Tutorial</button>
• Link Titles
• The title attribute specifies extra information about an element. The information is most often shown as a tooltip
text when the mouse moves over the element.
• Example
• <a href="https://www.w3schools.com/html/" title="Go to W3Schools HTML section">Visit our HTML Tutorial</a>
• HTML Link Colors
• By default, a link will appear like this (in all
browsers):
• An unvisited link is underlined and blue
• A visited link is underlined and purple
• An active link is underlined and red
• You can change the link state colors, by using
CSS:
• <!DOCTYPE html>
• <html>
•
•
•
•
<head>
<style>
a:link {
color: green;
EXample
• background-color: transparent;
• text-decoration: none;
• }
• a:visited {
• color: pink;
• background-color: transparent;
• text-decoration: none;
• }
• a:hover {
• color: red;
• background-color: transparent;
• text-decoration: underline;
• }
• a:active {
• color: yellow;
• background-color: transparent;
• text-decoration: underline;
• }
• </style>
• </head>
• <body>
• <h2>Link Colors</h2>
• </body>
• </html>
HTML Links - Create Bookmarks
• <!DOCTYPE html>
• <html>
• <style>
• table, th, td {
• border:1px solid black;
• }
• </style>
• <body>
• <table style="width:100%">
• <tr>
• <th>Company</th>
• <th>Contact</th>
• <th>Country</th>
• </tr>
• <tr>
• <td>Alfreds Futterkiste</td>
• <td>Maria Anders</td>
• <td>Germany</td>
• </tr>
• <tr>
• <td>Centro comercial Moctezuma</td>
• <td>Francisco Chang</td>
• <td>Mexico</td>
• </tr>
• </table>
• <p>To understand the example better, we have added borders to the table.</p>
• </body>
• </html>
• HTML Table Borders
To add a border, use the CSS border property on table, th, and td elements:
table, th, td {
border: 1px solid black;
}
• Collapsed Table Borders
• To avoid having double borders like in the example above, set the CSS border-collapse property to collapse.
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
Style Table Borders
table, th, td {
border: 1px solid white;
border-collapse: collapse;
}
th, td {
background-color: #96D4D4;
}
Round Table Borders
table, th, td {
border: 1px solid black;
border-radius: 10px;
• Dotted Table Borders
• With the border-style property, you can set the appearance of the border.
h, td {
border-style: dotted;
}
}
• Border Color
• With the border-color property, you can set the color of the border.
th, td {
border-color: #96D4D4;
}
HTML Table Sizes
• HTML tables can have different sizes for each column, row
or the entire table.
• Use the style attribute with the width or height properties
to specify the size of a table, row or column.
• <table style="width:100%">
• Column width
• <th style="width:70%">Firstname</th>
• HTML Table Row Height
• <tr style="height:200px">
• TagDescription
• <table> Defines a table
• <th> Defines a header cell in a table
• <tr> Defines a row in a table
• <td> Defines a cell in a table
• <caption> Defines a table caption
• <colgroup> Specifies a group of one or more columns in
a table for formatting
• <col> Specifies column properties for each column
within a <colgroup> element
• <thead> Groups the header content in a table
• <tbody> Groups the body content in a table
• <tfoot> Groups the footer content in a table
HTML Table Padding & Spacing
• HTML tables can adjust the padding inside the cells, and also the space between the cells.
• Cell Padding
• Cell padding is the space between the cell edges and the cell content.
• By default the padding is set to 0.
• To add padding on table cells, use the CSS padding property:
• Example
• th, td {
padding: 15px;
}
• Example
• th, td {
padding-top: 10px;
padding-bottom: 20px;
padding-left: 30px;
padding-right: 40px;
}
• Cell Spacing
• Cell spacing is the space between each cell.
• By default the space is set to 2 pixels.
• To change the space between table cells, use the CSS border-spacing property on the table element:
• Example
• table {
border-spacing: 30px;
}
Table Colspan & Rowspan
Column Span
Row Span
<th colspan="2">Name</th>
<th rowspan="2">Phone</th>
Table Colgroup
• An HTML form is used to collect user input. The user input is most often sent to a server
for processing.
• <form> Element
• The HTML <form> element is used to create an HTML form for user input:
• <form>
.
form elements
.
</form>
• The <form> element is a container for different types of input elements, such as: text
fields, checkboxes, radio buttons, submit buttons, etc.
• <input type="text">Displays a single-line text input field
• <input type="radio">Displays a radio button (for selecting one of many choices)
• <input type="checkbox">Displays a checkbox (for selecting zero or more of many choices)
• <input type="submit">Displays a submit button (for submitting the form)
• <input type="button">Displays a clickable button
HTML <form> Elements
• <input> Element
• One of the most used form element is the <input> element
• The <label> Element
• The <label> element defines a label for several form elements.
• <select> Element
• The <select> element defines a drop-down list:
• <textarea> Element
• The <textarea> element defines a multi-line input field (a text area):
• <button> Element
• The <button> element defines a clickable button:
• Example
• <button type="button" onclick="alert('Hello World!')">Click Me!</button>
• <fieldset> and <legend> Elements
• The <fieldset> element is used to group related data in a form.
• The <legend> element defines a caption for the <fieldset> element.
• <datalist> Element
• The <datalist> element specifies a list of pre-defined options for an <input> element.
• Users will see a drop-down list of the pre-defined options as they input data.
• Input Type Reset
• <input type="reset"> defines a reset button that will reset all form values to their default values:
• Input Type Radio
• <input type="radio"> defines a radio button.
• Input Type Checkbox
• <input type="checkbox"> defines a checkbox.
• Input Type Color
• The <input type="color"> is used for input fields that should contain a color.
• Input Type Date
• The <input type="date"> is used for input fields that should contain a date.
• Input Type Email
• The <input type="email"> is used for input fields that should contain an e-mail address.
• Input Type Image
• The <input type="image"> defines an image as a submit button.
• Input Type File
• The <input type="file"> defines a file-select field and a "Browse" button for file uploads.
• Input Type Hidden
• The <input type="hidden"> defines a hidden input field (not visible to a user).
• Input Type Number
• The <input type="number"> defines a numeric input field.
• Input Type Range
• The <input type="range"> defines a control for entering a number whose exact value is not
important (like a slider control). Default range is 0 to 100
• Input Type Search
• The <input type="search"> is used for search fields (a search field behaves like a regular text
field).
INPUT Type
• <input type="button"> defines a single-line text input field:
• <input type="password">
• <input type="checkbox">
• <input type="color">
• <input type="date">
• <input type="datetime-local">
• <input type="email">
• <input type="file">
• <input type="hidden">
• <input type="image">
• <input type="month">
• <input type="number">
• <input type="password">
• <input type="radio">
• <input type="range">
• <input type="reset">
• <input type="search">
• <input type="submit">
• <input type="tel">
• <input type="text">
• <input type="time">
• <input type="url">
• <input type="week">
HTML Input Attributes
• <form action="/action_page.php">
• <label for="fname">First name:</label><br>
• <input type="text" id="fname" name="fname"><br><br>
• <input type="submit" value="Submit">
• <label for="cars">Choose a car:</label>
<select id="cars" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
• <textarea name="message" rows="10" cols="30">
The cat was playing in the garden.
</textarea>
• </form>
• </body>
• </html>
Form Attributes
• The HTML <form> element contains several attributes for controlling data submission. They are as follows:
• action
• The action attributes define the action to be performed when the form is submitted. It is usually the url for the server where the form data
is to be sent.
• <form action="/login">
• <label for="email">Email:</label> <input type="email" name="email"><br><br>
• <label for="password">Password:</label>
• <input type="password" name="password"><br><br>
• <input type="submit" value="Submit"> </form>
• method
• The method attribute defines the HTTP method to be used when the form is submitted. There are 3 possible values for
the method attribute:
• post - It is used to send data to a server to update a resource.<form method = "post"> ... </form>
• get: It is used to request data from a specified resource.
• Canvas
• The HTML <canvas> element is used to draw graphics, on the fly, via
JavaScript..
• Canvas has several methods for drawing paths, boxes, circles, text, and
adding images.
• <canvas id="myCanvas" width="200" height="100"></canvas>
• What is SVG?
• SVG stands for Scalable Vector Graphics
• SVG is used to define graphics for the Web
• SVG is a W3C recommendation
• <svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-
width="4" fill="yellow" />
</svg>
Differences Between SVG and Canvas
• h1, h2, p {
text-align: center;
color: red;
}
How To Add CSS
• With an external style sheet, you can change the look of an entire website by changing just
one file!
• Each HTML page must include a reference to the external style sheet file inside the <link>
element, inside the head section.
• <!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
• An external style sheet can be written in any text editor, and must be saved with a .css
extension.
Internal CSS
• An internal style sheet may be used if one single HTML page has a unique style.
• The internal style is defined inside the <style> element, inside the head section.
• <!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Inline CSS
• An inline style may be used to apply a unique style for a single element.
• To use inline styles, add the style attribute to the relevant element. The style
attribute can contain any CSS property.
• Example
• Inline styles are defined within the "style" attribute of the relevant element:
• <!DOCTYPE html>
<html>
<body>
</body>
</html>
Multiple Style Sheets
p.two {
border-style: solid;
border-width: medium;
}
p.three {
border-style: dotted;
border-width: 2px;
}
p.four {
border-style: dotted;
border-width: thick;
}
• CSS Border - Individual Sides
• From the examples on the previous pages, you have seen that it is possible to specify a different border for each side.
• In CSS, there are also properties for specifying each of the borders (top, right, bottom, and left):
• Example
• p{
border-top-style: dotted;
border-right-style: solid;
border-bottom-style: dotted;
border-left-style: solid;
}
• CSS Rounded Borders
• The border-radius property is used to add rounded borders to an element:
• p{
border: 2px solid red;
border-radius: 5px;
}
CSS Margins
• The CSS margin properties are used to create space around elements,
outside of any defined borders.
• CSS has properties for specifying the margin for each side of an element:
• margin-top
• margin-right
• margin-bottom
• margin-left
• p{
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
CSS Padding
• Padding is used to create space around an element's content, inside
of any defined borders.
• Padding - Individual Sides
• CSS has properties for specifying the padding for each side of an
element:
• padding-top
• padding-right
• padding-bottom
• padding-left
• div {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
CSS Height, Width and Max-width
• he CSS height and width properties are used to set the height and width of
an element.
• he height and width properties may have the following values:
• auto - This is default. The browser calculates the height and width
• length - Defines the height/width in px, cm, etc.
• % - Defines the height/width in percent of the containing block
• initial - Sets the height/width to its default value
• inherit - The height/width will be inherited from its parent value
• div {
height: 200px;
width: 50%;
background-color: powderblue;
}
The CSS Box Model
• In CSS, the term "box model" is used when talking about design and
layout.
• The CSS box model is essentially a box that wraps around every HTML
element. It consists of: margins, borders, padding, and the actual
content. The image below illustrates the box model:
• Explanation of the different parts:
• Content - The content of the box, where text and images appear
• Padding - Clears an area around the content. The padding is
transparent
• Border - A border that goes around the padding and content
• Margin - Clears an area outside the border. The margin is transparent
CSS Outline
• Text Color
• The color property is used to set the color of the text. The color is specified by:
• a color name - like "red"
• a HEX value - like "#ff0000"
• an RGB value - like "rgb(255,0,0)"
• body {
color: blue;
}
h1 {
color: green;
}
Text Color and Background Color
• In this example, we define both the background-color property and the color property:
• Example
• body {
background-color: lightgrey;
color: blue;
}
h1 {
background-color: black;
color: white;
}
div {
background-color: blue;
color: white;
}
CSS Text Alignment
h2 {
text-align: left;
}
h3 {
text-align: right;
}
• div {
text-align: justify;
}
CSS Text Decoration
• Text Transformation
• The text-transform property is used to specify uppercase and lowercase
letters in a text.
• Example
• p.uppercase {
text-transform: uppercase;
}
p.lowercase {
text-transform: lowercase;
}
p.capitalize {
text-transform: capitalize;
}
Text Spacing
• The text-indent property is used to specify the indentation of the first line of a text:
• p{
text-indent: 50px;
}
• Letter Spacing
• The letter-spacing property is used to specify the space between the characters in a text.
• The following example demonstrates how to increase or decrease the space between characters:
• Example
• h1 {
letter-spacing: 5px;
}
h2 {
letter-spacing: -2px;
}
• Line Height
• The line-height property is used to specify the space between lines:
• Example
• p.small {
line-height: 0.8;
}
p.big {
line-height: 1.8;
}
• Word Spacing
• The word-spacing property is used to specify the space between the words in a text.
• The following example demonstrates how to increase or decrease the space between words:
• Example
• p.one {
word-spacing: 10px;
}
p.two {
word-spacing: -2px;
}
• White Space
• The white-space property specifies how white-space inside an element is handled.
• This example demonstrates how to disable text wrapping inside an element:
• Example
• p{
white-space: nowrap;
}
CSS Text Shadow
• ext Shadow
• The text-shadow property adds shadow to text.
• Text shadow effect!
• h1 {
text-shadow: 2px 2px;
}
• h1 {
text-shadow: 2px 2px red;
}
CSS Fonts
.p2 {
font-family: Arial, Helvetica, sans-serif;
}
.p3 {
font-family: "Lucida Console", "Courier New", monospace;
}
CSS Font Style
p.italic {
font-style: italic;
}
p.oblique {
font-style: oblique;
}
• Font Weight
• The font-weight property specifies the weight of a font:
• Example
• p.normal {
font-weight: normal;
}
p.thick {
font-weight: bold;
}
CSS Font Size
• If you do not want to use any of the standard fonts in HTML, you can use Google Fonts.
• Google Fonts are free to use, and have more than 1000 fonts to choose from.
• Just add a special style sheet link in the <head> section and then refer to the font in the
CSS.
• <head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Sofia">
<style>
body {
font-family: "Sofia", sans-serif;
}
</style>
</head>
• <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Trirong">
• Use multiple google
• <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Audiowide|
Sofia|Trirong">
• Enabling Font Effects
• Google has also enabled different font effects that you can use.
• First add effect=effectname to the Google API, then add a special class name to the element that is going to use
the special effect. The class name always starts with font-effect- and ends with the effectname.
• Example
• Add the fire effect to the "Sofia" font:
• <head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Sofia&effect=fire">
<style>
body {
font-family: "Sofia", sans-serif;
font-size: 30px;
}
</style>
</head>
<body>
</body>
• Result:
CSS Icons
• How To Add Icons
• The simplest way to add an icon to your HTML
page, is with an icon library, such as Font
Awesome.
• Add the name of the specified icon class to any
inline HTML element (like <i> or <span>).
• To use the Font Awesome icons, go to
fontawesome.com, sign in, and get a code to add
in the <head> section of your HTML page:
• <script
src="https://kit.fontawesome.com/yourcode.js"
crossorigin="anonymous"></script>
• Font Awesome 5
• Font Awesome 5 has a PRO edition with 7842 icons,
and a FREE edition with 1588 icons. This tutorial
will concentrate on the FREE edition
• <script src="https://kit.fontawesome.com/
yourcode.js" crossorigin="anonymous"></script>
• We got the code a076d05399 and by inserting the
script tag, with the code, we can start using Font
Awesom
• <script src="https://kit.fontawesome.com/
a076d05399.js" crossorigin="anonymous"></
script>
Styling Links
• Links can be styled with any CSS property (e.g. color, font-family, background, etc.).
• Example
• a{
color: hotpink;
}
• The four links states are:
• a:link - a normal, unvisited link
• a:visited - a link the user has visited
• a:hover - a link when the user mouses over it
• a:active - a link the moment it is clicked
• /* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
/* selected link */
a:active {
color: blue;
}
• Try it Yourself »
• Text Decoration
• The text-decoration property is mostly used to remove underlines from links:
• a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
• Background Color
• The background-color property can be used to specify a background color for links:
• Example
• a:link {
background-color: yellow;
}
a:visited {
background-color: cyan;
}
a:hover {
background-color: lightgreen;
}
a:active {
background-color: hotpink;
}
• Link Buttons
• This example demonstrates a more advanced example where we combine several CSS properties to display links as boxes/buttons:
• Example
• a:link, a:visited {
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: red;
}
CSS Lists
ul.b {
list-style-type: square;
}
ol.c {
list-style-type: upper-roman;
}
ol.d {
list-style-type: lower-alpha;
}
• list-style-image property specifies an image as the list item marker:
• Example
• ul {
list-style-image: url('sqpurple.gif');
}
• list-style-position property specifies the position of the list-item markers (bullet points).
• ul.a {
list-style-position: outside;
}
ul.b {
list-style-position: inside;
}
• Styling List With Colors
• We can also style lists with colors, to make them look a little more interesting.
• ol {
background: #ff9999;
padding: 20px;
}
ul {
background: #3399ff;
padding: 20px;
}
ol li {
background: #ffe5e5;
color: darkred;
padding: 5px;
margin-left: 35px;
}
ul li {
background: #cce5ff;
color: darkblue;
margin: 5px;
}
• table, th, td {
}
border: 1px solid; CSS Tables
• Full-Width Table
• table {
width: 100%;
}
• Table Width and Height
• table {
width: 100%;
}
th {
height: 70px;
}
• Table aligne
• Horizontal Alignment
• td {
text-align: center;
}
• Vertical Alignment
• td {
height: 50px;
vertical-align: bottom;
}
• Table Padding
• th, td {
padding: 15px;
text-align: left;
}
• Horizontal Dividers
• th, td {
border-bottom: 1px solid #ddd;
}
• Hoverable Table
• tr:hover {background-color: coral;}
• Striped Tables
• tr:nth-child(even) {background-color: #f2f2f2;}
• Table Color
• th {
background-color: #04AA6D;
color: white;
}
• Responsive Table
• A responsive table will display a horizontal
scroll bar if the screen is too small to display
the full content:
• <div style="overflow-x:auto;">
<table>
... table content ...
</table>
</div>
CSS Layout - The display Property
• div.ex1 {
width: 500px;
margin: auto;
border: 3px solid #73AD21;
}
div.ex2 {
max-width: 500px;
margin: auto;
border: 3px solid #73AD21;
}
• Explain With Example
CSS Layout - The position Property
• The position property specifies the type of positioning method used for an
element.
• There are five different position values:
• Static HTML elements are positioned static by default.
• Static positioned elements are not affected by the top, bottom, left, and
right properties.
li a {
display: block;
}
• ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 60px;
}
li a {
display: block;
}
• Horizental Navigation Bar
• li {
display: inline;
}
• li {
float: left;
}
a{
display: block;
padding: 8px;
background-color: #dddddd;
}
• float: left; - Use float to get block elements to float next to each other
• display: block; - Allows us to specify padding (and height, width, margins, etc. if you want)
• padding: 8px; - Specify some padding between each <a> element, to make them look good
• background-color: #dddddd; - Add a gray background-color to each <a> element
• Sticky Navbar
• Add position: sticky; to <ul> to create a sticky navbar.
• A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned
relative until a given offset position is met in the viewport - then it "sticks" in place (like
position:fixed).
• Responsive Nvigation Bar
• See Example
• Dropdown Navbar
• Explain With Example
•
CSS Dropdowns
Create a dropdown box that appears when the user moves the mouse over an element.
• <style>
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
<div class="dropdown">
<span>Mouse over me</span>
<div class="dropdown-content">
<p>Hello World!</p>
</div>
</div>
• Example Explained
• HTML) Use any element to open the dropdown content, e.g. a <span>, or a <button> element.
• Use a container element (like <div>) to create the dropdown content and add whatever you want inside of it.
• Wrap a <div> element around the elements to position the dropdown content correctly with CSS.
• CSS) The .dropdown class uses position:relative, which is needed when we want the dropdown content to be placed right below the dropdown
button (using position:absolute).
• The .dropdown-content class holds the actual dropdown content. It is hidden by default, and will be displayed on hover (see below). Note the min-
width is set to 160px. Feel free to change this. Tip: If you want the width of the dropdown content to be as wide as the dropdown button, set
the width to 100% (and overflow:auto to enable scroll on small screens).
• Instead of using a border, we have used the CSS box-shadow property to make the dropdown menu look like a "card".
CSS Image Gallery
input[type=text]:focus {
width: 100%;
}
• Styling Select Menus
• select {
width: 100%;
padding: 16px 20px;
border: none;
border-radius: 4px;
background-color: #f1f1f1;
}
/* Navbar links */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other on smaller screens
(600px wide or less) */
@media screen and (max-width: 600px) {
.column {
width: 100%;
}
}
• Tip: To create a 2-column layout, change the width to 50%. To create a 4-column layout, use 25%, etc.
• Tip: Do you wonder how the @media rule works? Read more about it in our CSS Media Queries chapter.
• Tip: A more modern way of creating column layouts, is to use CSS Flexbox. However, it is not supported in Internet Explorer
10 and earlier versions. If you require IE6-10 support, use floats (as shown above).
• Footer
• The footer is placed at the bottom of your
page. It often contains information like
copyright and contact info:
• .footer {
background-color: #F1F1F1;
text-align: center;
padding: 10px;
}
CSS Rounded Corners
• With the CSS border-radius property, you can give any element "rounded corners".
• #rcorners1 {
border-radius: 25px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
#rcorners2 {
border-radius: 25px;
border: 2px solid #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
#rcorners3 {
border-radius: 25px;
background: url(paper.gif);
background-position: left top;
background-repeat: repeat;
padding: 20px;
width: 200px;
height: 150px;
}
• CSS Multiple Backgrounds
• CSS allows you to add multiple background images for an element, through the background-image property.
• #example1 {
background-image: url(img_flwr.gif), url(paper.gif);
background-position: right bottom, left top;
background-repeat: no-repeat, repeat;
}
CSS Gradients
• CSS defines three types of gradients:
• Linear Gradients (goes down/up/left/right/diagonally)
• Radial Gradients (defined by their center)
• Conic Gradients (rotated around a center point)
• Syntax
• background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
• #grad {
background-image: linear-gradient(red, yellow);
}
Using Angles
• If you want more control over the direction of the gradient, you can define an angle, instead of the predefined directions (to bottom, to top, to right, to left,
to bottom right, etc.).
• background-image: linear-gradient(angle, color-stop1, color-stop2);
• #grad {
background-image: linear-gradient(180deg, red, yellow);
}
use multicolor stop
#grad {
background-image: linear-gradient(red, yellow, green);
}
•
CSS Transitions
CSS transitions allows you to change property values smoothly, over a given duration.
• o create a transition effect, you must specify two things:
• the CSS property you want to add an effect to
• the duration of the effect
• If the duration part is not specified, the transition will have no effect, because the default value is 0.
• In this chapter you will learn about the following properties:
• transition
• transition-delay
• transition-duration
• transition-property
• transition-timing-function
• Example
• div {
width: 100px;
height: 100px;
background: red;
transition: width 2s;
}
• Example effact width and height
• div {
transition: width 2s, height 4s;
}
• Specify the Speed Curve of the Transition
• The transition-timing-function property specifies the speed curve of the transition effect.
• The transition-timing-function property can have the following values:
• ease - specifies a transition effect with a slow start, then fast, then end slowly (this is default)
• linear - specifies a transition effect with the same speed from start to end
• ease-in - specifies a transition effect with a slow start
• ease-out - specifies a transition effect with a slow end
• ease-in-out - specifies a transition effect with a slow start and end
• cubic-bezier(n,n,n,n) - lets you define your own values in a cubic-bezier function
• Delay the Transition Effect
• The transition-delay property specifies a delay (in seconds) for the transition effect.
• div {
transition-delay: 1s;
}
• ransition + Transformation
• The following example adds a transition effect to the transformation:
• Example
• div {
transition: width 2s, height 2s, transform 2s;
}
CSS Animations
• CSS allows animation of HTML elements without using JavaScript or Flash!
• An animation lets an element gradually change from one style to another.
• You can change as many CSS properties you want, as many times as you want.
• The @keyframes Rule
• When you specify CSS styles inside the @keyframes rule, the animation will gradually
change from the current style to the new style at certain times.
• /* The animation code */
@keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
.button:hover {
background-color: #4CAF50; /* Green */
color: white;
}
Shadow Buttons
.button1 {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
.button2:hover {
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}
• Disabled Buttons
• Use the opacity property to add transparency to a button (creates a "disabled" look).
• .disabled {
opacity: 0.6;
cursor: not-allowed;
}
• Button Width
• .button1 {width: 250px;}
.button2 {width: 50%;}
.button3 {width: 100%;}
• Button Groups
• .button {
float: left;
}
• Bordered Button Group
• .button {
float: left;
border: 1px solid green;
}
• Vertical Button Group
• Use display:block instead of float:left to group the buttons below each other, instead of side by side:
• .button {
display: block;
}
CSS Media Queries
• CSS3 Introduced Media Queries
• Media queries in CSS3 extended the CSS2 media types idea: Instead of looking for a type of device, they look at the capability of the
device.
• Media queries can be used to check many things, such as:
• width and height of the viewport
• width and height of the device
• orientation (is the tablet/phone in landscape or portrait mode?)
• resolution
• Using media queries are a popular technique for delivering a tailored style sheet to desktops, laptops, tablets, and mobile phones
(such as iPhone and Android phones).
• Media Query Syntax
• A media query consists of a media type and can contain one or more expressions, which resolve to either true or false.
• @media not|only mediatype and (expressions) {
CSS-Code;
}
• <link rel="stylesheet" media="mediatype and|not|only (expressions)" href="print.css">
• CSS3 Media Types
• Value Description
• All Used for all media type devices
• Print Used for printers
• Screen Used for computer screens, tablets, smart-phones etc.
• Speech Used for screenreaders that "reads" the page out loud
• The following example changes the background-color to lightgreen if the viewport is 480 pixels wide or wider (if the viewport is less
than 480 pixels, the background-color will be pink):
@media screen and (min-width: 480px) {
body {
background-color: lightgreen;
}
}
CSS Flexbox
• Before the Flexbox Layout module, there were four layout modes:
• Block, for sections in a webpage
• Inline, for text
• Table, for two-dimensional table data
• Positioned, for explicit position of an element
• <div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
• The flex item properties are:
• order
• flex-grow
• flex-shrink
• flex-basis
• flex
• align-self
• <div class="flex-container">
<div style="order: 3">1</div>
<div style="order: 2">2</div>
<div style="order: 4">3</div>
<div style="order: 1">4</div>
</div>
• <div class="flex-container">
<div style="flex-grow: 1">1</div>
<div style="flex-grow: 1">2</div>
<div style="flex-grow: 8">3</div>
</div>
• <div class="flex-container">
<div>1</div>
<div>2</div>
<div style="flex-shrink: 0">3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
</div>
Responsive Flexbox
• For example, if you want to create a two-column layout for most screen
sizes, and a one-column layout for small screen sizes (such as phones and
tablets), you can change the flex-direction from row to column at a specific
breakpoint (800px in the example below):
• .flex-container {
display: flex;
flex-direction: row;
}
• See Example
• Responsive Website using Flexbox
• See Example