I have RichText editor and I want to let user create its own figcaption
for a figure. However, the number of a figure should be generated separetely. I want to combine user description of a figure (p
tag) with a number (span
tag) to make them behave as a single paragraph
. I tried with float: left
on a span
but I can’t center it properly (the combined figcaption
should have the width of entire page instead of fitting the width of an image.
Here is my demo: https://codepen.io/degel123/pen/rNRpWNQ
As you can see, this float
element does not center properly. I tried adding
width: fit-content;
margin-left:auto;
margin-right:auto;
to figcaption
style but then content is splitted into two lines instead of keeping it in single one.
2
Answers
Use
display: flex
for the figcaption, and then applyjustify-content
;Just use display flex and justify the content center to make it horizontally centered and then align the items center to make it vertically centered and then a .5 rem gap to show it clean (my choice)
Here is a demo
I just updated the snipped that you gave and made changes in the CSS of figcaption