James Williams
Birmingham Newman University
jwilliams@staff.newman.ac.uk
3-hour session
h1 {
color: blue;
font-size: 24px;
text-align: center;
}
See Moodle for supporting materials.
Quick introduction to CSS - the styling language for web pages
selector {
property: value;
property: value;
}
/* Element selector */
h1 { color: red; }
/* Class selector */
.highlight { background: yellow; }
/* ID selector */
#header { font-size: 20px; }
/* Descendant selector */
div p { margin: 10px; }
/* Specificity: 0,0,0,1 */
p { color: black; }
/* Specificity: 0,0,1,0 */
.text { color: blue; }
/* Specificity: 0,1,0,0 */
#content { color: red; }
/* Specificity: 0,0,0,0 */
* { color: green; }
!important sparingly<!-- Method 1: External CSS -->
<link rel="stylesheet" href="styles.css">
<!-- Method 2: Internal CSS -->
<style>
h1 { color: blue; }
</style>
<!-- Method 3: Inline CSS -->
<h1 style="color: blue;">Title</h1>
h1 {
color: #333333;
font-family: Arial, sans-serif;
font-size: 24px;
font-weight: bold;
text-align: center;
text-decoration: underline;
line-height: 1.5;
}
/* Named colors */
color: red;
/* Hexadecimal */
color: #ff0000;
color: #f00;
/* RGB */
color: rgb(255, 0, 0);
/* RGBA (with transparency) */
color: rgba(255, 0, 0, 0.5);
.box {
background-color: #f0f0f0;
background-image: url('image.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.box {
width: 200px;
height: 100px;
padding: 20px;
border: 2px solid black;
margin: 10px;
}
.border-demo {
border-width: 3px;
border-style: solid;
border-color: #007bff;
border-radius: 10px;
}
/* Block elements */
.block { display: block; }
/* Inline elements */
.inline { display: inline; }
/* Inline-block elements */
.inline-block { display: inline-block; }
/* Hidden elements */
.hidden { display: none; }
/* Static (default) */
.static { position: static; }
/* Relative */
.relative { position: relative; top: 10px; left: 20px; }
/* Absolute */
.absolute { position: absolute; top: 0; right: 0; }
/* Fixed */
.fixed { position: fixed; bottom: 20px; right: 20px; }
/* Absolute units */
font-size: 16px;
width: 2in;
height: 3cm;
/* Relative units */
font-size: 1.5em;
width: 50%;
height: 100vh;
margin: 1rem;
/* This is a CSS comment */
/* Header styles */
header {
background: #333;
color: white;
}
/* TODO: Add responsive styles */
/* @media (max-width: 768px) { ... } */
/* */ for commentsstyled-page.htmlTime: 45 minutes
This task will help you understand basic CSS syntax and styling
Take a break, ask questions, or catch up on the previous task.
Next: Secondary slides and Task 2
body {
font-family: Arial, sans-serif;
color: #333;
line-height: 1.5;
}
/* All child elements inherit these properties */
inherit to force inheritance/* Rule 1: User agent (browser default) */
/* Rule 2: User styles */
/* Rule 3: Author styles (your CSS) */
/* Rule 4: Author !important */
/* Rule 5: User !important */
/* Long form */
margin-top: 10px;
margin-right: 20px;
margin-bottom: 10px;
margin-left: 20px;
/* Shorthand */
margin: 10px 20px;
/* Even shorter */
margin: 10px;
/* Debug with temporary border */
* { border: 1px solid red !important; }
layout-demo.htmlTime: 45 minutes
This task will help you understand CSS layout and positioning
CSS Layout and Box Model - Advanced positioning and layout techniques