Download presentation
Presentation is loading. Please wait.
Published byEvelyn Black Modified over 6 years ago
1
Cao Yuewen ywcao@se.cuhk.edu.hk 2017.10.12
SEEM4570 Tutorial 03: CSS Cao Yuewen
2
What is CSS ? CSS stands for Cascading Style Sheets
CSS describes how HTML elements are to be displayed
3
Why CSS ? Separates content from form
Easy maintenance of multiple pages Faster page loading Easy to learn
4
Three Ways to Insert CSS
Inline: the “style” attribute Internal: the <style> markup tag External: the .css stylesheet file <p style=“font-color:red;font-size:10px;”>Content</p> <html><head><style> p {background-color: Red;font-family: serif;font-color: White; } </style></head><body> <p>Content</p> </body></html> <link rel="stylesheet" type="text/css" href=“mystylesheet.css" />
5
CSS Rule Structure CSS rule-set consists of a selector and a declaration block: The selector points to the HTML element you want to style The declaration block contains one or more declarations Each declaration includes a CSS property name and a value Each declaration separates with a semi-colon
6
ID in CSS Specify a style for a unique element by referring to the “id” in the HTML element. The style is defined by “#” in CSS <head> <style> #para1{ color:red; } </style> </head> <body> <p id="para1">A style paragraph</p> <p id="para1">Another style paragraph</p> </body>
7
Class in CSS Specify a style for a unique of elements by referring to the “class” in the HTML element. The style is defined by “.” in CSS <head> <style> .para1{ color:red; } </style> </head> <body> <p class="para1">A style paragraph</p> <p class="para1">Another style paragraph</p> </body>
8
Class in CSS You can also specify the specific HTML elements should be affected by a class. <head> <style> div.para1{ color:red; } </style> </head> <body> <p class="para1">No effect</p> <div class="para1">Affected</p> </body>
9
Some Useful Elements - Table
Table <table> <th> head <tr>table row <td>table data Table border Table width and height Table color Alignment Table Padding Horizontal Dividers Hoverable Table Apply style to a specific table …
10
Some Useful Elements - Table
11
Some Useful Elements - Layer
We use <div> to represent it. You need to understand the layout first:
12
Some Useful Elements - Position
Position properties allow you to position an element. It can also specify what should happen if an element’s content is too big or which element overlaps with one another. There are four different position value: Static(default) Relative Fixed Absolute
13
Some Useful Elements - Position
Position: relative A relative positioned element is positioned relative to its normal position. Example: div.relative{ position: relative; left: 30px; border: 3px; }
14
Some Useful Elements - Position
Position: fixed A fixed positioned element is positioned relative to the browser window. Example: div.fixed{ position: fixed; bottom: 0; right: 0; width: 300px; border:3px; }
15
Some Useful Elements - Position
Position: absolute An absolute positioned element is positioned relative to the nearest positioned ancestor. If no such ancestor is found, it uses the document body, and move along with page scrolling. Example: div.relative { position: relative; width: 400px; height: 200px; border: 3px; } div.absolute { position: absolute; bottom: 0; right: 0; width: 200px; height: 100px; border: 3px; } <div class="relative">This div element has position: relative; <div class="absolute">This div element has position: absolute;</div> </div>
16
Some Useful Elements - Position
Position: overlapping Elements can overlap other elements if needed. The z-index property specifies the stack order of an element. Example: img { position: absolute; left: 0px; top: 0px; z-index: -1; }
17
Some Useful Elements - Position
18
Some Useful Elements - Display
Display property specifies how an element is displayed. Commonly used values: div { display: inline; /* Default of all elements*/ display: inline-block; /* Characteristics of block, but sits on a line */ display: block; /* Display block-level element */ display: run-in; /* Not particularly well supported */ display: none; /* Hide */ }
19
Some Useful Elements - Display
Inline Don’t start on a new line and only take up as much width as necessary. It sits right inline with the natural flow of the text. e.g. <span>、<em> 、<b>、<a> Inline Block Similar to inline element but is able to set a width and height Block Don’t sit inline but break past them. Take up as much horizontal space as they can. e.g. <div>、<section>、<ul>、<h1> Run-in Make a header element to sit inline with the text below it. Don’t work in Firefox
20
Some Useful Elements - Display
21
Some Useful Elements - Display
Table Values Force non-table elements to behave like table-elements Browser Support: IE8 supports the "table-" values only if a !DOCTYPE is specified. div { display: table; /* like a <table> element*/ display: table-cell; /* like a <td> element*/ display: table-column; /* like a <col> element*/ display: table-column-group; /* like a <colgroup> element*/ display: table-header-group; /* like a <thead> element */ display: table-row-group; /* like a <tbody> element*/ display: table-footer-group; /* like a <tfoot> element*/ display: table-row; /*like a <tr> element */ display: table-caption; /* like a <caption> element*/ }
22
Some Useful Elements - Display
23
Some Useful Elements - Display
Put together a multi-column layout
24
Resources http://www.w3schools.com/css/
25
Question Time
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.