WEB-DEVELOPMENT-APPLICATIONS practice question 13 of 25

A web designer inserts an image into a web page. Which CSS attribute should this designer use to ensure that there is one of pixel of space between the line image and the surrounding elements?

Full set: 131 questions
Answer options
A: Content
B: Padding
C: Margin Correct answer
D: border
Correct Answer:
C. Margin
Explanation

The CSS margin property is used to create space around an element, outside of any defined borders. To ensure there is space between an image and the elements surrounding it, a developer should apply a margin to the image element. A margin: 1px; rule would create one pixel of space on all four sides of the image, pushing other elements away.

Why Incorrect

Content refers to the image itself, not the space around it. Padding adds space between the content (the image) and its border, which is inside the element's boundary. A border is a line drawn around the element, between the padding and the margin, not empty space.

References

- Mozilla Developer Network (MDN). (2023). margin. In CSS: Cascading Style Sheets. Retrieved from https://developer.mozilla.org/en-US/docs/Web/CSS/margin. The summary states, "The margin CSS shorthand property sets the margin area on all four sides of an element."

- W3C. (2018). CSS Box Model Module Level 3. W3C Candidate Recommendation. Section 2.2: "Margin Area". Retrieved from https://www.w3.org/TR/css-box-3/#margin-area. This section defines the margin area as extending from the border edge to the margin edge, providing separation.

- Miller, R., & Gancarz, M. (2011). 6.813/6.831 User Interface Design and Implementation, Lecture 4: CSS. MIT OpenCourseWare. Retrieved from https://ocw.mit.edu/courses/6-813-user-interface-design-and-implementation-spring-2011/resources/mit6813s11lec04/. The lecture notes explicitly differentiate margin as space "outside the border" and padding as space "inside the border."

Scroll to Top