css 1
css 1
● Create Stunning Web site - CSS handles the look and feel part of a web page.
Using CSS, you can control the color of the text, the style of fonts, the spacing
between paragraphs, how columns are sized and laid out, what background images
or colors are used, layout designs,variations in display for different devices and
screen sizes as well as a variety of other effects.
● Control web - CSS is easy to learn and understand but it provides powerful control
over the presentation of an HTML document. Most commonly, CSS is combined with
the markup languages HTML or XHTML.
● Learn other languages - Once you understands the basic of HTML and CSS then
other related technologies like javascript, php, or angular are become easier to
understand.
CSS Syntax
A CSS rule-set consists of a selector and a declaration block:
● Selector − A selector is an HTML tag at which a style will be applied. This
could be any tag like <h1> or <table> etc.
● Property − A property is a type of attribute of HTML tag. Put simply, all the
HTML attributes are converted into CSS properties. They could be color,
border etc.
● Value − Values are assigned to properties. For example, color property can
have value either red or #F1F1F1 etc.
The element selector selects HTML elements based on the element name.\
<head>
<style>
p{
text-align: center;
color: red;
</style>
</head>
<p>Me too!</p>
<p>And me!</p>
</body>
ID Selectors
You can define style rules based on the id attribute of the elements. All the elements
having that id will be formatted according to the defined rule.The id of an element is
unique within a page, so the id selector is used to select one unique element!
#black {
color: black; }
This rule renders the content in black for every element with id attribute set to black
in our document.
h1#black {
color: black;
This rule renders the content in black for only <h1> elements with id attribute set to
black.
To select elements with a specific class, write a period (.) character, followed by the
class name.
This rule renders the content in black for every element with class attribute set to
black in our document.
.black {
color: black;
This rule renders the content in black for only <h1> elements with class attribute set
to black.
h1.black {
color: black;
CSS - Inclusion
There are three ways to associate styles with your HTML document. Most commonly
used methods are inline CSS and External CSS.
● External CSS
● Internal CSS
● Inline CSS
External CSS - The <link> Element
An external style sheet is a separate text file with .css extension. You define all the
Style rules within this text file and then you can include this file in any HTML
document using <link> element.
External styles are defined within the <link> element, inside the <head> section of an
HTML page:
Syntax:
<head>
</head>
Internal CSS
You can put your CSS rules into an HTML document using the <style> element. This
tag is placed inside the <head>...</head> tags.
An internal style sheet may be used if one single HTML page has a unique style.
body {
background-color: red;
h1 {
color: maroon;
margin-left: 40px;
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
Inline CSS
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style attribute to the relevant element. The style attribute
can contain any CSS property.
<body>
</body>
CSS Colors
CSS uses color values to specify a color.
These are used to set a color either for the foreground of an element (i.e., its text) or
else for the background of the element.
They can also be used to affect the color of borders and other decorative effects.
#rrggbb
rgb(red,green,blue)