Вы находитесь на странице: 1из 6

CSS stands for Cascading Style Sheets.

CSS describes how HTML elements are to be displayed on screen, paper,


or in other media.

CSS saves a lot of work. It can control the layout of multiple web pages all at
once.

Why Use CSS?


CSS is used to define styles for your web pages, including the design, layout
and variations in display for different devices and screen sizes.

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

The selector points to the HTML element you want to style.

The declaration block contains one or more declarations separated by


semicolons.

Each declaration includes a CSS property name and a value, separated by a


colon.

A CSS declaration always ends with a semicolon, and declaration blocks are
surrounded by curly braces
CSS can be added to HTML elements in 3 ways:

Inline - by using the style attribute in HTML elements


Internal - by using a <style> element in the <head> section
External - by using an external CSS file

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.

<h1 style="color:blue;">This is a Blue Heading</h1>

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

An internal CSS is defined in the <head> section of an HTML page, within a


<style> element:

<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>

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

With an external style sheet, you can change the look of an entire web
site, by changing one file!

To use an external style sheet, add a link to it in the <head> section of the
HTML page
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.

#test {
text-align: center;
color: red;
}

Note: an id name cannot start with number.

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="test" will be red and
center-aligned:

.test {
text-align: center;
color: red;
}

Grouping Selectors
If you have elements with the same style definitions
h1, h2, p {
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.

CSS background:

Background Color
The background-color property specifies the background color of an element.

The background color of a page is set like this:

body {
background-color: lightblue;
}
Background Image
The background-image property specifies an image to use as the background of
an element.

By default, the image is repeated so it covers the entire element.

The background image for a page can be set like this:

body {
background-image: url("paper.gif");
}

CSS Fonts :
The CSS color property defines the text color to be used.

The CSS font-family property defines the font to be used.

The CSS font-size property defines the text size to be used.

h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 160%;
}

CSS Border :
The CSS border property defines a border around an HTML element.

p {
border: 1px solid red;
}
CSS Padding
The CSS padding property defines a padding (space) between the text and the
border:

p {
border: 1px solid powderblue;
padding: 30px;
}

CSS Margin:
p {
border: 1px solid powderblue;
margin: 50px;
}

Вам также может понравиться