There's no real magical formula to it.
The parts of it you can control is really to post great answers and post interesting questions. Its pretty hard to define what that is though. Its a soft skill as much as a hard one
Of course what a "great" answer is varies - some of my favourite answers are underloved, and I've occationally mock complained about an answer I consider trivial hitting hot network question - I have a fuller write up here, but it comes down to posting stuff that's well understood, stands alone and clear.
I do use a few tricks in my answers - As a visual person I often use screenshots, and animated gifs, and I tend to focus on things where I'm familiar with the subject matter, and draw on external sources where my expertise isn't quite there. A lot of that's experience and seeing what works.
In your case your answer isn't 'bad' but got posted on a question that's a software recommendation - the accepted practice has been changed over the years.