It’s easy to vertically align the anchor elements by something like display: block , but I have no idea how to put the <div> element next to them. Note 1 : The <div> needs to be the anchors’ next sibling. Note 2: The above is just a sample code. My actual links can be any width.
Unfortunately that doesn’t work for me. As mentioned in my question and markup, the div needs to be the anchor’s next sibling. That’s not the case in the solution provided above.
However** I would strongly advise** that you adjust the structure (similar to the post from @Zawhether ) but I would go with flex or gid as mentioned by @Pepster64
My example is just a trick based on the code you presented.
You’d need to have a wrapper around the three links to use flex and a parent wrapper around all the items (unless you use the body instead of a main wrapper).
There will only be the contrived solutions if the html has to stay as is.
Eureka! I studied some basic concepts of the grid layout and came up with the following: DEMO
Everything seems good, but the problem is the anchors’ height: I’ve explicitly given them a height value, but I want their height to fit their content. Is there a better approach?
I’d expected that you would want the links to spread out and match the height of the green block. I think you may be stuck with an arbitrary height in that grid demo if you want the links to line up under each other (use rems and not px though).
I did have another demo with columns that I didn’t show but does the trick (assuming you don’t change/add to the rules again )
No, not really: There can be any number of links in the first column and the <div> in the second column can be any height. My code is just a sample and the sizes and values are just arbitrary numbers. Sorry I didn’t mention that in my question.
Many thanks for the demo, but as I said the number of links can be more than that, so I can’t use this approach. I’m going to stick to your first answer.