Understanding CSS Box Model and Style Priorities

Slide Note
Embed
Share

Dive into the world of CSS with topics covering box model concepts, quick tips for CSS styling, and the significance of CSS style priorities. Explore techniques for centering elements, setting priorities, and handling different style rules to create effective web designs. Learn about inline styles, embedded CSS rules, separate stylesheets, and browser-default styles to enhance your understanding of CSS styling techniques.


Uploaded on Oct 04, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. CSS and Box Model

  2. Topics Quick Tips and CSS style priorities Divisions The Design Process Box sizing Practice - MockUp Implementation

  3. CSS Tips To center an element, other than text, use the margin attributes. image { margin-left: auto; margin-left: auto; } Float can be used for alignment, but it is unpredictable because it is highly responsive to the size of a screen. image { float:right; } Use clear to ensure that nothing else appears to the left/right of an element. table { clear: both; margin-left: 100px; width: 150px; }

  4. CSS Style Priorities It matters where you define the rules and in what order they are applied. Styles can be defined in different places. A higher-priority rule will overwrite a previous definition.

  5. Priority Rule 1: Inline Style Rule Example: <li> <a href= "http://www.Redlands.edu" style="color: #90a184;" title="About Us">About Us </a> </li> NOTE: This style should usually be avoided.

  6. Priority Rule 2: Style Rule Embedded in HTML Example: <head> <title>A Simple Webpage</title> <style> table, th, td { border: 1px solid black; } </style> </head> NOTE: Use only for very small projects.

  7. Priority Rule 3: Stylesheet in a separate CSS file IDEAL

  8. Priority Rule 4: Style Used by a Browser Different browsers have slightly different styles. Browsers use default stylesheets to determine how to display HTML elements. Because these rules differ sometimes between browsers, there are efforts to promote consistency in styles across browsers.

  9. Final Statement on Priority Rules If an object has multiple, overlapping CSS rules defined for it, the one with the higher priority will take effect.

  10. Divisions in a Design A webpage is a collection of objects. When designing, objects should be placed in divisions. div represents a division class. div is used to divide a page into objects, box model elements. Goal: Position elements so that they can be easily rearranged if we decide to give users a different experience.

  11. Carve a webpage mockup into box elements

  12. Every object on a web page is modeled as a box

  13. Box Model size width + padding + border = actual visible/rendered width of an element's box height + padding + border = actual visible/rendered height of an element's box

  14. Box Sizing The box-sizing property can make CSS layouts more intuitive. The box-sizing property has a common value called border-box. Every current browser supports box-sizing: border-box; If you need to support older versions of Safari (< 5.1), Chrome (< 10), and Firefox (< 29), you should include the prefixes -webkit and -moz: * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }

  15. Lab 4 Exercise 1 How is this webpage carved up?

More Related Content