15
CSS Making Layouts with CSS 1

CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

  • Upload
    lydiep

  • View
    215

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

CSSMaking Layouts with CSS

1

Page 2: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

Where does it go?

CSS can be included in

The style attribute of an element

The <head> tag of a HTML document

An external file specified in the <head> tag

➡ This order indicates the dominance scheme

Dominance absolutely applies only in certain cases

2

Page 3: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

Things to know

CSS rules applied by specificity

Selectors are not overridden simply by order

Most specific selector for an element’s property wins

Comments /* */

Not every browser renders content the same

3

Page 4: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

CSSBasic Layout Properties

4

Page 5: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

Layout & HTML

By default, elements are rendered top to bottom, left to right

Elements are divided into two layout categories

inline: width & height determined by contentsex: <a>, <img>, <span>, <strong>

block: height determined by contents; width extends to edge of parent container

ex: <div>, <p>, <table>, <h1>

5

Page 6: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

Layout & HTML

Elements are rendered from L-to-R until a block is encountered

Blocks break flow of inline elements

ex: <br/>

CSS Box Model explains spacing between objects rendered according to this scheme

6

Page 7: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

Layout: The Box Model

Describes how layout properties alter rendering

Well-illustrated in real-time with Firebug

Padding

Element

MarginBorder

7

Page 8: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

How to change attributes

Elementwidth, height

Paddingpadding macro

Borderborder macros

Marginmargin macro

Padding

Element

Margin

Border

8

Page 9: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

How it’s seen

Background color extends to border

Margin is invisiblePadding

Element

Margin

Border

9

Page 10: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

About Macro Properties

Macro properties take multiple values, separated by spaces

border: <border-width> <border-style> <border-color>

ex: border: 1px solid #000000;

Each constituent value corresponds to a property that can be set itself

10

Page 11: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

CSSAdvanced Layout Properties

11

Page 12: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

How?✦ Standard layout model does not provide

capabilities for side-by-side elements

✕ Use tables to layout page-- NO.

✓ Use <div>s with creative CSS to layout page

➡ Maintains semantics of document

! It is recommended that you view this section of the slides interactively:

http://sipb.mit.edu/iap/webdesign/course_materials/lecture_2/floats.html

12

Page 13: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

Using Floats✦ What is it?

✦ Any block element given

✦ float: left; or float: right;

✦ Floats break from the normal layout flow

✦ Rendered to either side of parent

✦ Objects around them flow around it

✦ ex: an inset figure in a paper

13

Page 14: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

Using Floats✦ Floated <div>s can be used to place block

content side-by-side

➡ Enables traditional layout schemes

✦ Elements floated to the same side are rendered in order

✦ To interrupt aligned layout (next “row”), use✦ clear: (left | right | both);

14

Page 15: CSS · CSS can be included in ... 7. How to change attributes Element ... ¬‚oats.html 12

The Problem with Floats✦ Usage is very common & valid, but feature

was not designed for this purpose

➡ Unexpected behavior (padding & margin)

✦ Floats must be given an explicit width

✦ A non-floated element containing only a float has 0 height

➡ Floats (blocks) may also need a height

15