AltSchool Of Engineering Tinyuka’24 Month 3 Week 4


This week, we started our class with a revision session, which I've summarized here. I highly recommend reviewing it if you haven't done so already. Let’s dive into Enhancing readability as thought by our awesome instructor.
Enhancing Readability and User Experience
Typography is a vital element of web design, significantly influencing readability, accessibility, and the overall user experience. Here are some essential CSS properties that play a role in effective typography:
Key CSS Typography Properties
font-style
Modifies the style of the text (e.g., italic or normal).
Example:
font-style: italic; /* Italicizes the text */
font-weight
Controls the thickness of the text, ranging from normal to bold.
Example:
font-weight: bold; /* Makes the text bold */
font-size
Sets the size of the text, crucial for readability.
Example:
font-size: 16px; /* Defines the font size */
line-height
Adjusts the space between lines of text, enhancing legibility.
Example:
line-height: 1.5; /* Increases line height for better readability */
font-family
Specifies the typeface to be used for the text, allowing for stylistic choices.
Example:
font-family: 'Arial', sans-serif; /* Sets the font family */
text-align
Aligns the text within its container (e.g., left, right, center).
Example:
text-align: center; /* Centers the text */
text-transform
Controls the capitalization of text (e.g., uppercase, lowercase).
Example:
text-transform: uppercase; /* Transforms text to uppercase */
text-decoration
Adds decorations to text, such as underline or strikethrough.
Example:
text-decoration: underline; /* Underlines the text */
letter-spacing and word-spacing
Adjusts the spacing between letters and words, respectively.
Example:
letter-spacing: 2px; /* Increases spacing between letters */
text-shadow
Adds shadow effects to text, enhancing visual appeal.
Example:
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); /* Creates a shadow effect */
Font Integration
To enhance typography, designers can use font hosting services like Google Fonts, which offers a variety of free, open-source fonts that are easy to integrate into a website.
Example of Google Fonts Integration:
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
Using @font-face for Custom Fonts
- The @font-face rule allows embedding custom fonts into a web page, enabling the use of various font file formats (e.g., .woff, .woff2, .ttf).
Example:
@font-face {
font-family: 'MyCustomFont';
src: url('mycustomfont.woff2') format('woff2');
font-weight: normal;
font-style: normal;
}
Guide to Finding CSS Errors
Debugging is the process of identifying and fixing errors in software code. When developing, code may appear functional, but runtime errors can occur, typically falling into two main categories:
Syntax Errors
- These arise when the code violates the language's rules, preventing it from compiling or interpreting correctly.
Logic Errors
- These occur when the code is syntactically correct but produces incorrect results due to flawed reasoning or implementation.
Why Debug CSS?
Debugging CSS is essential when styles aren’t applied as expected or when elements behave unexpectedly. A helpful tip is to temporarily add a border to the element in question to visualize its boundaries.
Using Browser Developer Tools
Modern browsers like Chrome and Firefox offer robust developer tools that facilitate debugging. Here’s how to access and utilize these tools:
Accessing DevTools
click on an element on a webpage and select "Inspect" from the context menu. This action highlights the selected element's code and displays the HTML structure and applied CSS.
Keyboard Shortcuts:
- Windows: Ctrl + Shift + I
- macOS: Command + Shift + I
Features of DevTools
Live Editing
You can modify HTML and CSS directly in the DevTools, with changes reflected immediately in the browser. This feature allows for quick previewing of modifications.
Toggling CSS Rules
Uncheck CSS properties in the DevTools to experiment with different styles on the fly, helping you identify what works best.
Box Model Insights
The layout view in DevTools provides a detailed view of the box model for selected elements, showing properties like border, margin, padding, height, and width.
Inspecting Applied CSS
To check the CSS affecting an element, right-click on the element and select "Inspect." This opens DevTools, displaying the HTML and the CSS rules applied to the element, making it easier to diagnose unexpected styling issues.
Inline, Internal, and External
CSS can be applied in various ways to style HTML elements, with inline CSS being one of the simplest methods. It is used to apply unique styles directly to a single HTML element via the style attribute within the HTML tag.
Inline CSS
Inline CSS allows you to apply specific styles to an individual HTML element.
Advantages
Quick Changes: Ideal for making fast, specific adjustments without needing to modify external stylesheets.
Style Override: Useful for temporarily overriding styles defined in internal or external styles.
Disadvantages
- Readability: Inline styles can clutter the HTML code, making it harder to read and maintain.
- Limited Reusability: Not suitable for styling multiple elements since each element needs its own inline style.
Example of Inline CSS
<p style="color: blue; font-size: 20px;">This is a blue paragraph with a larger font size.</p>
Internal CSS
Internal CSS is defined within a <style>
tag in the <head>
section of an HTML document. This method allows you to apply styles to the entire page.
Advantages
Single Document: Styles are contained within the same HTML file, making it easier to manage for smaller projects.
Effective for Multiple Elements: You can style multiple elements without repeating the styles, improving maintainability.
Disadvantages
- Limited Scope: Styles only apply to the specific document, which means you need to duplicate styles across multiple pages if required.
- Increased File Size: For larger projects, internal CSS can make HTML files bulkier.
Example of Internal CSS;
<head>
<style>
body {
background-color: lightgray;
}
p {
color: blue;
font-size: 18px;
}
</style>
</head>
External CSS
External CSS involves linking to a separate CSS file from within the HTML document. This is the most efficient way to apply styles across multiple pages.
Advantages
Reusability: A single CSS file can be linked to multiple HTML documents, ensuring consistent styling across an entire website.
Cleaner HTML: Keeps HTML files clean and focused on structure, separating content from presentation.
Easier Maintenance: Updates to styles can be made in one place, affecting all linked pages.
Disadvantages
Additional HTTP Request: Each linked CSS file requires an additional request, which can slightly increase load times.
Dependency: If the CSS file is unavailable, styles won’t be applied, affecting the appearance of the site.
Example of External CSS;
<head>
<link rel="stylesheet" href="styles.css">
</head>
And in styles.css file;
body {
background-color: lightgray;
}
p {
color: blue;
font-size: 18px;
}
Understanding Flexbox
Flexbox is a one-dimensional layout model in CSS that enables the arrangement of items either vertically (in columns) or horizontally (in rows). To use Flexbox, you simply set display: flex;
on the parent container.
This layout method operates along two axes. The main axis is the direction in which flex items are arranged, while the cross axis runs perpendicular to it. The main axis has defined start and end points, as well as a measurable size, while the cross axis has its own start, end, and size.
To create a Flexbox layout, apply display: flex;
to the parent element, transforming its child elements into flex items. This allows for various layout capabilities, such as displaying items in rows or columns, vertically centering content, and respecting the document's writing mode.
Flexbox also offers flexibility in visual ordering of items, enabling you to rearrange them without changing their order in the HTML structure. Additionally, it ensures that columns in a multi-column layout can adopt equal heights, even with differing content amounts. Space within flex items can be allocated dynamically, allowing them to grow or shrink based on the available space in their parent. This makes Flexbox an ideal choice for responsive design, where you might want all children of a container to share equal dimensions regardless of the space they occupy.
Example
.container {
display: flex;
justify-content: space-between; /* Distributes space between items */
}
.item {
flex: 1; /* Each item takes equal width */
}
This example creates a layout where items are arranged in a row with equal widths, making use of Flexbox’s powerful capabilities.
Direction and Alignment in Flexbox
In Flexbox, the arrangement of flex items within a container is primarily determined by direction and alignment. The flex-direction
property specifies the direction of the flex items, which can be set to either a column (vertical) or a row (horizontal).
For example, using flex-direction: row;
will align items in a horizontal line, while flex-direction: column;
will stack them vertically. This property is essential for controlling the layout based on the design requirements.
Example
.container {
display: flex;
flex-direction: row; /* Items arranged in a row */
}
In this example, the flex items will be displayed horizontally within the container, allowing for versatile design options.
Alignment in Flexbox
Flexbox is highly effective for precise alignment of elements, facilitating both horizontal and vertical positioning. This capability is especially valuable for creating responsive layouts that adapt seamlessly to various screen sizes.
Key properties for alignment include:
Justify Content: This property aligns flex items along the main axis, allowing you to control the distribution of space between them. For instance, justify-content: center; centers items horizontally within the container.
Align Items: This property is used for aligning flex items along the cross axis. Using align-items: stretch; makes all items expand to fill the container height.
Align Content: When dealing with multiple lines of items, this property aligns the lines themselves along the cross axis. For example, align-content: space-between; distributes space evenly between lines.
Align Self: This property allows individual flex items to override the alignment set by align-items, giving more control over specific items. For instance, align-self: flex-end; can be used to push a single item to the bottom of the container.
Example
.container {
display: flex;
justify-content: space-between; /* Distributes space between items */
align-items: center; /* Vertically centers items */
}
In this example, the flex items are spaced out evenly along the main axis and centered vertically, showcasing Flexbox’s powerful alignment capabilities.
Growing and Shrinking in Flexbox
In Flexbox, understanding how items grow and shrink is crucial for effective layout management. Two key size concepts are the minimum content size, which is the smallest an item can be without overflowing, and the hypothetical size, representing the size an item would have without flex properties affecting it.
The flex-grow property dictates how much a flex item will expand relative to others when there’s extra space in the container. It uses a unitless value to determine the proportion of available space each item should occupy. For instance, if one item has flex-grow: 2;
and another has flex-grow: 1;
, the first item will take up twice as much of the free space.
Conversely, the flex-shrink property determines how items will reduce in size when the container is too small. This property only applies when items are between their minimum and hypothetical sizes. Setting flex-shrink: 0;
can prevent an item from shrinking altogether.
The flex-basis property defines the initial size of a flex item before any growth or shrinkage occurs, similar to setting a width for a flex item in a row.
Using the flex shorthand property combines flex-grow
, flex-shrink
, and flex-basis
into a single declaration for convenience. For example:
.item {
flex: 1 1 200px; /* flex-grow: 1; flex-shrink: 1; flex-basis: 200px; */
}
In this example, the item will grow to fill space, shrink if necessary, and start with a base size of 200 pixels, highlighting the streamlined management Flexbox provides for responsive designs.
I truly appreciate your support throughout this journey and your enthusiasm is incredibly motivating! I encourage you to dive deeper into the concepts we've explored together. Remember, practice is key, so keep experimenting and refining your skills!
I’d love to hear your feedback and thoughts, so please leave a comment below to start a conversation!
I’m Ikoh Sylva, a dedicated Cloud Computing enthusiast with several months of hands-on experience in AWS. I’m documenting my cloud journey from a beginner's perspective right here. If this resonates with you, please like and follow my posts, and consider sharing this article with others who are starting their own cloud journeys. Together, we can learn and grow!
Feel free to connect with me on social media as well!
Subscribe to my newsletter
Read articles from Ikoh Sylva directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Ikoh Sylva
Ikoh Sylva
I'm a Mobile and African Tech Enthusiast with a large focus on Cloud Technology (AWS)