Css
Css
Advantages of CSS
1.CSS saves time – You can write CSS once and then reuse same sheet in multiple
HTML pages
2.Pages load faster – If you are using CSS, you do not need to write HTML tag
attributes every time. Just write one CSS rule of a tag and apply to all the
occurrences of that tag. So less code means faster download times.
3.Easy maintenance – To make a global change, simply change the style, and all
elements in all the web pages will be updated automatically
4.Superior styles to HTML – CSS has a much wider array of attributes than HTML so
you can give far better look to your HTML page in comparison of HTML attributes.
6.Global web standards – Now HTML attributes are being deprecated and it is being
recommended to use CSS. So it’s a good idea to start using CSS in all the HTML
pages to make them compatible to future browsers
1. External Style Sheet – Define style sheet rules in a separate .css file and then
include that file in your HTML document using HTML <link> tag.
2. Internal Style Sheet – Define style sheet rules in header section of the HTML
document using <style> tag.
3. Inline Style Sheet – Define style sheet rules directly along with the HTML
elements
using style attribute. Let’s see all the three cases one by one with the help of
suitable
examples
SELECTORS IN CSS
1:TYPE SELECTOR
<body>
<p>Every paragraph will be affected by the style.</p>
<p id="para1">Me too!</p>
<p>And me!</p>
</body>
<style>
p{
text-align: center;
color: red;
}
</style>
===================================================================================
========
2:ID SELECTOR
<body>
<p id="para1">Hello World!</p>
<p>This paragraph is not affected by the style.</p>
</body>
<style>
#para1{
text-align: center;
color: red;
}
</style>
===================================================================================
=========
3:CLASS SELECTOR
<body>
<h1 class="center">Red and center-aligned heading</h1>
<p class="center">Red and center-aligned paragraph.</p>
</body>
<style>
.center {
text-align: center;
color: red;
}
</style>
===================================================================================
========
<body>
<h1 class="center">This heading will not be affected</h1>
<p class="center">This paragraph will be red and center-aligned.</p>
</body>
<style>
p.center {
text-align: center;
color: red;
}
</style>
===================================================================================
========
5.UNIVERSAL SELECTOR "*" or empty space
<body>
<h1>Hello world!</h1>
<p>Every element on the page will be affected by the style.</p>
<p id="para1">Me too!</p>
<p>And me!</p>
</body>
<style>
* {
text-align: center;
color: blue;
}
</style>
===================================================================================
========
6.GROUPING SELECTOR
<body>
<h1>Hello World!</h1>
<h2>Smaller heading!</h2>
<p>This is a paragraph.</p>
</body>
<style>
h1, h2, p {
text-align: center;
color: red;
}
</style>
===================================================================================
========
7.ATTRIBUTE SELECTOR
synatx:
type[attribute='value'{
}
<body>
<form>
Firstname:<input type="text" name="Name" value="Peter" size="20">
Lastname:<input type="text" name="Name" value="Griffin" size="20">
<input type="button" value="Example Button">
</form>
</body>
<style>
input[type="text"] {
width: 150px;
display: block;
margin-bottom: 10px;
background-color: yellow;
}
input[type="button"] {
width: 120px;
margin-left: 35px;
display: block;
}
</style>
===================================================================================
===================================
CSS OVERRIDING RULE
INLINE>>>INTERNAL>>>EXTERNAL
===================================================================================
===================================
COLOR CODES:
ways:2
way1:Hexadecimal notation
A hexadecimal is a 6 digit representation of a color. The first two digits(RR)
represent a
red value, the next two are represent a green value(GG), and the last are represent
the
blue value(BB).
A hexadecimal value can be taken from any graphics software like Adobe Photoshop,
Jasc Paintshop Pro or even using Advanced Paint Brush.
Each hexadecimal code will be preceded by a pound or hash sign #.
example:#000000(black),#FFFFFF(white)
This color value is specified using the rgb( ) property. This property takes three
values,
one each for red, green, and blue. The value can be an integer between 0 and 255 or
a
percentage.
Note: All the browsers do not support rgb() property of color so it is recommended
not to
use it
Example:-
rgb(0,0,0) for black color
rgb(255,255,255) for white color