The div
tag defines a division or a section in an HTML document that is used as a container to hold other HTML elements. It occupies more space than its contents and looks larger than its contents. We can make a div that is not larger than its contents using the following two CSS properties:
display:inline-block
display:table
If we apply any one of the above CSS properties to div
tag, then the div
will not be larger than its contents.
In the HTML tab:
div
tag named content1
.div
tag named content2
.div
tag named content3
.In the CSS tab:
background-color
property for content1
.background-color
and display: inline-block
property.background-color
and display: table
property.We apply background color to all three div
tags so that we can distinguish the space they use.
We can observe from the output that the first div
is larger than its contents. However, the div
tags which have CSS properties applied to them perfectly encapsulate their contents with no extra space.
RELATED TAGS
CONTRIBUTOR
View all Courses