This could be asked in any CSS forum… depending on the theme you are using this might already be implemented. What you seek is “inline lists” and starting from the following link you can reach your goal:
The problem you are having with this specific code is, that you wrap <h2> around the link. H2 is a block tag and always will lead to blocks, not inline code. Remove it and add the design (fontsize, font weight) to the list item that you need.
Hierarchically speaking listitems should never be headings.
If the code you posted does NOT result in an inline list then some other css part is overwriting what you attempt. Please post a link to a sample page or your repo and we can look into it.