Support Us
Help us keep WebWise free for all. Every donation fuels our mission to provide accessible web development education. Join us in empowering learners worldwise!
Fundamentals Course
In our previous lesson, we delved into the distinctive box models associated with different display types, realizing how we can alter box calculations by adjusting the display property. CSS introduces two fundamental box types: block and inline boxes, dictating the behavior and interaction of elements. The display property serves as a means to control the appearance of HTML elements on a webpage. Let's delve deeper into its diverse options in this lesson.
In this lesson overview, you will find a comprehensive outline of the topics covered in each section.
The majority of elements you've encountered thus far are block elements, signified by their default style, display: block. By default, block elements are displayed stacked on top of each other, with each new element initiating on a new line.
On the other hand, inline elements do not commence on a new line but rather appear in line with adjacent elements. A prime example of an inline element is a link, or <a> tag. When placed within a paragraph of text, a link seamlessly integrates into the paragraph. Moreover, padding and margin behave distinctively on inline elements. Typically, it's discouraged to add extra padding or margin to inline elements.
Inline-block elements exhibit characteristics of both inline and block elements, featuring block-style padding and margin while maintaining inline behavior. display: inline-block proves to be a valuable tool, yet in practice, flexbox is often preferred for aligning multiple boxes.
A discussion on block and inline elements wouldn't be complete without addressing divs and spans. Unlike other HTML elements that imbue meaning to their content, divs and spans are devoid of specific meaning. They serve as generic containers, capable of housing any content.
Despite their seemingly straightforward nature, divs and spans offer remarkable utility. They can serve as "hook" elements, allowing us to target them for styling with CSS using ids or classes. Additionally, we frequently use these elements to group related elements under one parent, facilitating proper positioning on the page.
You will discover additional resources and references to further enhance your understanding of the lesson topics.
Help us keep WebWise free for all. Every donation fuels our mission to provide accessible web development education. Join us in empowering learners worldwise!