2. Import style sheet
• In style sheet, we can import other style
sheet by use
• @import “style.css”;
3. CSS Selectors
Use CSS Selectors to define properties for the
structure and presentation of your site.
This is the key to defining specific properties for
specific parts of your design.
Tag, Class, ID, Compound
4. CSS Selectors
Tag: properties defined for an HTML tag.
Class: properties defined for an HTML tag
using a class or a <span> tag.
ID: properties defined for an element or div
using an id.
Compound: properties defined using multiple
selector types.
6. CSS Selectors
Tag*: properties defined for an HTML tag.
(*Also referred to as Type, Element)
body {margin: 10px 0;}
7. CSS Selectors
Tag
body {margin: 10px 0;}
<body>
Everything within the body will start out
with this property.
</body>
8. CSS Selectors
Class: properties defined for an HTML tag
using a class or a <span> tag.
.red {margin: 15px; color: red;}
9. CSS Selectors
Class
.red {margin: 15px; color: red;}
<p class=”red”>This is a paragraph of text
in red.</p>
These are <span class=”red”>words in
red.</span>
10. CSS Selectors
ID: properties defined for an element or div
using an id.
#wrapper {margin :0 auto;}
11. CSS Selectors
ID
#wrapper {margin :0 auto;}
<div id=”wrapper”></div>
12. CSS Selectors
Compound: properties defined using multiple
selector types.
#content p {margin :0;}
13. CSS Selectors
Compound
#content p {margin :0;}
<div id=”content”>
<p>This is a paragraph of text in the
content div.</p>
</div>
14. CSS Box Model
How do you position content?
You position content in your page by
using a combination of margins, padding
and floats.
But, in order to get your positioning and
layout correct, you must know how the
CSS Box Model works.
18. CSS Box Model
total box width =
content area width +
left padding + right padding +
left border + right border +
left margin + right margin
19. CSS Box Model
What is the total box width?
#content {width:
200px;border: 1px solid
#900;padding: 10px;margin:
0;background: #fee;}
20. CSS Box Model
If the total box width is 400px, what is the width
of the content area?
#content {width:
???px;border: 1px solid
#000;padding: 20px;margin:
10;}
21. Pseudo-Selectors
• •General Purpose Pseudo-Selector:
• –:hover Element with mouse over
• Specific to hyperlinks (and/or buttons)
• –a:active A link or button that is currently
being clicked on.
• –a:link A link that has NOT been visited yet.
• –a:visited A link that HAS been visited.
22. Background Image Properties
• background-image:
url(../location/of/image.jpg)
• •background-repeat:tile image in
background
• •background-position:vertical(top, center,
bottom, or size) horizontal(left, center, right,
or size)
• •background-attachment: (scrollor fixed)
23. Text Properties
• text-indent:indents first line of a paragraph
according to size
• text-align:right;or left;or center;or justify;
• text-decoration: none; orunderline;
• text-transform:Capitalize;
• Line-height:added vertical space to each
line of text according to size
24. Text shadows
• h3 {text-shadow: 1px 1px 2px #00}
• x (horizontal) offset casts shadow to the right
of the text. Negative cast to the left.
• y (vertical) offset casts shadow below the
text. Negative value casts above
• Blue radius: blurs the shadow, with higher
values making the shadow wider or lighter.
• Color: make color for shadow text
25. Attribute selector
- CSS [attribute]: use to select element with specified
attribute
Ex. a[target] {color: red}
- CSS [attribute=value]: use to select element with
specified attribute and value
Ex. Input[type=“submit”] {color: #fff}
26. Attribute selector(con)
- CSS [attribute~=value]: use to select element with
an attribute with containing a specified word
- Ex. [title~=“shop”] {color: #000}
- CSS [attribute|=value]: select elements with the
specified attribute starting with the specified value.
- Ex. [class|=“top”] {background: blue}
27. Attribute selector(con)
- CSS [attribute^=value]: used to select elements
whose attribute value begins with a specified
value
Ex. [class^=“top”] {background: blue}
- CSS [attribute$=value]: used to select elements
whose attribute value ends with a specified value.
Ex. [class$=“top”] {background: blue}
32. Position relative
• element is positioned relative to its normal
position.
• Ex. Box2 {
position: relative;
left: -10px;
}
33. Position absolute
• An absolute position element is positioned
relative to the first parent element that has a
position other than static.
• Ex. Box2 {
position: absolute;
left: 10px;
top: 20px;
}
34. Z-index
• property specifies the stack order of an
element (which element should be placed in
front of, or behind, the others).
• Ex. .box2 {
z-index: 1;
Position: absolute;
}
Hinweis der Redaktion
|
Note: The value has to be a whole word, either alone, like class="top", or followed by a hyphen( - ), like class="top-text"!
<h1 class="top-header">Welcome</h1>
<p class="top-text">Hello world!</p>
<p class="topcontent">Are you learning CSS?</p>