Welcome to our CSS Display Property tutorial! This lesson will guide you through understanding and mastering one of the fundamental CSS properties that help you control the layout and visibility of HTML elements. Let's dive in! 🐳
The display property in CSS is a powerful tool that allows you to define how a block-level element will be rendered on the page. You can change the nature of an element from an inline box to a block box, an inline-block, or even something more complex like a table cell or an inline-flex container.
display: blockWhen you set an element's display property to block, it will render as a standalone block-level box. A block-level box will start on a new line and take up the full width available, extending to the left and right margins.
div {
display: block;
border: 1px solid red;
padding: 10px;
width: 200px;
height: 100px;
}display: inlineWhen you set an element's display property to inline, it will flow along the line with other inline elements, taking up as much space as necessary.
span {
display: inline;
border: 1px solid blue;
padding: 10px;
margin-right: 10px;
}display: inline-blockThe inline-block value treats an element as if it were inline but allows you to set width, height, margin, and padding like a block-level element.
div {
display: inline-block;
border: 1px solid green;
padding: 10px;
width: 200px;
height: 100px;
margin-right: 10px;
}display: flexThe flex value enables Flexbox, a powerful and flexible (pun intended) layout model that allows you to create complex layouts easily.
div {
display: flex;
border: 1px solid purple;
padding: 10px;
}Which display value makes an element a standalone block-level box?
Which display value treats an element as if it were inline but allows you to set width, height, margin, and padding like a block-level element?
Happy learning, and stay curious! 🌟