Styling HTML with CSS
CSS stands for Cascading Style Sheets.
CSS describes how HTML elements are to be displayed on screen, paper, or in other media.
CSS can be added to HTML elements in 3 ways:
Inline - by using the style attribute in HTML elements
Internal - by using a
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
This is a Blue Heading
External CSS
An external style sheet is used to define the style for many HTML pages.
To use an external style sheet, add a link to it in the section of the HTML page:
This is a paragraph.
This is a heading
This is a paragraph.
CSS Border
The CSS border property defines a border around an HTML element:
p { border: 1px solid powderblue;}
CSS Padding
The CSS padding property defines a padding (space) between the text and the border:
Example
p { border: 1px solid powderblue; padding: 30px;}
CSS Margin
The CSS margin property defines a margin (space) outside the border:
p { border: 1px solid powderblue; margin: 50px;}
CSS Syntax and Selectors
A CSS rule-set consists of a selector and a declaration block:
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.
The id Attribute
To define a specific style for one special element, add an id attribute to the element:
I am different
The class Attribute
To define a style for a special type of elements, add a class attribute to the element:
I am different
© ООО «Знанио»
С вами с 2009 года.