7 CSS1 Owd 2014 PDF
7 CSS1 Owd 2014 PDF
1 Advantages of CSS
Less work
Well supported
1.3 Color
Either names or numerical values can be used.
h1 {color: olive;}
{color : #000FF;}
{color: #00F;}
{color: rgb(0,0,255);}
{color: rgb(0%, 0%, 100%);}
- Left aligned,
- Right aligned
- Centered
<style type="text/css">
p.levo { text-align : left }
p.desno { text-align : right }
p.centar { text-align : centar }
</style>
… … …
<p class="desno">
A right aligned paragraph
</p>
<p class="centar">
A centered paragraph.
</p>
<p class="levo">
A left aligned paragraph
</p>
Complete code
<html>
<head>
<title>Стилизирање на страна</title>
<style type="text/css">
p.levo { text-align : left }
p.desno { text-align : right }
p.centar { text-align : center }
</style>
</head>
<body>
<p class="desno">
A right aligned paragraph
</p>
<p class="centar">
A centered paragraph.
</p>
<p class="levo">
A left aligned paragraph
</p>
</body>
</html>
Results
A centered paragraph.
A left aligned paragraph.
<style type="text/css">
#levo { text-align : left }
#desno { text-align : right }
#centar { text-align : centar }
</style>
In code:
<html>
<head>
<title>Web page style</title>
<style type="text/css">
#levo { text-align : left }
#desno { text-align : right }
#centar { text-align : center }
</style>
</head>
<body>
<p id="desno">
A right aligned paragraph
</p>
<p id="centar">
A centered paragraph
</p>
<p id="levo">
A left aligned paragraph
</p>
</body>
</html>
Example:
<style type="text/css">
p.levo { text-align : left }
p.desno { text-align : right ; color:blue }
p.centar { text-align : center }
p.crveno { color : red }
</style>
Second paragraph
The result
A right aligned paragraph
A centered paragraph.
<style type="text/css">
.levo { text-align : left }
.desno { text-align : right }
.centar { text-align : center }
.crveno { color : red }
</style>
<html>
<head>
<title>Стилизирање на страна</title>
<style type="text/css">
.polni {font-weight: bold;}
</style>
</head>
<body>
<p class="polni">
A paragraph with bold text
</p>
selector:pseudo-class {property:
value}
Examples
with
a{
color: blue;
}
a:link {
color: blue;
}
a:visited {
color: red;
}
a:hover {
color: orange;
font-style: italic;
}
Important:
a:hover {
letter-spacing : 10px;
font-weight : bold;
color : red;
}
Example
<html>
<head>
<style type="text/css">
a.one:link {color: red}
a.one:visited {color: blue}
a.one:hover {color: green}
* {color: blue; }
All tags will have blue text color
body, h1, h2, h3, h4, h5, h6, p, table, tr, td, th, pre, ul,
li { color: blue ; }
Try
<html>
<head>
<style>
div * { color : red }
</style>
</head>
<body>
<div>
<table>
Normal letters
<p>
Red letters
</p>
</table>
<div>
</body>
</html>
Normal letters
Red letters
blockquote em {color:
red;}
div.main>p {line-
height:1.5;}
1.6.1.1.1 Summary of selectors
Selector Type of selector Description
p+ul {margin-top:0;}
.classname Class selector Matches the value of the class attribute in all
elements or a specified element.
A.classname
p.credits {font-size:
.8em;}
A[att] Simple attribute Matches any element A that has the given
selector attribute defined, whatever its value.
table[border]
{background-color: white;}
A[att="val"] Exact attribute Matches any element B that has the specified
value selector attribute set to the specified value.
table[border="3"]
{background-color: yellow;}
A[att~="val"] Partial attribute Matches any element B that has the specified
value selector value as one of the values in a list given to the
specified attribute.
table[class~="example"]
{background-color: orange;}
1.6.1.1.1 Summary of selectors
Selector Type of selector Description
A[hreflang|="es"] Hyphenated Matches any element A that has an attribute
prefix attribute hreflang with a hyphen-separated list of values
selector beginning (from the left) with "es".
a[hreflang|="es"]
{background-image: url(https://www.scribd.com/flag-%3Cbr/%20%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20es.png);}
a:link Pseudoselector Specifies a style for links that have not yet been
visited.
a:visited Pseudoselector Specifies a style for links that have already been
visited.
p.intro:after {content:
"fini"; color: gray;}
p.intro:before {content:
"start here "; color: gray;}
p:firstchild {text-style:
italic;}
p:first-letter {font-
size: 60px;}
:first-line Pseudoselector Specifies a style for the first line of the specified
element.
p:first-line {color:
fuchsia;}
input[type="text"]:focus
{background-color: yellow;}
a:hover {text-decoration:
underline;}
a:lang(de) {color:
green;}
2 Box model
*{
margin: 0;
padding: 0;
}
With
#myBox {
margin: 10px;
padding: 5px;
width: 70px;
}
You get