paint-brush
How to Set a div to Its Content's Width in CSSby@smpnjn
291 reads

How to Set a div to Its Content's Width in CSS

by Johnny Simpson2mJuly 4th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Both inline and block elements are important components of CSS. To learn about the box model in CSS, click here. When we create a new div or other block element, it takes up the full width of the page - but what if we want a div or any other block DOM element to only be the width of its contents and no more? To make an HTML block an element like a div take up no more space than its content, we can use the fit-content keyword.

Coin Mentioned

Mention Thumbnail
featured image - How to Set a div to Its Content's Width in CSS
Johnny Simpson HackerNoon profile picture
Johnny Simpson

Johnny Simpson

@smpnjn

Product, Engineering, Web

About @smpnjn
LEARN MORE ABOUT @SMPNJN'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Johnny Simpson HackerNoon profile picture
Johnny Simpson@smpnjn
Product, Engineering, Web

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Newsbreak
Minibird
Platypush
Coffee-web
Asorrybowl
Trendradars
Artist
Allella
Spaceint
Dcs0
Numblr
Jakobs