Hong Kong Baptist University · FACULTY OF COMPUTER SCIENCE

AIDM7450 Chap.1 HTML Structure and CSS Foundations

- one subject, every graph, every model, every mark
6 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 1 of 7 · AIDM7450

HTML Structure and CSS Foundations

Three responsibilities in one page

HTML supplies structure and meaning, CSS supplies presentation, and JavaScript later supplies behaviour. This chapter builds the document tree from head and body, headings, paragraphs, links and grouping elements before it introduces CSS rules.

It then compares inline, embedded and external styles by scope and maintenance cost, and treats type, class and ID selectors as promises about how broadly a rule may be reused. The debugging method is to classify a defect as structure, selector, declaration or path before changing code.

A local link, in-page anchor and remote URL may all use the same element while depending on different address rules.

Likewise, two CSS declarations may look similar while reaching one element, one document or an entire site. The chapter therefore asks two questions before syntax: what responsibility owns the result, and how widely should the decision apply? Those questions prevent a visual override from hiding broken structure.

In this chapter

What this chapter covers

  • 01

    HTML document structure and visible content

  • 02

    Block and inline grouping with div and span

  • 03

    Remote, local, relative and in-page links

  • 04

    CSS selectors and property-value declarations

  • 05

    Inline, embedded and external stylesheet scope

  • 06

    Type, class and unique ID selection

Worked example · free

Refactor duplicated magazine styles

Q [8 marks]. AskSia-authored practice. Three pages repeat the same inline heading rules and reuse one ID on several captions. Repair the structure without changing the visible result. The marks shown are an AskSia study allocation.
The three web layers answer different questions.The three web layers answer different questions. The nested boxes show structure supporting presentation and behaviour without collapsing their responsibilities. One page, three responsibilities HTML: structure and meaning CSS: appearance and layout JavaScript: behaviour A clean page changes one layer without forcing a rewrite of the other two.
The three web layers answer different questions. The nested boxes show structure supporting presentation and behaviour without collapsing their responsibilities.
  • 3Move shared declarations to one linked external stylesheet.
  • 3Replace repeated IDs with a reusable caption class.
  • 2Keep one explicit class for the genuine exception.
The marks shown here divide a revision task and are not a published university marking scheme. Link every page to one external stylesheet and move shared heading and paragraph rules there. Give the repeated captions one class because they share a reusable role, and remove duplicated IDs because an ID promises uniqueness. Add a second descriptive class to the exceptional caption. HTML now holds the content roles while CSS holds the shared presentation and narrow exception.
Sia tip — Choose selector scope from reuse before choosing specificity. A stronger selector can hide a structural mistake without fixing it.
Glossary

Key terms

HTML Element
A structured unit of markup represented by a tag, content and any attributes.
Block Element
An element that participates as a block in document flow and normally begins a new line.
Inline Element
An element that groups content within an existing line without creating a new block.
CSS Selector
The part of a CSS rule that identifies which elements receive its declarations.
External Stylesheet
A separate CSS file linked by documents so shared presentation has one source.
FAQ

HTML Structure and CSS Foundations FAQ

How do I decide whether a defect belongs to HTML or CSS?

Remove appearance from the diagnosis. If the content, hierarchy or destination is absent or wrong, repair HTML. If the right element exists and performs the right role but looks wrong, inspect CSS. A click-dependent change belongs to the behaviour layer instead.

When should I use a class instead of an ID?

Use a class for a category that several elements may share and an ID for one unique role in the document. Repeating an ID creates ambiguous lookups and links. Creating a unique class for every element removes the reuse classes are meant to express.

Why prefer an external stylesheet for shared design?

An external stylesheet gives several pages one source for colour, spacing and layout. A site-wide change is then made once. Inline and embedded rules remain useful for genuine exceptions or document-specific design, but copying them across pages creates avoidable maintenance work.

Study strategy

Exam move

Build one page in two passes. First write only semantic structure and test every link. Then add an external stylesheet, beginning with broad reusable rules and ending with narrow exceptions. For each unexpected result, write whether the fault is structure, path, selector or declaration before editing. This forces the three web responsibilities to remain visible.

Make a small link matrix containing one remote address, one sibling file, one child path and one in-page destination; predict the resolved target before selecting each link. Next inspect a single heading and list every rule that reaches it, including the browser default, external sheet, embedded block and inline style if present. Remove rules from narrowest to broadest and explain each change in the computed result.

Finish by refactoring a repeated inline declaration into a class, then into an external rule shared by two pages. Check that unique roles retain unique IDs and repeated categories use classes. A useful final test is to read the document with styles disabled: headings should still communicate hierarchy, destinations should still work, and image descriptions should still carry meaning.

Restore CSS and verify that no new selector was added merely to overpower an avoidable conflict. Keep a repair log with the observed symptom, owning layer, smallest change and retest result; this makes accidental overrides visible and turns debugging into a repeatable method.

Working through HTML Structure and CSS Foundations in AIDM7450? Sia is AskSia’s AI Computer Science tutor — ask any AIDM7450 HTML Structure and CSS Foundations question and get a clear, step-by-step explanation grounded in how AIDM7450 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 16 of your subjects at Hong Kong Baptist University, plus 1,000+ more Bibles across the AskSia library.
Sia - your AIDM7450 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works