Web Design and Programming-Chap 3
Web Design and Programming-Chap 3
Style Sheets
• O b j e c t i v e s:
• In this chapter you’ll learn:
• Control a website’s appearance with style sheets.
• Use a style sheet to give all the pages of a website the same look and
feel.
• Use the class attribute to apply styles.
• Specify the precise font, size, color and other properties of displayed text.
• Specify element backgrounds and colors.
• Understand the box model and how to control margins,borders and
padding.
• Use style sheets to separate presentation from content.
Introduction to Cascading
Style Sheets
• Outline:
• Introduction • Backgrounds
• Inline Styles • Element Dimensions
• Embedded Style Sheets • Box Model and Text Flow
• Conflicting Styles • Media Types and Media Queries
• Linking External Style Sheets • Drop-Down Menus
• Positioning Elements: Absolute
Positioning, z-index
• Positioning Elements: Relative
Positioning, span
Introduction
• In this chapter, we shift our focus to formatting and presenting information.
• To do this, we use a W3C technology called Cascading Style Sheets 3 (CSS3) that allows
you to specify the presentation of elements on a web page (e.g., fonts, spacing, sizes,
colors, positioning) separately from the document’s structure and content (section
headers, body text, links, etc.).
• This separation of structure from presentation simplifies maintaining and modifying
web pages, especially on large-scale websites.
• Though HTML5 has some attributes that control presentation, it’s better not to mix
presentation with content.
• If a website’s presentation is determined entirely by a style sheet, you can simply
swap in a new style sheet to completely change the site’s appearance.
Inline Styles
• You can declare document styles
• inline in the HTML5 markup,
• in embedded style sheets or
• in separate CSS files.
• This section presents inline styles that
declare an individual element’s format
using the HTML5 attribute style.
• Inline styles override any other styles
applied using the techniques we discuss
later in the chapter.
• Figure 4.1 applies inline styles to p
elements to alter their font size and color.
Fig. 4.1 | Using inline styles.
Inline Styles
• Software Engineering Observation 4.1:
• Inline styles do not truly separate
presentation from content.
• To apply similar styles to multiple
elements, use
• embedded style sheets or
• external style sheets