White space within border

Hello!

How do I remove the white space within the borders of an element?

I have tried setting padding and margin to 0 in CSS this doesn’t seem to work. I would like a border that fits around the below code, and does not extend to the sides as shown in the image.

HTML code:

<div id="price">EUR 27.00</div> 

CSS code:

#price {
  text-align: center;
  display: block;
  border: 2px solid black;
 padding: 0px;
  margin: 0px;

Thanks in advance!

divs by default are block level elements. That means they will take up the entire horizontal space.

You would need to adjust the width instead.
You can set the width to use the fit-content value

1 Like

Thank you this has worked! :slight_smile:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.