Styling the Webs
Thinking about our websites as modular components and the fundamentals of styling websites. Lecture slides will be made available on the day of the lecture (May 20).
Common false assumptions about the web:
- Everyone has a mouse or touchscreen
- Everyone has steady high-speed internet
- 1 pixel = 1 pixel
- Everyone's computer is faster each year
- Everyone will view my website on Chrome
Thinking one has mastered 'the webz'...
What we want the web to be
Your first goal for every web project, fulfilling a need. You typically have less than 10 seconds to convince someone your website is the one they need.
What might help convince users your website is 'the one'?
What You Can Give the Webs
This potentially endless list...
- Content: text, visual, aural
- Structure: layout, grids, hierarchy, IA
- Accessibility: clean markup, flexibility
- Usable: interaction, utility, UX
Cascading Style Sheets
While HTML defines the structure of the content on the page, CSS styles the page to ensure the user get's something usable. Good code will clearly separate semantic markup from styling.
Keeping Them Apart
A real Romeo/Juliet scenario
Rules for keeping them separate
- Do not use HTML to define styling; i.e.
<br>, <i>, <b>
- Do not use inline CSS styling;
<section style="color: blue;">
- Keep files separate; .html defines content, .css defines style, never shall they meet
Let's Talk CSS
You want to aim for CSS stylings that are scalable and modular. Here are some divisions suggested as a framework:
- Base rules: direct styling of elements for normalizing or defaults
- Layout: structural styling for the page (i.e. .grid, .grid-column)
- Modules: styling for different components (i.e. .nav-bar, .nav-button)
- State Rules: styling different states (i.e. .is-current, .is-opened)
When you get started on planning out elements
More things to ensure:
- Use a purpose-oriented naming convention: .external-link (describe the content)
- Avoid naming based on style: .blue-border
- Use understandable names: #footer makes more sense then #lower-bar
- Agree with your teammate: You need to understand one another
ID vs. Class
IDs must always be unique,
<section id="kittens"> they can only be specified once. While classes can be used as many times as needed —
The order in which things are read
Inline styles:should never be used
- ID's: #home, #cool-stuff
- Classes, attributes & pseudo-classes: .home, [class], :hover
Units in CSS
In the journey to responsiveness, we want to aim for relative and scalable units as much as possible.
Rems — root-ems — are units responsive to the font-size set by the browser which help us establish easy relationships in type. As a general rule of thumb, setting your paragraphs to 1rem and scaling other things accordingly is better practice.
The Box Model
content-box vs border-box
Your new best friend
Ever wanted to know what the slides would look like with a red background? Right-click and 'Inspect Element' opens up the development tools to mess around with things in.
Block, Inline, and Inline-block
Block elements break to the next line, can have a height and width, and by default are full-width.
Inline elements stay in-line with other inline elements, and listen to their content for their sizing.
Inline-block elemetns stay in-line with other inline elements, can have a height and width, and listen to their content for their sizing.
Why we care
At the end of the day, it's about your mental sanity. But good clean, clear coding conventions, page and file structure typically loads and runs faster.
Some things to think about
You are not required to generate your own images and icons for this project. That being said, the branding must still be your own work. Here are some recommended suggestions:
For this week's lecture time please make sure you have the CSS tutorial starter-files ready to go.
Next week's lecture
Like Building Blocks
More depth on styleguides, as well as thinking and building responsive structures online..
Pre-recorded lectures and slides will typically become available the day of the lecture.