Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts...

14
Layout with Styles Castro Chapter 11

Transcript of Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts...

Page 1: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Layout with Styles

Castro Chapter 11

Page 2: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Tables vs. CSS

You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or CSS.

However, CSS styles can be updated in a central location and consequently affect changes across your entire site. This cannot be accomplished with tables.

Additionally, CSS separates formatting & style rules from the content of your page.

Page 3: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Structuring Your Pages

Divide your page into logical sections using the <div> tag(ex: “header”, “main”, “footer”)

Place your content in the order that would be most useful if CSS were not used.

Use header elements (h1, h2,…) consistently throughout your pages.

Page 4: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Structuring Your Pages (2)Window document body div “header” div “main” div “footer”

Page 5: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

The Box Model

Every element has an invisible box around it.

The invisible box has four parts to it:• Content area

• Padding

• Border

• Margin

Page 6: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

The Box Model Examples

W3C Box Model Specifications

ILoveJackDaniels.com (Simplified Model)

HicksDesign 3D Box Model

Page 7: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Positioning With CSSWe can leverage the power of CSS to help us position our

elements in our pages.

4 Ways to Position an Element Box1. Static: leaves the box where it is found in the flow of the

page.2. Absolute: places the box exactly where you want it on the

page with respect to its parent.3. Fixed: place the box in a fixed location in the browser

window.4. Relative: places the box relative to its natural position.

Z-Index: determines the stacking order of overlapping boxes.

Page 8: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Changing Backgrounds

We can change the backgrounds of our boxes. The following CSS rule creates a background image of an avacado that does not repeat and will always appear at the top left corner of the screen. The background color of the page is green.

Page 9: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Setting Box Width / Height

The code below sets the “main” division to a width and height of 90% of a browser’s window. As a user resizes the browser window the “main” division will stretch.

Page 10: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Setting Margins

The code below demonstrates several possible options for setting the margins around a box. Note: the value must be set in clockwise order (top, right, bottom, left).

Page 11: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Setting Padding

The code below demonstrates several possible options for setting the padding around a box. Note: the value must be set in clockwise order (top, right, bottom, left).

Page 12: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Absolute Positioning

Places your box anywhere on a page you choose, with respect to its parent.

Page 13: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Fixed Positioning

Places your box at a fixed location on the page. As a user scrolls through your page, the image does not move from its affixed location. The following code forces content to stay at the top left corner of the browser.

Page 14: Layout with Styles Castro Chapter 11. Tables vs. CSS You can produce “liquid layouts” (layouts that stretch as the browser is resized) using tables or.

Float Positioning

Forces your box to the right or left of your text (and other elements) on your page.