You are on page 1of 7

CSS Syntax

A CSS rule-set consists of a selector and a declaration block:

CSS Selectors

CSS selectors are used to "find" (or select) HTML elements based on their element name, id,
class, attribute, and more.

The element Selector

The element selector selects elements based on the element name.

The id Selector

The id selector uses the id attribute of an HTML element to select a specific element.

The id of an element should be unique within a page, so the id selector is used to select one
unique element!

To select an element with a specific id, write a hash (#) character, followed by the id of the
element.

Example
#para1 {
text-align: center;
color: red;
}

The class Selector

The class selector selects elements with a specific class attribute.

To select elements with a specific class, write a period (.) character, followed by the name
of the class.

In the example below, all HTML elements with class="center" will be red and center-
aligned:
Example
.center {
text-align: center;
color: red;
}

CSS Comments
Comments are used to explain the code, and may help when you edit the
source code at a later date.

Comments are ignored by browsers.


A CSS comment starts with /* and ends with */. Comments can also span
multiple lines:
How to create another property and value in one selector

External CSS

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.

This example sets the text color of the <h1> element to blue:

Internal CSS
An internal CSS is used to define a style for a single HTML page.

External CSS
An external style sheet is used to define the style for many HTML pages.
Property Description

color Sets the color of text

direction Specifies the text direction/writing direction

letter-spacing Increases or decreases the space between characters in a text

line-height Sets the line height

text-align Specifies the horizontal alignment of text

text-decoration Specifies the decoration added to text

text-indent Specifies the indentation of the first line in a text-block

text-shadow Specifies the shadow effect added to text

text-transform Controls the capitalization of text

text-overflow Specifies how overflowed content that is not displayed should be si


the user

unicode-bidi Used together with the direction property to set or return whether
should be overridden to support multiple languages in the same docu

vertical-align Sets the vertical alignment of an element

white-space Specifies how white-space inside an element is handled

word-spacing Increases or decreases the space between words in a text


Why Use Bootstrap?
Advantages of Bootstrap:

 Easy to use: Anybody with just basic knowledge of HTML and CSS can
start using Bootstrap
 Responsive features: Bootstrap's responsive CSS adjusts to phones,
tablets, and desktops
 Mobile-first approach: In Bootstrap 3, mobile-first styles are part of the
core framework
 Browser compatibility: Bootstrap is compatible with all modern
browsers (Chrome, Firefox, Internet Explorer, Edge, Safari, and Opera)

Where to Get Bootstrap?


There are two ways to start using Bootstrap on your own web site.
You can:

 Download Bootstrap from getbootstrap.com

Include Bootstrap from a CDN Rounded Corners


The .img-rounded class adds rounded corners to an image (IE8 does not
support rounded corners):

Thumbnail
The .img-thumbnail class shapes the image to a thumbnail:

Responsive Images
Images come in all sizes. So do screens. Responsive images automatically
adjust to fit the size of the screen.
Create responsive images by adding an .img-responsive class to
the <img> tag. The image will then scale nicely to the parent element.
The .img-responsive class applies display: block; and max-width:
100%; and height: auto; to the image:
Bootstrap Basic Table
A basic Bootstrap table has a light padding and only horizontal dividers.
The .table class adds basic styling to a table

Striped Rows
The .table-striped class adds zebra-stripes to a table:

Bordered Table
The .table-bordered class adds borders on all sides of the table and cells:

Hover Rows
The .table-hover class adds a hover effect (grey background color) on table
rows:

Condensed Table
The .table-condensed class makes a table more compact by cutting cell
padding in half:

Contextual Classes
Contextual classes can be used to color table rows (<tr>) or table cells (<td>):

Responsive Tables
The .table-responsive class creates a responsive table. The table will then
scroll horizontally on small devices (under 768px). When viewing on anything
larger than 768px wide, there is no difference:

<h1> - <h6>
By default, Bootstrap will style the HTML headings (<h1> to <h6>) in the
following way:

<small>
In Bootstrap the HTML <small> element is used to create a lighter, secondary
text in any heading
<mark>
Bootstrap will style the HTML <mark> element in the following way:

<abbr>
Bootstrap will style the HTML <abbr> element in the following way:

<blockquote>
Bootstrap will style the HTML <blockquote> element in the following way:

<dl>
Bootstrap will style the HTML <dl> element in the following way:

<code>
Bootstrap will style the HTML <code> element in the following way:

Grid System Rules


Some Bootstrap grid system rules:

 Rows must be placed within a .container (fixed-width) or .container-


fluid (full-width) for proper alignment and padding
 Use rows to create horizontal groups of columns
 Content should be placed within columns, and only columns may be
immediate children of rows
 Predefined classes like .row and .col-sm-4 are available for quickly
making grid layouts
 Columns create gutters (gaps between column content) via padding. That
padding is offset in rows for the first and last column via negative margin
on .rows
 Grid columns are created by specifying the number of 12 available
columns you wish to span. For example, three equal columns would use
three .col-sm-4
 Column widths are in percentage, so they are always fluid and sized
relative to their parent element
Grid Classes
The Bootstrap grid system has four classes:

 xs (for phones - screens less than 768px wide)


 sm (for tablets - screens equal to or greater than 768px wide)
 md (for small laptops - screens equal to or greater than 992px wide)
 lg (for laptops and desktops - screens equal to or greater than 1200px
wide)