|
Unit 11.1B · Web Development
CSS in Web DesignFrom HTML structure to professional web design
HTML creates the structure of a web page. CSS controls how that structure is presented to the user. In this lesson, you will compare different ways of implementing CSS and apply CSS when designing a website. 11.5.3.5
Compare CSS implementing types 11.5.3.6
Use CSS when designing a website Success criteriaBy the end of the lesson, I can:
Why CSS? CSS Rule 3 Methods Compare Selectors Cascade Box Model Web Design Quiz Debug Practice Vocabulary
1. Why do we need CSS?Imagine two web pages with the same information. One uses only basic HTML. The other uses CSS. Which page would be easier and more pleasant to use? HTML only →
HTML + CSS Coding Club
Learn. Create. Share.
Develop websites and programming projects with other students. CSS stands for Cascading Style Sheets.
CSS controls the visual presentation of HTML documents. HTML and CSS work together
HTML Structure headings, paragraphs, images, links
+
CSS Presentation colour, size, spacing, layout
→
Browser Web page visual result seen by the user
2. Anatomy of a CSS ruleA CSS rule tells the browser what to select and how to style it. h1 { color : navy ; }
Selector
Which HTML element? Property
What feature? Value
What setting? h1 { color: navy; font-size: 32px; text-align: center; }
Read the rule as:
“Select every <h1> element and make its text navy, 32 pixels high and centred.” Try to interpret this rulep { color: #455a64; font-size: 18px; line-height: 1.6; }
Show explanationThe selector p targets paragraphs.
Their text becomes dark grey, the font size becomes 18 px, and the line spacing becomes 1.6. 3. Three ways to implement CSSCSS can be added to a web page in three main ways. 1
Inline CSSCSS is written directly inside an HTML element using the style attribute. ONE ELEMENT2
Internal CSSCSS rules are placed inside a <style> element in the HTML document. ONE PAGE3
External CSSCSS rules are stored in a separate .css file. MANY PAGESInteractive CSS Method ExplorerChoose a CSS implementation method. Inline CSS<h1 style="color:blue;">Welcome</h1>
Scope: one HTML element.
Useful for a small exceptional change, but difficult to maintain when repeated. Internal CSS<head> <style> h1 { color: blue; } p { font-size: 18px; } </style> </head>
Scope: one HTML page.
Suitable for a single-page website, demonstration or prototype. External CSSHTML: <link rel="stylesheet" href="styles.css">
styles.css: h1 { color: blue; } p { font-size: 18px; }
Scope: many web pages.
This usually provides better maintainability for a multi-page website. How external CSS connects pages
index.html Home page
→
styles.css Shared styles
←
contact.html Contact page
One external stylesheet can be linked to many HTML pages.
Change the stylesheet once and the appearance of all linked pages can change. 4. Compare CSS implementation methods
Important:
The appropriate CSS implementation method depends on the design problem. For a multi-page website with a consistent design, external CSS normally provides better reuse, consistency and maintainability. Which CSS method would you choose?1. A website contains 25 pages that should all use the same colours and typography.
✓ Correct. One external stylesheet can provide consistent styles across many pages.
✗ Think about reuse and maintenance across many pages.
2. You are creating a one-page prototype and want all CSS inside the same HTML file.
✓ Correct. Internal CSS can be suitable for a single-page prototype.
✗ The CSS should remain inside the HTML document.
3. One specific heading requires a temporary, exceptional colour.
✓ Correct. Inline CSS can be used for a specific one-element exception.
✗ Consider the scope: only one element needs the change.
5. CSS SelectorsA selector determines which HTML elements will receive a CSS rule. p
Element selectorSelects all elements of a particular type. p { color: navy; }
.card
Class selectorSelects elements sharing the same class. .card { padding: 20px; }
#header
ID selectorSelects an element with a specific ID. #header { color: white; }
Class exampleCSS
.important { color: red; font-weight: bold; }
HTML
<p class="important"> Exam deadline </p> <p class="important"> Submit your project </p>
A class can be reused on several elements.
An ID should identify a unique element within the page. 6. Why is it called “Cascading” Style Sheets?More than one CSS rule may affect the same element. The browser must decide which declaration applies. 1
Matching rules
Which rules target this element? 2
Specificity
Some selectors are more specific. 3
Order
Later rules may override earlier rules. Predict the resultp { color: blue; } .warning { color: red; }
<p class="warning"> Important message </p>
Show answerImportant message The class selector .warning is more specific than the element selector p.7. The CSS Box ModelEvery visible HTML element can be considered as a rectangular box. MARGIN
BORDER
PADDING
CONTENT
ContentText, images or other content inside the element. PaddingSpace between content and border. BorderA line surrounding the padding and content. MarginSpace outside the border. Use HTML and CSS editorExample.card { width: 300px; padding: 20px; border: 1px solid #cccccc; margin: 20px; }
8. Using CSS when designing a websiteGood CSS helps create visual hierarchy, consistency and readability. TypographyFont family, size, weight and line spacing. ColourText, background, borders and contrast. SpacingMargin and padding improve readability. LayoutOrganise content into logical sections. ConsistencyReuse styles for related components. ReadabilityUsers should easily identify content and actions. Example: styling a cardHTML
<div class="course-card"> <h3>Web Development</h3> <p> Learn HTML and CSS. </p> <a href="#"> Start course </a> </div>
CSS
.course-card { max-width: 400px; padding: 20px; background: white; border: 1px solid #dddddd; border-radius: 10px; margin: 20px auto; }
9. Check your understandingWhich selector targets every element with class="card"?
✓ Correct. A class selector begins with a dot.
✗ Remember the symbol used for a CSS class.
Answer these questions:
Check key ideas1. Inline CSS is placed on an element, internal CSS is placed inside the HTML document, and external CSS is stored in a separate file. 2. One stylesheet can be reused across many pages. 3. Selector, property and value. 4. A class can be reused; an ID identifies a unique element. 5. Padding is inside the border; margin is outside the border. 10. Debug the CSSA student wants all elements with class="warning" to have red text. HTML
<p class="warning"> Password is too short. </p>
CSS
#warning { colour: red; font-size = 18px; }
Find three errors.
Show corrected CSS.warning { color: red; font-size: 18px; }
The HTML uses a class, so the selector requires .. CSS uses color. CSS uses : between a property and value. 11. Practical ChallengeSchool Coding Club WebsiteTransform a basic HTML page into a clear, consistent and attractive website using CSS. Starter HTML<!DOCTYPE html> <html> <head> <title>School Coding Club</title> </head> <body> <header> <h1>School Coding Club</h1> <p>Learn. Create. Share.</p> </header> <main> <section class="card"> <h2>Web Development</h2> <p> Learn HTML and CSS. </p> </section> <section class="card"> <h2>Programming</h2> <p> Develop Python projects. </p> </section> </main> </body> </html>
Your CSS must demonstrate:
Decision point — LO 11.5.3.5
Choose inline, internal or external CSS. Write one sentence explaining why your choice is appropriate. Extension challenge
Show one possible CSS solutionbody { margin: 0; font-family: Arial, sans-serif; background-color: #f4f7f6; color: #263238; } header { padding: 35px 20px; background-color: #286d60; color: white; text-align: center; } main { max-width: 900px; margin: 30px auto; padding: 0 20px; } .card { margin-bottom: 20px; padding: 20px; background-color: white; border: 1px solid #d5e4e0; border-radius: 10px; } .card h2 { color: #286d60; }
12. Design ReviewExchange your website with a partner. Review the design. Visual hierarchyConsistencyReadabilityCSS qualityVocabulary · English–Russian
Questions:
Check answers1. Inline, internal and external CSS. 2. External CSS is usually appropriate because one stylesheet can be reused across many pages. 3. Selector, property and value. 4. .card selects a class; #card selects an ID. 5. Padding is inside the border. Margin is outside the border. 6. h2 { color: green; font-size: 24px; }
Exercises:Ex. 1 CSS Practical Exercise for a School Club Website (Rus)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Просмотров: 868 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Всего комментариев: 0 | |