CSS
Background Colors

In HTML background colors and background image can be applied to the whole page or to a table. CSS provides the facility to apply background color to whole page word.

The property used for this purpose id background-color.

Basic Syntax

p{
   background-color: blue;
}

Background Color Example

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <p style="background-color: yellow;">Learn CSS with PHPDocs community</p>
    </body>
</html>


CSS
Height & Width

Height and width are dynamic dimensions of an element as they fluctuate in order to fit the content.

The width CSS property specifies the width of an element, and the height CSS property specifies the height of an element.

Dimensions Properties

The possible properties can be used to set dimensions are as follows:

PropertyDescription
heightIt specifies the height of an element.
widthIt specifies the width of an element.
max-heightIt specifies the maximum height of an element.
max-widthIt specifies the maximum width of an element.
min-heightIt specifies the minimum height of an element.
min-widthIt specifies the minimum width of an element.

Dimensions Example

Below examples will demonstrate the basic architecture of height ∓ width

Basic Syntax:

h1{
   height:40px;
  width:30px; 
}

Example:

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <h1 style="height:40h1x; width:30px;">PHPDocs</h1>
    </body>
</html>

CSS
Hyperlink

A hyperlink is an element in a hypertext markup language (HTML) document that links to either another portion of the document or to a different document altogether.

Browsers highlight the content of this element as blue and underlined and permit users to follow the link with a click.

Hyperlink Properties

The following four style sheet entities are used to control hyperlinks in CSS.

ValuesDescription
a:linkIt is used to specify the attributes of a hyperlink
a:visitedIt is used to specify the attributes of a hyperlinks that have been visited
a:activeIt is used to specify the attributes of an active hyperlink
a:hoverIt is used to specify the attributes of the hyperlinks on which the user is moving the mouse.

Hyperlink Example

Below examples will demonstrate the basic architecture of Hyperlink

Basic Syntax:

a:hover{
   color: magenta;
   text-decoration: none;
}

Example:

<!doctype html>  
<html>
    <head>
        <title>...</title>
        <style type="text/css"> 
          h1:hover{
             color: magenta;
            text-decoration: none;
          }
        </style>
    </head>
  
    <body>
       <h1 style="color: #00DDFF;">PHPDocs</h1>
    </body>
</html>


CSS
Indent

The command Indent the first line in every paragraph. Empty space before lines of text in a block is called indentation.

Basic Syntax

Indent Example

Below example will demonstrate the basic architecture of CSS Indent

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <p style="text-indent: 10px;">You can learn programming languages from PHPDocs.</p>
    </body>
</html>

Units

The possible units can be used for these properties are as follows:

ValuesDescription
pixelValues with “px” e.g. 3px, 4px
percentageValues with “%” e.g. 1%, 6%

CSS
Spacing

There are two types of spacing properties in CSS.

  1. Letter Spacing
  2. Word Spacing

Letter Spacing

The letter-spacing defines the spacing between the characters of a block of text.

Syntax:
Example:

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <p style="letter-spacing: 3px;">You can learn programming languages from PHPDocs.</p>
    </body>
</html>

Word Spacing

The word-spacing defines the length of space between words and tags.

Syntax:
Example:

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <p style="word-spacing: 3px;">You can learn programming languages from PHPDocs.</p>
    </body>
</html>


Units

The possible units can be used for these properties are as follows:

ValuesDescription
pixelValues with “px” e.g. 3px, 4px
remValues with “rem” e.g. 1rem, 6rem
normalIt alters the space between characters in order to justify text.


CSS
Float

Float is used to align an element to the left or right side of its container.

It is similar to text-align but the main difference between them is that Align does not remove the item from the document flow whereas float removes it.

Property Values

The possible values are as follows:

ValuesDescription
rightIt aligns the element along the right side.
leftDefault value. It aligns the element along the left side.
inheritIt inherits the alignment of the parent.

Float Example

Below example will demonstrate the basic architecture of CSS Float

Float text to right
Float text to left
Float text as inherit
Example:

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <p style="float: right;">Learn CSS from PHPDocs.</p>
    </body>
</html>

CSS
Text Alignment

