Monday, June 17, 2013

What is CSS? Lesson #1

Cascading Style Sheets (CSS) is a design language. It

simplify the presentation of web pages. CSS take care of the look and feel of a web page. CSS help control the color of the text, the style of fonts, spacing between paragraphs, background images and other effects. CSS enable presenting same content on different devices like mobiles , tabs, Web TV and desktops. CSS is combined with HTML and XHTML.

CSS Syntax
Selector: is an HTML element like <h1> for style to be applied.Property: is an attribute HTML element like width or border
Value: Values are assigned to attributes/properties. color:red etc.

Inline CSS
<p style="color:red;margin-left:10px;">This is a paragraph.</p>

Internal Style Sheet
Internal styles are defined in the <head> section of an HTML document, by using the <style> tag.

<style type="text/css">
body {background-color:brown;}
p {color:yellow;}

External Style Sheet
An external style sheet is used to apply same style to many pages. As each page links to a common style sheet, you can change look and feel of all web pages  by changing the external css.

<link rel="stylesheet" type="text/css" href="mystyle.css">

Importing an external style sheet
@import "mystyle.css";

Universal selector
The css renders the content of every element in black.
* {
  color: #000000;

The Descendant Selectors: style rule will apply to <em> element only when it lies inside <ul> tag.

ul em {
  color: #000000;

The Class Selectors:
All the elements having "black" will have text in black.

.black {
  color: #000000;

Renders the text in black for <h1> elements with class name "black" {

  color: #000000;

<div class="centerbold">
This content will be styled by the class centerbold.

ID Selectors:
All the elements having same id will be formatted.

Renders the content in black for every element with id "black"

#black {
  color: #000000;

Renders only the H1 with id ="black"

h1#black {

  color: #000000;

Multiple Styling:
define multiple styles of single element, class or id.

h1 {
color: red;
margin-bottom: 1.1em;
text-transform: lowercase;

Grouping Selectors:
You can apply a style to many selectors in one go.

h1, h2, h3 {
color: #EFEFEF;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;

You can combine various class selectors together as shown below:

#content, #footer, #supplement {
position: absolute;
left: 510px;
width: 200px;

No comments:

Post a Comment