Need to make images responsive in CSS/HTML for custom plugin

I’ve searched the existing questions and found some similar issues, but the suggestions there didn’t solve my problem.

Here is the issue:

We are using the Visual Editor plugin for WordPress. My boss wanted this plugin to be used for a special promotion area in the header – he wants to display images that are clickable or have a button. I wrote some custom CSS so this plugin will do that. The issue, as you know, is you can’t make a link in CSS. So for the background image, I needed a button. However in this particular case there was so much text on the image, a button would not work.

So, I wrote an ID that I could call in HTML. I made a link, called the ID, and then inside the ID I put a text indent that would push the text off the page and the image would be clickable.

The issue here is that for some reason the image would not fully load. It was cutting off height-wise. I had set width: 100%; and height: auto;, but neither of those things worked.

So, I ended up simply inserting the IMG normally, and linking it normally, but now the problem is I need it to be responsive.

I wrote a class called .responsive-image and made the width: 100%; and height: auto; but this still doesn’t work.

Do I need to put the responsive image information elsewhere? Do I need to write some other class? I’m at a loss and have looked at this too long at this point.

You can see this header widget right here – 100daysofrealfood.com/carrot-top-almond-pesto-sustainable-almond-recipes/

And if you inspect you can see what I mean about it not being responsive.

Here’s what I’ve written to insert it into the widget:

<div class="days100-background-header-widget"><div class="responsive-image"><a 
href="https://www.100daysofrealfood.com/spring-reset-real-food-mini-pledge-
program/?utm_source=headerwidget">
<img src="https://www.100daysofrealfood.com/wp-
content/uploads/2017/04/WidgetHeaderAreaMP2017.png" border="0" 
class="responsive-image" alt="Real Food Mini Pledge Program" />
</a>
</div>
</div>

I have the class in there two places. Maybe that’s the issue?

Here’s the CSS for the main header widget class:

.days100-background-header-widget{
display: flex;
align-items: center;
justify-content: center;
}

Any feedback is really appreciated. Thanks for reading this super long question!!

Read more here: Need to make images responsive in CSS/HTML for custom plugin

Leave a Reply

Your email address will not be published. Required fields are marked *