We briefly look at ways of taking the donkey work out of writing HTML & CSS:
content-management systems, HTML templates and CSS frameworks.
Writing HTML for a single web page is nearly painless.
But writing HTML for a web site gets very repetitive:
most pages have the same design, but differ in some of their content.
We can save work by using
static site generation:
creating HTML files from templates.
We'll investigate this using Jinja2 templates — because they're the same ones we'll use in Flask later.
staticJinja is a program that converts templates into regular HTML web pages.
Each page has the same header and footer; only their main differs.
Let's say this is stored in base.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</header>
{% block main %}{% endblock %}
<footer>
<p>
<small>
© Derek Bridge
</small>
</p>
</footer>
</body>
</html>
{% extends 'base.html' %}
{% block title %}
Home
{% endblock %}
{% block main %}
<main>
<h1>Welcome!</h1>
<p>
This is the home
page.
</p>
</main>
{% endblock %}
{% extends 'base.html' %}
{% block title %}
About
{% endblock %}
{% block main %}
<main>
<h1>About us!</h1>
<p>
This is about who
we are.
</p>
</main>
{% endblock %}
{% extends 'base.html' %}
{% block title %}
Contact
{% endblock %}
{% block main %}
<main>
<h1>Contact us!</h1>
<p>
This is the how
to contact us.
</p>
</main>
{% endblock %}
The browser does not fetch templates and then combine them.
The server does not take templates and combine them.
staticjinja is a quite separate program.
It combines templates.
Then its output (web pages) can be placed on the server.
Browsers and servers work as normal.
They know nothing about templates.
Writing CSS to create a visually appealing web site is difficult.
Writing CSS for a visually appealing, responsive web site is even more difficult.
Making sure that the web site is also accessible is even more difficult.
Prewritten CSS for multi-column sites,
usually liquid, sometimes RWD.
E.g. Bootstrap
Mobile-first and RWD.
Up to 12 equal-sized columns, but you can combine them.
You may need to put some extra divs into your HTML.
You will need to put class attributes onto the elements in your HTML.
You can customize the colours and so on.
Other CSS frameworks: Pico, Tailwind, …
One way to use Bootstrap:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Welcome!</title>
<link href="
</head>
<body>
<-- Your stuff goes here -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js" integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous" />
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Welcome!</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous" />
</head>
<body>
<header>
Header
</header>
<div class="row" role="presentation">
<nav class="col-sm-4">
Nav
</nav>
<main class="col-sm-8">
Main
</main>
</div>
<footer>
Footer
</footer>
</body>
</html>
divs and class attributes (class-itis!) for presentational
purposes;Our study of Web Development in the case of static web sites ends here.
We have only scratched the surface!
But, we will resume with a study of Web Development in the case of dynamic web sites.