Click here to Skip to main content
15,921,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm asking if you can encapsulate an img tag around an anchor tag.

For example,

HTML
<a href="#" class="subnavbtn"><img src="images/news logo (1).png" alt="play" class="sidebar_img" height='32px' width='32px'>Today</a>


The img tag is inside of the anchor tag in this example. I was just wondering if this is acceptable. When I run the code, it does what I want it to do. Also if it is acceptable then how do you apply styling to the image itself with CSS.

What I have tried:

I tried looking for similar examples online, but I didn't find any other examples.
Posted
Updated 20-Jul-21 13:36pm
v2

1 solution

Of course you can put an IMG tag inside an A tag. There's nothing wrong with it.

As for "apply styling to the image itself", that all depends on what you want to do. You've got limited options.

CSS Styling Images[^]
 
Share this answer
 
Comments
adam breslin 21-Jul-21 0:57am    
Are you saying I can reference the img tag by using the "img" selector?
Dave Kreskowiak 21-Jul-21 8:51am    
Did you even bother to click the link I posted?
adam breslin 22-Jul-21 19:02pm    
Ok that was a dumb question. I want to know how you style the anchor text without affecting the img tag at all from my example at the top. @Dave Kreskowiak
Dave Kreskowiak 22-Jul-21 19:06pm    
https://www.w3schools.com/css/css_link.asp
adam breslin 22-Jul-21 19:26pm    
I want to add padding to the anchor text. The examples from w3schools only shows how to change the font or color of the anchor text, but not how to add padding to the anchor text. @Dave Kreskowiak

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900