Monday, 19 April 2021

HTML BASICS PART II

 HTML Colors

HTML colors are specified with predefined color names, or with RGB, HEX, HSL, RGBA, or HSLA values.

<h1 style="background-color:DodgerBlue;">Hello World</h1>
<p style="color:MediumSeaGreen;">Ut wisi enim...</p>
<h1 style="border:2px solid Tomato;">Hello World</h1>
<h1 style="background-color:rgb(255, 99, 71);">...</h1>
<h1 style="background-color:#ff6347;">...</h1>
<h1 style="background-color:hsl(9, 100%, 64%);">...</h1>

An RGB color value represents RED, GREEN, and BLUE light sources.
An RGBA color value is an extension of RGB with an Alpha channel (opacity).
  • In HTML, a color can be specified as an RGB value, using this formula
rgb(red, green, blue)

  • Each parameter (red, green, and blue) defines the intensity of the color with a value between 0 and 255.
  • RGBA color values are an extension of RGB color values with an Alpha channel - which specifies the opacity for a color.
  • An RGBA color value is specified with:
rgba(red, green, blue, alpha

  • The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not transparent at all)

HEX Color Values

In HTML, a color can be specified using a hexadecimal value in the form:
#rrggbb
Where rr (red), gg (green) and bb (blue) are hexadecimal values between 00 and ff (same as decimal 0-255).

HSL Color Values

  • In HTML, a color can be specified using hue, saturation, and lightness (HSL) in the form:
hsl(hue, saturation, lightness)

  • Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is blue.
  • Saturation is a percentage value, 0% means a shade of gray, and 100% is the full color.
  • Lightness is also a percentage value, 0% is black, and 100% is white.

  • Saturation can be described as the intensity of a color.
  • 100% is pure color, no shades of gray
  • 50% is 50% gray, but you can still see the color.
  • The lightness of a color can be described as how much light you want to give the color, where 0% means no light (black), 50% means 50% light (neither dark nor light) 100% means full lightness (white).

Using CSS

CSS can be added to HTML documents in 3 ways:

Inline - by using the style attribute inside HTML elements
Internal - by using a <style> element in the <head> section
External - by using a <link> element to link to an external CSS file

Use the HTML style attribute for inline styling
Use the HTML <style> element to define internal CSS
Use the HTML <link> element to refer to an external CSS file
Use the HTML <head> element to store <style> and <link> elements
Use the CSS color property for text colors
Use the CSS font-family property for text fonts
Use the CSS font-size property for text sizes
Use the CSS border property for borders
Use the CSS padding property for space inside the border
Use the CSS margin property for space outside the border

HTML Links - Syntax

<a href="url">link text</a>

The link text is the part that will be visible to the reader.
Clicking on the link text, will send the reader to the specified URL address.

By default, links will appear as follows in all browsers:
An unvisited link is underlined and blue
A visited link is underlined and purple
An active link is underlined and red

HTML Links - The target Attribute

By default, the linked page will be displayed in the current browser window. To change this, you must specify another target for the link.
The target attribute specifies where to open the linked document.

The target attribute can have one of the following values:

_self - Default. Opens the document in the same window/tab as it was clicked
_blank - Opens the document in a new window or tab
_parent - Opens the document in the parent frame
_top - Opens the document in the full body of the window

<a href="https://www.w3schools.com/" target="_blank">Visit W3Schools!</a>

Use an Image as a Link

  • To use an image as a link, just 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>
  • 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):
<a href="mailto:someone@example.com">Send email</a><button onclick="document.location='default.asp'">HTML Tutorial</button>
<a href="https://www.w3schools.com/html/" title="Go to W3Schools HTML section">Visit our HTML Tutorial</a>
  • Example
Use a full URL to link to a web page: 
<a href="https://www.w3schools.com/html/default.asp">HTML tutorial</a>
  • Example
Link to a page located in the html folder on the current web site: 
<a href="/html/default.asp">HTML tutorial</a>
  • Example
Link to a page located in the same folder as the current page: 
<a href="default.asp">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:

<style>
a:link {
  color: green;
  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>

Create a Bookmark in HTML

Bookmarks can be useful if a web page is very long.
To create a bookmark - first create the bookmark, then add a link to it.
When the link is clicked, the page will scroll down or up to the location with the bookmark.
Example
First, use the id attribute to create a bookmark:

<h2 id="C4">Chapter 4</h2>

Then, add a link to the bookmark ("Jump to Chapter 4"), from within the same page:

<a href="#C4">Jump to Chapter 4</a>
  • Use the id attribute (id="value") to define bookmarks in a page
  • Use the href attribute (href="#value") to link to the bookmark 




0 comments:

Post a Comment