Developer Notes

Q & A

Q1 Can multiple <p> be put inside <figcaption>?

Yes, multiple <p> elements can be placed inside a <figcaption> element. The <figcaption> is a container element that can hold various types of content, including multiple paragraphs, lists, or other block-level elements.

Example:

                        
                            <figure>
                                ㅤㅤ<img src="image.jpg" alt="Description">
                                ㅤㅤ<figcaption>
                                    ㅤㅤㅤㅤ<p>First paragraph of caption.</p>
                                    ㅤㅤㅤㅤ<p>Second paragraph of caption.</p>
                                ㅤㅤ</figcaption>
                            </figure>
                        
                    

This is valid HTML5 and commonly used for detailed figure descriptions or multi-part captions.

Q2 How to make .note-box equal in height?

Issue: Different content lengths cause uneven heights.

Dev note image

Original code:

                        
                            <section class="note-options">

                                ㅤㅤ<a href="" class="note-box-link">
                                ㅤㅤㅤㅤ<div class="note-box">
                                    ㅤㅤㅤㅤㅤㅤ<i class="fa-solid fa-laptop-code"></i>
                                    ㅤㅤㅤㅤㅤㅤ<div class="note-box-desc">
                                        ㅤㅤㅤㅤㅤㅤㅤㅤ<h3>Class Notes</h3>
                                        ㅤㅤㅤㅤㅤㅤㅤㅤ<p>Core concepts, technical foundations,
                                        ㅤㅤㅤㅤㅤㅤㅤㅤlearning materials & references.</p>
                                    ㅤㅤㅤㅤㅤㅤ</div>
                                ㅤㅤㅤㅤ</div>
                                ㅤㅤ</a>

                                ㅤㅤ<a href="" class="note-box-link">
                                ㅤㅤㅤㅤ<div class="note-box">
                                    ㅤㅤㅤㅤㅤㅤ<i class="fa-regular fa-file-code"></i>
                                    ㅤㅤㅤㅤㅤㅤ<div class="note-box-desc">
                                        ㅤㅤㅤㅤㅤㅤㅤㅤ<h3>Developer Notes</h3>
                                        ㅤㅤㅤㅤㅤㅤㅤㅤ<p>Project insights & practical development 
                                        ㅤㅤㅤㅤㅤㅤㅤㅤlearnings.</p>
                                    ㅤㅤㅤㅤㅤㅤ</div>
                                ㅤㅤㅤㅤ</div>
                                ㅤㅤ</a>

                            </section>
                        
                    

Solutions

Dev note image

Use the parent container to stretch each card wrapper, then make each .note-box fill it.

                    
                        .note-options {
                            ㅤㅤdisplay: flex;
                            ㅤㅤgap: 1.25rem;
                            ㅤㅤalign-items: stretch; /* key */
                        }

                        .note-box-link {
                            ㅤㅤdisplay: flex; /* let child stretch */
                            ㅤㅤwidth: 50%;
                        }

                        .note-box {
                            ㅤㅤdisplay: flex;
                            ㅤㅤflex-direction: column;
                            ㅤㅤheight: 100%; /* fill equal-height wrapper */
                        }
                    
                

If heights still differ, it usually means content is not inside the same wrapper structure for each item—keep each card as a.note-box-link > .note-box with identical nesting. Want me to apply this directly to your CSS?

Q3 Why does the margin of <img> not overlap with <p> before it?

Issue: <p> has a developer preset margin of 0.7rem 0 while <img> has no preset margin. I set a margin of 1rem 0 to <img> but it didn't work as expected. I expected the higher margin top and bottom on the image to collapse with the <p> margin and expand the margin top and bottom to 1rem, but it didn't.

Instead of collapsing into one combined vertical margin, the margins of the <p> and <img> elements are rendered independently and sit on top of each other.

Dev note image

Explanations

Margin collapsing, where the top margin of one element and the bottom margin of an adjacent element are combined into a single margin, only occurs between block-level elements – never between block and inline-block, block and inline, or inline and inline.

In this case:

Because the image is an inline element, its margins will not collapse with the block-level paragraph element. The margins of both elements will be rendered independently.


Is <img> an inline element?

Yes, based on the computed styles, the img.class-note-img element has a default display: inline; property. Images are inline elements by default in HTML.


Then why are you able to set width and height on <img> if it's an inline element?

