My problem is that when I use text-align: center;
, my text is centered but the "p" element doesn't resize to fit the text.
In the example below, we can see that the "p" element is much larger thant the text itself, I would like it to fit perfectly the text, because I want the text to be against the green borders (but still centered in its "p").
How could I do that ?
#container {
width: 270px;
display: flex;
justify-content: space-between;
border: 2px green solid;
}
div {
border: 2px black solid;
}
p {
text-align: center;
display: block;
font-family: "Times New Roman";
font-size: 16px;
background-color: yellow;
}
<div id="container">
<div>
<p>Small text</p>
</div>
<div>
<p>This is another small paragraph</p>
</div>
</div>