Text alignment is specified by using the property text-align. It only works on block level elements i.e. the elements that add line break around themselves like h1, p, img etc.

Property Values

The possible values are as follows:

ValuesDescription
rightIt aligns the text along the right side.
leftDefault value. It aligns the text along the left side.
centerIt aligns the contents to the center within the line box.
justifyIt specifies the text as justify in order to exactly fill the line box.

Text Alignment Example

Below example will demonstrate the basic architecture of Text Alignment

Align text to right
Align text to left
Align text as center
Align text as justify
Example:

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <p style="float: center;">Learn CSS from PHPDocs.</p>
    </body>
</html>

CSS
Text Decoration

The last formatting property is text-decoration. It is used to remove the underlines and other effects of the text. It is normally used to remove the underline from hyperlinks.

Property Values

The possible values are as follows:

ValuesDescription
noneIt removes any extra formatting and makes the text normal.
underlineIt adds an underline.
overlineIt adds a line over the text.
line-throughIt creates a strike through effect.
blinkIt makes the text flash on and off.
dashedIt makes the text dashed.
dottedIt makes the text dotted.
doubleThe line will display as a double line.
inheritIt inherits the decoration of the parent.
initialIt sets this property to its default value.
solidThe line will display as a single line. It is default value.
wavyIt gives wavy effect to text.

Text Decoration Example

Below examples will demonstrate the basic architecture of Text Decoration

              
p {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: red;
}

It can also be written as

p{
  text-decoration: underline wavy red;
}

Example:

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <p style="text-decoration: underline wavy red;">Learn CSS from PHPDocs.</p>
    </body>
</html>

CSS
Special Effects

Some special effects in CSS are following:

Italics

CSS command for italics is font-style. The possible values are inherit, initial, italic, normal, oblique or unset.

Basic Syntax:

Example:

<!doctype html>  
<html>

    <head>
        <title>...</title>
    </head>
  
    <body>
       <p style="font-style: italic;">Learn CSS from PHPDocs.</p>
    </body>

    </html>

Boldness

The property that controls the boldness of text is font-weight.

Basic Syntax:
Example:

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <p style="font-weight: bold;">Learn CSS from PHPDocs.</p>
    </body>
    </html>

Capitalization

CSS provides two properties to specify the capitalization of text. Font-variant is used to set all characters in small versions of capital letters.

The possible values are:

  • uppercase: makes all the letters capital.
  • lowercase: makes all the letters small.
  • capitalize: capitalize the first letter in every word.
  • none: override any inherited transformation.
Basic Syntax:

p{ font-variant: small-caps; }

Example:

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <p style="font-variant: small-caps;">Learn CSS from PHPDocs.</p>
    </body>
    </html>


CSS
Text Formatting

HTML provides limited facilities for text formatting, whereas, CSS provides complete text formatting presentation and style.

Text Color

Text color is changed by specifying any color to color property. The color value can be pecified as hexadecimal code like #00DDFF or a named color value like red.

Basic Syntax:
Example:

<!doctype html>  
<html>
    <head>
        <title>...</title>
    </head>
  
    <body>
       <h1 style="color: #00DDFF;">PHPDocs</h1>
    </body>
    </html>

Typeface

Typeface is used to specify the font-family of the text.

The browser will keep going down the list of specified faces until it finds one that is installed on the system. If no font in the list is installed on the system, a font similar to the specified face will be used.

Basic Syntax:
h2 { font-family: Verdana, Arial, Helvatica;}
Example:

<!doctype html>  
<html>

    <head>
        <title>...</title>
    </head>
  
    <body>
       <h2 style="font-family: Verdana, Arial, Helvatica;">PHPDocs</h2>
    </body>

    </html>

Text Size

CSS can be used to specify the text size. HTML can display text of size 7 at maximum. In CSS, font-size property is used to specify the size of text.

The size can be specified by using different units that are as follows:

  • Units: points (like 50pt, 70pt etc) and pixels (like 43px, 52px etc)
  • Predefined Keywords: small, medium, large etc
  • Percentage: 2%, 5% etc
Using Point:
Using Pixel:
Using Keyword:
Using Percentage: