HTML & CSS Intro Course: Divs, IDs, & More
Master HTML Structure with Divs and CSS Styling
This tutorial covers essential HTML structure concepts including div tags, CSS styling, the box model, and responsive design principles for creating professional web layouts.
Key HTML & CSS Concepts
Div Tags
Block-level containers that stack vertically and wrap content sections. Essential for page structure and layout organization.
IDs vs Classes
IDs are unique identifiers used once per page with hashtag syntax. Classes can be reused multiple times with period syntax.
Box Model
Understanding padding, margins, borders, and how they affect element spacing and layout on your webpage.
Div vs Span Elements
| Feature | Div Tags | Span Tags |
|---|---|---|
| Display Type | Block-level | Inline |
| Layout Behavior | Stack vertically | Flow horizontally |
| Use Case | Large content sections | Small text portions |
| Default Width | Full container width | Content width only |
Creating a Page Wrapper
Add Background to Body
Set a background color on the body tag to establish the page's base color scheme
Create Div Container
Wrap all content in a div tag to create a distinct content area separate from the page background
Assign ID to Div
Give the div a unique ID like 'wrapper' to target it with CSS styling rules
Style with CSS
Use hashtag syntax to reference the ID and apply width, background, padding, and margin properties
Remember: hashtag (#) targets IDs, period (.) targets classes. IDs should be unique per page, while classes can be reused multiple times.
Width vs Max-Width
Box Model Properties
Padding
Space inside the element between content and border. Increases the internal breathing room and improves readability.
Margin
Space outside the element between it and other elements. Use 'margin: auto' to center block elements horizontally.
Border
Visible boundary around the element. Specify size, style (solid/dotted/dashed), and color properties.
To center a block element horizontally, set a max-width and use 'margin: auto'. This automatically distributes equal margins on left and right sides.
In general, you want to probably put some sort of limits on the width of your page to make it look better
CSS Best Practices
Avoids case sensitivity issues and maintains consistency
Names like 'wrapper' or 'container' clearly indicate purpose
Keeps code DRY (Don't Repeat Yourself) and more efficient
Child elements inherit parent styles, making code more maintainable
Ensures responsive behavior across different screen sizes
Using max-width instead of fixed width allows your content to adapt to different screen sizes, creating a better user experience across desktop, tablet, and mobile devices.
Key Takeaways