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:

CSS
Selectors and Combinators

Here are the possible selectors and combinators:

Selector

CSS selectors are the patterns utilize for selecting the elements for style purpose.

SelectorDescriptionSyntax
TypeIt selects all the elements that match the given node name.selector_name
ClassIt selects all elements that have the given class attribute..class_name
IDIt selects an element based on the value of its id attribute.#id_name
UniversalIt selects all elements.* universal_name|* *|*
AttributeIt selects the elements based on the value of given attribute.[attr] [attr_value]

Combinator

CSS combinators are used to explain the relationship between two or more selectors.

SelectorDescriptionSyntax
Adjacent SiblingThe “+” combinator selects adjacent siblings, which means, the second element directly follows the first, and both share the same parent.Selector + Selector
General SiblingThe ~ combinator selects siblings, which means, the second element follows the first, and both share the same parentSelector ~ Selector
ChildThe > combinator selects the direct children of the first element.Selector > Selector
DescendantThe (space) combinator selects the nodes which are descendants of the first element.Selector Selector
ColumnThe || combinator selects nodes which belong to a column.Selector || Selector


CSS
Integration

In order to apply CSS properties on existing HTML tags, it is must to link CSS code with HTML. There are three ways to embed CSS file into HTML document.

Inline CSS

Inline style is applied to an individual tag. It modifies the attributes of a tag in the current occurrence of that tag. If the tag is used again, the default style of the tag will be used.

The attributes are given in the opening tag using <style>.

Example:

<!doctype html>  
<html>

    <head>
        <title>...</title>
    </head>
  
    <body>
        <p style=”color: blue;”> PHPDocs</p>
    </body>
</html>


Internal CSS

An internal style sheet is inserted in the head section of a web page. It only affects the web page in which it is inserted. It is added in an HTML document using the <style> tag.

Example:

<!doctype html>  
<html>
    <head>
        <style type=”text/css”>
            H4{ color: green; }
            H5{ color: red; }
        </style>
    </head>
  
    <body>
        ...
    </body>
</html>

External CSS

An external style sheet is defined in a separate file stored with .css extension. It is very useful when the style is applied to many pages.

It is used to specify the style of an entire website in one file. An external style sheet file is then linked to the web page using the <link> tag. This <link> tag us written inside the head section.

Example:

<!doctype html>  
<html>
    <head>
        <link rel=”stylesheet” type=”text/css” href=”mystyle.css”>
    </head>
  
    <body>
        ...
    </body>
</html>


Introduction to
CSS

Cascading Style Sheet (CSS) is a collection of formatting styles that are used to modify the properties of existing HTML tags. The designer can specify the design of a web page in a style sheet.

The same style sheet can be used in multiple web pages. It provides a facility of creating websites with consistent design and outlook.

Basic Syntax

Selector{
         Property: Value;
}
              

CSS Breakdown

Here is the breakdown of CSS