Build a YouTube Video Card in 30 Minutes | HTML & CSS

Share

Summary

Learn how to build a YouTube video recommendation component using HTML and CSS. This tutorial covers structuring the HTML, styling with Flexbox for layout, utilizing CSS positioning for overlays, and integrating Google Fonts like Roboto for a polished look.

Highlights

Introduction and Component Breakdown
00:00:00

The video introduces the goal of building a YouTube recommendation component using HTML and CSS in CodePen. The component is broken down into two main sections: a left section for the image/video preview and a right section for text information. A wrapper div with the class 'recommendation' will contain both sections, named 'preview' and 'info' respectively.

Initial Layout with Flexbox
00:04:00

To align the 'preview' and 'info' sections side-by-side, the 'recommendation' wrapper is given 'display: flex'. This immediately places the two block-level elements horizontally. The importance of starting with layout in CSS is emphasized.

Structuring the Info Section
00:05:22

The right 'info' section is further structured with divs for the video 'title', 'username', and a 'view-info' section for views and upload time. Flexbox is used for the 'view-info' to align sub-elements and demonstrate different 'justify-content' properties like 'space-between'.

Building the Preview Section with an Image
00:11:00

The left 'preview' section is built, starting by embedding a thumbnail image. The video demonstrates how to inspect a YouTube video to extract its thumbnail URL. The image is given a specific width to match the YouTube design.

Adding an Overlay Timestamp with CSS Positioning
00:14:00

A timestamp (e.g., "1:33") is added to the preview section. To overlay this text on the image, CSS positioning is used. The 'preview' container is given 'position: relative', and the 'timestamp' div is given 'position: absolute'. This allows the timestamp to be precisely placed at the bottom-right of the image using 'bottom: 5px' and 'right: 5px'. Explanations of static, relative, and absolute positioning are provided.

Styling the Timestamp and Adding Cursor Pointer
00:21:00

The timestamp is styled with a black background, white text, padding, and a border-radius to match the YouTube aesthetic. A 'cursor: pointer' is added to the overall recommendation component to indicate it's clickable, replicating YouTube's behavior.

Styling Text in the Info Section
00:24:00

The video title in the 'info' section is styled to be bold and a bit larger. The concept of truncating long titles using JavaScript (not covered in this CSS tutorial) is mentioned. Additional styling, such as adding a 'margin-right' to the 'preview' section, is applied for better spacing.

Integrating Google Fonts (Roboto)
00:29:56

The video demonstrates how to identify the font typically used by YouTube (Roboto) using browser developer tools. It then shows how to import Roboto from Google Fonts and apply it to the entire document using the 'font-family' property, including a 'sans-serif' fallback for browser compatibility.

Conclusion and Key Concepts
00:33:30

The tutorial concludes by reviewing the core CSS concepts used: Flexbox for layout control and CSS positioning (relative and absolute) for element overlays. The final card closely resembles YouTube's recommendation component, demonstrating effective use of HTML and CSS for building complex UI elements.

Recently Summarized Articles

Loading...