Showing posts with label CSS. Show all posts
Showing posts with label CSS. Show all posts

Friday, 1 May 2015

CSS Links

Links are found in every document. Links are used to click their way from one page to another page. With CSS, we can style links to make them decorative and colorful.

Styling Links

Links can be styled with any CSS property such as color, font-family, background etc. In addition, links can be styled differently depending on what state they are in.

The four link states are:
  • a:link - a normal link, or an unvisited link
  • a:visited - a link that the user had visited
  • a:hover - a link when the user mouses over it
  • a:active - a link at the moment it is clicked
For example:
a:link {color:#FF0000;}
a:visited {color:#00FF00;}
a:hover {color:#FF00FF;}
a:active {color:#0000FF;}

Text Decoration

The text-decoration property is mainly used to remove the underline from the links.

For example:
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 is used to specify background color for the links.

For example:
a:link {background-color:#0000FF;}
a:visited {background-color:#FF00FF;}
a:hover {background-color:#00FF00;}
a:active {background-color:#FF0000;}

Saturday, 25 April 2015

CSS List

WebLearn Tech

The CSS List property allows you to set different list item markers for ordered and unordered list. In HTML, there are two kinds of list, unordered list and ordered list. With CSS, it can be styled further and images can be used as lists.

List Style

The list-style property is used to set all list styles in one declaration. The properties are in the order: list-style-type, list-style-position, list-style-image.

For example:

<!DOCTYPE html>
<html>
<head>
<style>
ul
{
list-style:square url('square.gif');
}
</style>
</head>

<body>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
</ul>
</body>
</html>

List Style Image

The list-style-image property replaces the list-item marker with an image.

For example:

<!DOCTYPE html>
<html>
<head>
<style>
ul
{
list-style-image:url('square.gif');
}
</style>
</head>

<body>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
</ul>
</body>
</html>

List Style Position

The list-style-position property is used to specify if the list item markers should appear inside or outside of the content flow.

For example:

<!DOCTYPE html>
<html>
<head>
<style>
ul.a {list-style-position:inside; }
ul.b {list-style-position:outside; }
</style>
</head>

<body>
<p>The following list has the list-style-position inside:</p>
<ul class="a">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
</ul>

<p>The following list has the list-style-position outside:</p>
<ul class="b">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
</ul>
</body>
</html>

List Style Type

The list-style-type property is used to specify the type of list-item in a list.

For example:

<!DOCTYPE html>
<html>
<head>
<style>
ul.a {list-style-type:circle; }
ul.b {list-style-type:square; }
ol.c {list-style-type:upper-roman; }
ol.d {list-style-type:lower-alpha; }
</style>
</head>

<body>
<p>Example of unordered lists:</p>

<ul class="a">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
</ul>

<ul class="b">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
</ul>

<p>Example of ordered lists:</p>

<ol class="c">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
</ol>

<ol class="d">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
</ol>

</body>
</html>

Thursday, 23 April 2015

CSS Text Formatting

HTML text can be styled using CSS. Text formatting properties are used for this purpose.

Text Color

The color property is used to color the HTML text. In CSS, color options can be given by three different ways:
  • HEX value - #000000
  • RGB value - rgb(0,0,0)
  • Color name - Black
For example:
<!DOCTYPE html>
<html>

<head>
<style>
h1.color {color:red;}
p.color {color:blue;}
</style>
</head>

<body>
<h1 class="color">This is a Heading</h1>
<p class="color">This is a paragraph</p>
</body>
</html>

Direction

The direction property is used to denote the text direction or the direction in which the text is written.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.dir {direction:rtl;}
</style>
</head>

<body>
<p>This paragraph is in default direction.</p>
<p class="dir">This paragraph is from right to left.</p>
</body>
</html>

Letter Spacing

The letter-spacing property is used to increase or decrease the space between the characters in a text.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
h1.letter_space {letter-spacing:3px;}
h2.letter_space {letter-spacing:-3px}
</style>
</head>

<body>
<h1 class="letter_space">This is a Heading</h1>
<h2 class="letter_space">This is a Heading</h2>
</body>
</html>

Line Height

The line-height property is used to specify the height of each line.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.small {line-height:50%;}
p.big {line-height:200%;}
</style>
</head>

<body>
<p class="small">This is a paragraph
This is a paragraph
This is a paragraph</p>
<p class="big">This is a paragraph
This is a paragraph
This is a paragraph</p>
</body>
</html>

Text Align

The text-align property is used to horizontally align the text.

For example:

<!DOCTYPE html>
<html>

<head>
<style>
h1.align {text-align:left;}
h2.align {text-align:center;}
h3.align {text-align:right;}
</style>
</head>

<body>
<h1 class="align">This is a Heading</h1>
<h2 class="align">This is a Heading</h2>
<h3 class="align">This is a Heading&lt/h3>
</body>
</html>

Text Decoration

The text-decoration property is used to specify the decoration added to the element.

For example:

<!DOCTYPE html>
<html>

<head>
<style>
h1.decoration {text-decoration:overline;}
h2.decoration {text-decoration:line-through;}
h3.decoration {text-decoration:underline;}
</style>
</head>

<body>
<h11 class="decoration">This is a Heading</h1>
<h21 class="decoration">This is a Heading</h2>
<h31 class="decoration">This is a Heading</h3>
</body>
</html>

Text Indent

The text-indent property is used to specify the indentation of the first line of the text.

For example:

<!DOCTYPE html>
<html>

<head>
<style>
p.indent {text-indent:50px;}
</style>
</head>

<body>
<p class="indent">CSS is used to control the style and layout of multiple 
web pages. It defines how to style HTML elements. An HTML element can be 
 displayed with different styles using CSS.</p>
</body>
</html>

Text Shadow

The text-shadow property is used to add shadow to text element.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
h1.shadow {text-shadow:5px 5px #ffffff;}
</style>
</head>

<body>
<h1 class="shadow">This Heading have Shadow</h1>
</body>
</html>

Text Transform

The text-property is used to specify the capitalization of the text element.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.uppercase {text-transform:uppercase;}
p.lowercase {text-transform:lowercase;}
p.capitalize {text-transform:capitalize;}
</style>
</head>

<body>
<p class="uppercase">This is a Paragraph</p>
<p class="lowercase">This is a Paragraph</p>
<p class="capitalize">This is a Paragraph</p>
</body>
</html>

Unicode Bi-Directional Text

The unicode-bidi property is used along with the direction property to set whether the text should be overridden to support multiple languages.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.dir_bidi {direction:rtl;
unicode-bidi:bidi-override;}
</style>
</head>

<body>
<p>This paragraph is in default direction.</p>
<p class="dir_bidi">This paragraph is from right to left.</p>
</body>
</html>

Vertical Align

The vertical-align property is used to set the vertical align of a text element.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
img.top {vertical-align:top;}
img.bottom {vertical-align:botoom;}
</style>
</head>

<body>
<p>This <img class="top" src="Birds.jpg" />paragraph is  at the top of the 
 image.</p>
<p>This <img class="bottom" src="Birds.jpg" />paragraph is  at the bottom
  of the image.</p>
</body>
</html>

White Space

The white-space property is used to specify how to handle white spaces inside an HTML document.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.white_space {white-space:nowrap}
</style>
</head>

<body>
<p class="white_space">This is a paragraph. This is another paragraph. This 
 is yet another paragraph and so the number of paragraphs continues.</p>
</body>
</html>

Word Spacing

The word-spacing property is used to increase or decrease the white space between words.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.word_space {word-spacing:20px}
</style>
</head>

<body>
<p class="word_space">This is a paragraph.</p>
</body>
</html>

Wednesday, 15 April 2015

CSS Font

The CSS Font property defines the font family, boldness, size and style of the text

Font

The font property is used to set all the font properties in one declaration. The font properties are set in the order of "font-style, font-variant, font-weight, font-size, font-family."

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.html_font {font:"italic bold 15px "Georgia, Serif;}
</style>
</head>

<body>
<p class="html_font">Hyper Text Markup Language</p>
</body>

</html>

Font Family

The font family of a text is set with the font-family property. The font-family property should contain several font names, so that the next font will be displayed if the first font is not present. If the names of the font is more than one word, then it should be contained in a pair of double quotes like "Times New Roman". If there are more than one font, then it should be separated by commas.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.html_fontfamily {font-family:"Times New Roman", Times, Serif;}
p.css_fontfamily {font-family:Arial, Helvetica, sans-serif;}
</style>
</head>

<body>
<p class="html_fontfamily">Hyper Text Markup Language</p>
<p class="css_fontfamily">Cascading Style Sheets</p>
</body>

</html>

Font Size

The font-size property sets the size of the text. Managing the text size is important, but it should not be used to make the text look like heading or so. The font-size value can be absolute or relative size. Font size can be denoted in percentage, pixels, and in emphemeral unit (em).

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.html_size {font-size:90%;}
p.css_size {font-size:10px;}
p.javascript_size (font-size:1.5em;)
</style>
</head>

<body>
<p class="html_size">Hyper Text Markup Language</p>
<p class="css_size">Cascading Style Sheets</p>
<p class="javascript_size">JavaScript</p>
</body>

</html>

Font Style

The font-style property is commonly used to style text. This property has the following values:
  • normal
  • italic
  • oblique
For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.html_style {font-style:normal;}
p.css_style {font-style:italic;}
p.javascript_style {font-style:oblique;}
</style>
</head>

<body>
<p class="html_style">Hyper Text Markup Language</p>
<p class="css_style">Cascading Style Sheets</p>
<p class="javascript_style">JavaScript</p>
</body>

</html>

Font Variant

The font-variant property is used to display the text into a small-caps form. In the small-caps font, all lowercase characters are transformed into upper characters, but will be somewhat smaller in size.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.html_variant {font-variant:normal;}
p.css_variant {font-variant:small-caps;}
</style>
</head>

<body>
<p class="html_variant">Hyper Text Markup Language</p>
<p class="css_variant">Cascading Style Sheets</p>
</body>

</html>

Font Weight

The font-weight property is used to make the text thick or thin.

For example:
<!DOCTYPE html>
<html>

<head>
<style>
p.html_weight {font-weight:normal;}
p.css_weight {font-weight:lighter;}
p.javacript_weight {font-weight:bolder;}
p.jquery_weight {font-weight:100;}
</style>
</head>

<body>
<p class="html_weight">Hyper Text Markup Language</p>
<p class="css_weight">Cascading Style Sheets</p>
<p class="javascript_weight">JavaScript</p>
<p class="jquery_weight">jQuery</p>
</body>

</html>

Sunday, 5 April 2015

CSS Background

CSS background property is used to define the background properties of an element. The background properties used in CSS are:
  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background position

Background

There are many properties when dealing with CSS backgrounds. So to shorten the code, it is best to specify all the properties in a single property. This is called the shorthand property of background. There is no problem if one of the content is missing as long as the ones that are present are in correct order.

For example:
body { 
background:#ffffff url('logo.png') no-repeat fixed top; 
}

Background Color

The background-color property is used to specify the background color of an element. The background color of a page should be declared in the body itself.
In CSS, color options can be given by three different ways:
  • HEX value - #000000
  • RGB value - rgb(0,0,0)
  • Color name - Black
For example:
body { background-color:#e0ffff; }

Background Image

The background-image property is used to specify a background picture in an HTML page. By default, the background image will be repeated to cover all area.

For example:
body { background-image:url("image.png") }

Background Repeat

By default, the background image will be repeated both horizontally and vertically so that it will cover all the region. But using the background-repeat property, we can adjust the repeating option of the image file.
We can adjust the image in the following four ways
  • repeat - Default option, the image will be repeated both horizontally and vertically
  • repeat-x - The image will be repeated horizontally only.
  • repeat-y - The image will be repeated vertically only
  • no-repeat - The image will not be repeated.
For example:
body { background-image:url("image.png"); 
       background-repeat:repeat-x; 
     }

Background Position

The background-position property is used to adjust the position of the image file to a specific position so that it does not disturb the elements.

For example:
body { background-image:url("image.png"); 
       background-repeat:repeat-x; 
       background-position:center; 
     }

Background Attachment

The background-attachment property is used to set whether the image is fixed or it scrolls with the element.
We can attach the elements in the following ways
  • scroll - The background scrolls along with the element.
  • fixed - The background is fixed.
  • local - The background scrolls along with the element's contents.
For example:
body { background-image:url("image.png"); 
       background-repeat:repeat-x; 
       background-position:center; 
       background-attachment:fixed;
     }

Friday, 3 April 2015

CSS3

CSS has evolved over time from CSS1 to CSS2(which are the current standard) to CSS3(which is still in development.) CSS3 is the latest standard of CSS. The term "CSS3" is not just a reference to the new features of CSS, but the third level in the progress of the CSS specifications.

It is a language which describes how a document looks and how it is formatted. Modern browsers support CSS1 and CSS2 but the support to CSS3 is limited. CSS3 has been split into modules. It contains the old CSS specifications ans new modules are added. Some of the new modules are:
  • Selectors
  • Box Model
  • Backgrounds and Borders
  • Image Values and Replaced contents
  • Text Effect
  • 2D/3D Transformation
  • Animations
  • Multiple Column Layout
  • User Interface
With CSS3, it is possible to add rounded borders, shadows to boxes, and use an image as border and much more.

Wednesday, 26 November 2014

Introduction to CSS

CSS is used to control the style and layout of multiple web pages. It defines how to style HTML elements. An HTML element can be displayed with different styles using CSS.

CSS stands for Cascading Style Sheets.

CSS language are normally saved as external .css file. External style sheets helps you to change the appearance and layout of al the webpages using a single file. Therefore, using a CSS file can save you a lot of work and design the webpage as you like.

CSS Syntax

A CSS declaration always ends in a semi-colon and the group is surrounded by curly brackets. A CSS rule consist of a selector and the declaration block:

For example:
h1 {color:blue;}
In this example, "h1" is the selector. The selector points out the HTML element you want to style.The selector is used to select a specific tag in which the style is to be applied on and edit the element according to our wish. CSS selectors are used to find or select the HTML element based on their id, classes, types, attributes, values of attributes etc.

Everything inside the curly bracket is called the declaration. The declaration block can contain more than one or more declarations separated by a comma. Each declaration contains a property name and values, which is separated by a comma. In this example, the property name is "color" and the value is "blue". It specifies the color of the h1 heading to be blue in color.

CSS Comments

Comments are used to explain the code or what that HTML element is used for. It is very useful for users to edit the source code later. Comments are ignored by the browser, so that they are not displayed in the web browser.

CSS comments starts with /* and ends with */. Comments are plain text written inside /* and */. Comments can also span multiple lines

For example:
/*This is a single line comment*/
h1 {color:blue;
/*This is a 
multiple line comment*/
}

CSS Style Sheets

CSS style sheets can be added in three ways:

  1. External Style Sheets
  2. Internal Style Sheets
  3. Inline Style Sheets
External Style Sheets: An external style sheets is used when the same style is used to more than one webpage. With an external style sheet, we can change the looks of the entire webpage by changing just one file. Each page must be linked to the style sheet using the tag. The tag goes inside the head section.

For example:
<head>
<link href="style.css" rel="stylesheet" type="text/css"></link>
</head>
An external CSS style sheet can be written in Notepad just like HTML, but should be saved with .css extension.

For example:
h1 {color:blue;}
p{color:red;}
Internal Style Sheets: An internal style sheet should be used when a single document should have a unique style. We can define internal style sheet in the head section of the HTML page,using the &ltstyle> tag.

For example:
<head>
<style>
h1 {color:blue;}
p{color:red;}
</style>
<head>
Inline Style Sheets: An inline style sheet is used when a single element should be given a unique style. Inline styles are given inside the tag itself as attributes. To use the inline style, we should use the style attribute in that particular tag. The style is possible to contain any CSS styles but that property is only restricted to that particular element only.

For example:
<div style="color: red;">
This is a paragraph.</div>