You've hit on a really interesting point about how CSS works! While <img> elements are indeed inline by default, they are a special category of inline elements known as replaced elements.

Here's why you can set width and height on them:

In summary: The ability to set width and height on an <img> element despite its inline display property is due to its nature as a replaced element, which needs to accommodate external content with intrinsic dimensions.

Putting this in another words, replaced elements like <img> have a unique behavior that allows them to be styled with width and height while still flowing inline with text.

<img> element exhibits a kind of "hybrid" behavior: they behave like inline elements in terms of flow and layout, but they also have block-like properties (like accepting width and height) due to their nature as replaced elements.


Then why is <img> not a block element?

You're asking a very insightful question that gets to the heart of CSS layout and the nuances of HTML elements! It seems contradictory that an <img> can have width, height, and respond to overflow like a block element, yet still be inline.

The key to understanding this is to distinguish between two concepts:

Let's break it down:

1. display: inline and Flow Layout

When an element has display: inline (which <img> does by default), it means:

This fundamental behavior of staying "in-line" with text is what makes it an inline element, distinguishing it from a block element which always starts on a new line and takes up the full available width.

2. Replaced Elements and Intrinsic Dimensions

As we discussed, <img> is a replaced element. This is where the difference comes in:

Why not a block element then?

If <img> were a block element by default:

In summary:

<img> is considered an inline element primarily because of its default flow behavior in the document: it sits alongside other content on the same line. The fact that you can apply width, height, and overflow to it stems from its secondary characteristic as a replaced element, whose dimensions are determined by an external resource that needs to be scaled or clipped within its allocated space.

This combination makes <img> quite versatile, allowing it to fit seamlessly into text while still offering precise control over its visual dimensions.


Can you apply margin-top and margin-bottom to an inline element?

Yes, you can apply margin-top and margin-bottom to an inline element, but they will not affect the layout in the same way as they do for block-level elements. For inline elements, vertical margins (top and bottom) do not collapse with adjacent elements and do not push other content away. Instead, they may overlap with surrounding content or be ignored in terms of layout, depending on the context and the specific inline element.

In the case of an <img> element, which is an inline replaced element, you can set margin-top and margin-bottom, and they will create space around the image. However, this space will not cause the image to push away adjacent text or elements vertically; instead, it may overlap with them or simply add space within the line height of the image.


Why does the margin of <img> not collapse with the margin of <p> before it?

Margin collapsing occurs when the vertical margins of adjacent block-level elements combine into a single margin. However, in this case, the <img> element is an inline element, while the <p> element is a block-level element. Since margin collapsing only occurs between block-level elements, the margins of the <img> and <p> will not collapse and will be rendered independently.

In summary, the margin of the <img> does not collapse with the margin of the <p> before it because they are different types of elements (inline vs block), and margin collapsing only occurs between block-level elements.


What other elements are considered replaced elements?

Beyond <img>, here are some other common HTML elements that are considered "replaced elements":

These elements share the characteristic that their content and, often, their intrinsic dimensions are determined by an external resource rather than the CSS styling of the element itself, allowing them to accept width and height properties even when they behave as inline elements in terms of flow.


Can you explain more about how replaced elements handle overflow?

That's an excellent question, as overflow behavior on replaced elements can sometimes be a bit counter-intuitive compared to standard block-level elements.

Here's a breakdown:

How overflow typically works (for non-replaced elements)

For most HTML elements (e.g., div, p, span with display: block or inline-block), the overflow property (hidden, scroll, auto, visible) controls what happens when the content of an element exceeds its content box. If you set a fixed width and height on a div and then put a lot of text inside, overflow determines if that text is clipped, scrollable, or visible outside the box.

How overflow applies to Replaced Elements (like <img>, <iframe>, <video>)

For replaced elements, the "content" is the external resource they represent (the image, the embedded page, the video stream). When you apply width and height to a replaced element, you are defining the dimensions of the box that contains this external resource.

The overflow property on a replaced element generally behaves as follows:

More Relevant Property: object-fit

While overflow can be used to clip, for controlling how an image or video fits within its allocated width and height (rather than just clipping it), the object-fit CSS property is often more powerful and semantically appropriate.

object-fit values include:

So, for images and videos, you'll often combine width and height with object-fit to control their appearance within their container, and then overflow: hidden if you specifically want to clip any parts of the element itself (though object-fit: cover often handles this implicitly for the content).