+ 4

how to maintain same size when the text replaces the image?

i have a button which has an image in it. when clicked, the image is replaced with a text. but now the button size reduces to fit the text size. how do i keep the same size for both image and text? and how to center text vertically in a button? https://code.sololearn.com/W6UXJZ3Ou6bu/?ref=app i know this is a naive approach. But how do i go about it with <div> or any other such thing?

11th Aug 2022, 6:38 PM
Harsha S
Harsha S - avatar
4 Antworten
+ 8
You could give the button a fixed size and set the image relative to the button size (see css tab) https://code.sololearn.com/WhMoU74kaS4w/?ref=app Maybe consider toggling the image visibility/ display instead of creating an html element each time via innerHtml...
11th Aug 2022, 7:10 PM
Lisa
Lisa - avatar
+ 4
I would resize the button to be slightly larger than the dimensions of the image. And I would separate the styles. https://code.sololearn.com/WSbmGY1KsxvE/?ref=app
11th Aug 2022, 6:51 PM
Chris Coder
Chris Coder - avatar
+ 4
Lisa that is great. Cleaner and responsive and the comments are informative.
11th Aug 2022, 7:26 PM
Chris Coder
Chris Coder - avatar