I have two elements (a paragraph and a img) inside a link element and i want the paragraph to be the same width as the img, i tried doing display: inline-block;
and a couple other things but cant seem to get it to work. can anyone help?
<li>
<a href="https://store.steampowered.com/app/4000/Garrys_Mod/" target="_blank" >
<img src="/Photos/garrysmod.jpg">
<p>Garrys Mod is a physics sandbox game in which you can do allmost anything you want, including playing hide and seek, fighting monster, fighting eachother, escape from jail, and much more</p>
</a>
</li>
2
Answers
Edited/changed after comment (the question wasn’t clear about this):
Apply
display: flex
andflex-direction: column;
to the link, plus an optionalwidth
setting to the parent container (ul
), and (also optionally)text-align: justify
to thep
tag to make the text align also to the right border:I have given you an example below to learn from.
You should look into flex. It’s just an easy way to control content. There is no actual purpose for it here, but I still gave the link container the flex property, because you would probably want to align the content later (e.g. align-items: center).
Read up on flexbox, good luck!