0% found this document useful (0 votes)
5 views23 pages

HTML CSS

Uploaded by

formyself3378
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views23 pages

HTML CSS

Uploaded by

formyself3378
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

HTML STYLES - CSS

WHAT IS CSS?
 Cascading Style Sheets (CSS) is used to format the layout of a webpage.
 With CSS, you can control the color, font, the size of text, the spacing
between elements, how elements are positioned and laid out, what
background images or background colors are to be used, different displays
for different devices and screen sizes, and much more!
 Tip: The word cascading means that a style applied to a parent element
will also apply to all children elements within the parent. So, if you set the
color of the body text to "blue", all headings, paragraphs, and other text
elements within the body will also get the same color (unless you specify
something else)!
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
The most common way to add CSS, is to keep the styles in external CSS
files. However, in this tutorial we will use inline and internal styles,
because this is easier to demonstrate, and easier for you to try it yourself.
INLINE CSS
An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the <h1> element to blue,
and the text color of the <p> element to red:

<h1 style="color:blue;">A Blue Heading</h1>

<p style="color:red;">A red paragraph.</p>


INTERNAL CSS
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML page,
within a <style> element.
The following example sets the text color of ALL the <h1> elements
(on that page) to blue, and the text color of ALL the <p> elements to red.
In addition, the page will be displayed with a "powderblue" background color:
<!DOCTYPE html>
<html>
<head>
<style>
body{background-colorj: powderblue;}
h1 {color:blue;}
p {color:red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS Colors, Fonts and Sizes
Here, we will demonstrate some commonly used CSS properties.
You will learn more about them later.
The CSS color property defines the text color to be used.
The CSS font-family property defines the font to be used.
The CSS font-size property defines the text size to be used.
 <!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p{
color: red;
font-family: courier;
font-size: 160%;
}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>
CSS BORDER
The CSS border property defines a border around an HTML element.
Tip: You can define a border for nearly all HTML elements.

p {
border: 2px solid powderblue;
}
CSS PADDING
The CSS padding property defines a padding (space) between the text and the border

p {
border: 2px solid powderblue;
padding: 30px;
}
CSS MARGIN
The CSS margin property defines a margin (space) outside the border.

p {
border: 2px solid powderblue;
margin: 50px;
}
CHAPTER SUMMARY

•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
 Links are found in nearly all web pages. Links allow users to click their way
from page to page.
 HTML Links - Hyperlinks
 HTML links are hyperlinks.
 You can click on a link and jump to another document.
 When you move the mouse over a link, the mouse arrow will turn into a
little hand.
HTML LINKS - SYNTAX
The HTML <a> tag defines a hyperlink. It has the following syntax:

The most important attribute of the <a> element is the href attribute,
which indicates the link's destination.
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.

<a href=“ URL”>Visit YouTube Page</a>


 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
EXAMPLE
 <a href=“https://www.youtube.com/?
gl=ES” target="_blank">YouTube </a>
ABSOLUTE URLS VS.
RELATIVE URLS
Both examples above are using an absolute URL (a full web address) in the href attribute.
A local link (a link to a page within the same website) is specified with a relative URL
(without the "https://www" part):

<h2>Absolute URLs</h2>
<p><a href="https://www.youtube.com/?
gl=EShttps://www.youtube.com/?
gl=ES">Youtube page</a></p>
<p><a href="https://www.google.com/">Google
</a></p>

<h2>Relative URLs</h2>
<p><a href="https://passport.moi.gov.af/">O
nline passport form</a></p>
<p><a href="">…</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:

<a href="https://passport.moi.gov.af/">
<img src=“Mustafa.JPEG" alt=“Online Passport Form" 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=“bayat_benyamin@yahoo.com">Send email to


Muhammad Mustafa </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:

<button
onclick="document.location='https://passport.m
oi.gov.af/'"> New button
</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.

<a href="https://passport.moi.gov.af//" title="Go


to Online Passport">Vist the Online form Page</a>
CHAPTER SUMMARY
•Use the <a> element to define a link
•Use the href attribute to define the link address
•Use the target attribute to define where to open the linked document
•Use the <img> element (inside <a>) to use an image as a link
•Use the mailto: scheme inside the href attribute to create a link that opens
• the user's email program

You might also like