Lecture2   CSS 3
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
646
On Slideshare
646
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
8
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • Show google.comcode before and after (in Google directory). Show: Why tables for layout is stupid: http://www.hotdesign.com/seybold/
  • Show 112 index.html without style sheet.
  • Show lab three example Show examples: Nofloat.html - normal flow of document Basicfloat.html - nav ul floated and a border added so area can be seen. Float.html - bells and whistles.
  • Show float.html again and discuss use of clear for footer.
  • Show Position> relative.html
  • Show Position> absolute.html
  • Show fixed.html and Women in CS site.
  • Show fixed.html and Women in CS site (http://www.cs.otago.ac.nz/staffpriv/morag/femmeweb/).
  • Show sites with layout examples.

Transcript

  • 1. Lecture 2 : CSS III SFDV2001 Web Development
  • 2. Page layout with CSS
    • Tables, though still heavily used by web designers to control page layout, were never intended for that purpose.
    • Ideally tables should be used for data only.
    • As browsers become better at supporting web standards and as users of the web adopt those browsers, layout controlled entirely by CSS is becoming an increasingly realistic option.
    • Even when table layout is still necessary, CSS streamlines their use, and makes your code much cleaner.
  • 3. Standard document flow
    • When no layout control is implemented for an HTML page, elements flow from top to bottom, left to right:
      • Block-level elements produce a line break that sees subsequent block-level elements come beneath them.
      • Inline elements come one after the other, left to right, in the order they appear.
      • The order sequence is determined by the tag sequence in your HTML.
    • When you expand or contract the browser window, block-level elements alter to fit the new width.
  • 4. Standard document flow
    • When you position elements with CSS you can remove an element from the normal flow.
    • Order your HTML sensibly so that someone accessing it without style information can make sense of it:
        • Title
        • Navigation
        • Main content
        • Footer
    • That order won’t affect what you can achieve with CSS with regard to layout.
  • 5. Float
    • In Transitional HTML we could align an image to the right and have text wrap around it on the left using the align attribute.
    • In CSS such behaviour is not limited to images. You can float any element.
    • ul#nav{
    • float: left;
    • }
  • 6. Clear
    • Just as we had the clear attribute of <br> in transitional HTML to stop text from sitting beside an aligned image when we didn’t want it to, so we have clear to accompany float in CSS.
    • The clear attribute of <br> had the possible values: left , right or all .
    • In CSS clear gets: left , right , both , none or inherit .
    • The clear property can only be applied to block-level elements.
  • 7. Position
    • There are a number of different values of position in CSS:
        • Static
        • Relative
        • Absolute
        • Fixed
    • Static is the normal (default) position of elements on your page. Elements conform to the standard document flow.
    • Position (and any of its values) can apply to any element.
  • 8. Position
    • Once you have determined what kind of positioning an element will employ (relative, absolute or fixed), the actual positioning is done via four properties:
        • Top
        • Right
        • Bottom
        • Left
    • The values of these properties can be a length or a percentage.
    • Top position refers to an elements distance from the top (the top of what depends on what kind of positioning you are employing).
  • 9. position: relative;
    • Relative positioning moves an element from its place in the standard document flow but retains the space where it came from:
    • position: relative;
    • top: 40px;
    • left: 40px;
    40 40
  • 10. position: absolute;
    • Absolute positioning moves an element from its place in the standard document flow and closes the space where it came from.
    • An element is positioned absolutely with relation to its nearest parent element that isn’t statically positioned.
    • position: absolute;
    • top: 40px;
    • left: 40px;
    40 40
  • 11. position: fixed;
    • Like absolute positioning, fixed positioning removes an element from the standard document flow, but instead of being fixed relative to its parent element it is fixed in relation to the view-port (normally the browser window).
    • Can be useful to recreate frame like behaviour where a navigation menu can stay fixed while the rest of the content scrolls.
    • Not as well supported as relative and absolute positioning.
  • 12. Position Combinations
    • Relative and absolutely positioned elements in particular can be combined to give your layout greater flexibility.
    • An absolutely positioned element inside a relative element is positioned absolutely with respect to that relatively positioned parent. So the parent may be flexible but the child always stays in the same place in relation to it.
    • Time for an example I think.
  • 13. CSS and tables
    • Please don’t get the message “tables are evil”.
    • Tables should absolutely be used for tabular data:
  • 14. CSS and tables
    • And they are still necessary for some layout purposes. Complex forms are still easier to control with a table than CSS (and in many instances the form information fits the tabular data description).
    • When you have to use a table for layout control keep it as clean as possible; use your CSS to style it.
    • Things like empty cells, though there were never very many good excuses for them, should be rare with CSS.
    • Combining CSS and tables for layout can be more of a headache than using CSS alone, so don’t think you’re taking the easy route.
  • 15. Learn by example
    • And by practice. Lots and lots of practice.
    • You could sit in a thousand lectures, read a thousand articles and still not really “get” CSS.
    • You absolutely must practice it: work out how things do what they do through experiment.
    • There is no learning experience like encountering a problem, getting incredibly frustrated and then feeling elated when you find a solution.
    • You will not come out of this course an expert in CSS.
  • 16. Recommended sites: Why Tables for Layout is Stupid: http:// www.hotdesign.com/seybold / A List Apart: Practical CSS Layout Tips, Ticks & techniques: http:// www.alistapart.com/articles/practicalcss / Max Design Floatutorial: http:// css.maxdesign.com.au/floatutorial / Further reading: Web Design in a Nutshell, 3rd Edition by Jennifer Niederst Robbins
  • 17.