CSS

From Grundy
Revision as of 05:38, 23 October 2017 by Ydidwania (talk | contribs) (Added Selectors)
Jump to navigation Jump to search

Cascading Style Sheet(CSS) is a style sheet language used for describing how the content, written in some markup language should be displayed on screen. It controls the style and layout of web pages. So one can use CSS to alter the text styles, table sizes, and other aspects of webpages that previously could only be defined in a page's HTML.

CSS helps Web developers create a uniform look and feel across several pages of a website. You donot have to define the style of each block of text within a page's HTML, commonly used styles need to be defined only once in a CSS file and can be used by any page that references that CSS file.

All websites on the internet today use CSS to style their webpages, hence it is the first technology one should start learning after HTML. It is highly recommended to have a basic knowledge about HTML before trying to learn CSS. You cannot really learn much about or use CSS without knowing the fundamentals of HTML.


Selectors

All the content on a webpage does not have the same style, and this why selectors are required. A CSS selector is that part of the CSS rule set which decides the set of elements to style. Here's an example

/* All p elements are red */
p {
  color: red;
}

The class or id of an HTML element are also used as selectors. Note that CSS uses the prefix # for IDs and . for Classes.

/* All  the elements with the class "important" are red */
.important {
  color: red;
}

/* The element with the id "header" is bolded */
#header {
  font-weight: bold;
}