Struggling to include a link for an image following the application of a hover effect

I am making a website to download wallpapers. On the home page, I want to create a hover effect on the image so I can add a "like" and "add" to the collection button. Here's the reference: I have the hover effect that I want but I want to be able to click on the image so that the user can go to a download page. But I can't seem to add an anchor tag after I added the hover effect.

The HTML code for a single image:

.card {
  overflow: hidden;
  position: relative;
  width: 400px;
}

.image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  opacity: 0;
  padding: 15px;
  transition: opacity 0.25s;
}

.image-overlay--blur {
  backdrop-filter: blur(5px);
}

.image-overlay:hover {
  opacity: 1;
}

.image-overlay>* {
  transform: translateY(-20px);
  transition: transform 0.25s;
}

.image-overlay:hover>* {
  transform: translateY(0);
}
<div class="container-fluid mt-4">
  <div class="row">
    <div class="card ml-4 bg-dark" style="width: 30rem;" data-aos="fade-left">
      <img src="img/1.png" class="card-img-top " alt="...">
      <div class="image-overlay image-overlay--blur">
        <div class="card-text">
          <button type="button" class="btn btn-outline-danger mr-2">Like</button>
          <button type="button" class="btn btn-outline-light mr-2">Add</button>
        </div>
      </div>
    </div>

Answer №1

If you need a solution that doesn't involve using an anchor tag, you can utilize the onclick attribute on the image container in this manner:

<div class="image-overlay image-overlay--blur" onclick="window.open('image-link')">

This code will trigger the specified URL to open within the window.open() function in a new tab. You can also use the second argument to open the link in the same tab.

<div class="image-overlay image-overlay--blur" onclick="window.open('image-link', '_self')">

However, if you do require an anchor tag, implement it as shown below:

<div class="container-fluid mt-4">
  <div class="row">
    <a href="url here" target="_blank" rel="noopener noreferrer">
    <div class="card ml-4 bg-dark" style="width: 30rem;" data-aos="fade-left">
      <img src="img/1.png" class="card-img-top " alt="...">
      <div class="image-overlay image-overlay--blur">
        <div class="card-text">
          <button type="button" class="btn btn-outline-danger mr-2">Like</button>
          <button type="button" class="btn btn-outline-light mr-2">Add</button>
        </div>
      </div>
      </a>
    </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Fading in and out occurs several times while scrolling through the window

My goal is to update the logo image source with a fadeIn and fadeOut effect when scrolling up or down. The issue I'm facing is that the effect happens multiple times even after just one scroll, resulting in the logo flashing many times before finally ...

CSS: Is there a way to create a square div that is always the same size as the smallest dimension of its parent container?

Check out this codepen that showcases my issue: http://codepen.io/anon/pen/xwQpLy?editors=110 I've been using a little trick to maintain a 1:1 ratio for the box: .squarebox { position: relative; width: 100%; } .squarebox::before { padding-bo ...

You are only able to click the button once per day

I am working on a button that contains numeric values and updates a total number displayed on the page when clicked. I would like this button to only be clickable once per day, so that users cannot click it multiple times within a 24 hour period. Below i ...

Styling with CSS to create a division that appears below another

I am working with HTML code that looks like this: <div class='box'> <div class='left'>content left</div> <div class='right'>content right</div> </div> Now, for smartphone devices, ...

Switch up the animation based on the state in AngularJS

In my AngularJS application, I have implemented CSS animations for transitioning between states. The animations involve sliding content from left to right with specific timings and transforms. .content.ng-enter, .content.ng-leave { -webkit-animation-t ...

minimizing the size of the response

Currently, I am developing a web application and have implemented a polling approach to continuously check for updates. These poll requests are sent out every 1-2 seconds. The response size is typically 240 bytes if there are no updates (in which case an e ...

Ways to align a DIV in the center of another DIV?

I am currently working on building a footer. My goal is to center the 4 divs in the footer, similar to the first paragraph or the 5 icons that are not rendering correctly. What would be the most effective approach to achieve this? Demo: http://jsfiddle.n ...

Using a PHP for loop to manage a div control

Query: I am seeking a way to exert influence over the positioning of my dynamic divs. I want each div to be relative to the parent div. Challenge: The current code does not provide the flexibility to adjust the div positions based on the parent div. For i ...

css How to target a specific row and column within a table using css selector in Selenium WebDriver

When attempting to locate css=table#Salarytable.dataTable.3.4 in Selenium IDE, the cell highlights correctly. However, when using this locator in my Selenium code... String salary=driver.findElement(By.cssSelector("table#Salarytable.dataTable.3.4")).get ...

Although PhoneGap resolution remains consistent, the outcomes may vary

I seem to be facing a similar issue as discussed in this post on Stack Overflow: Screen Resolution On A PhoneGap App My problem is that I have both an iPad and an Android tablet, both with a resolution of 1024 pixels across. However, while my screen displ ...

What are the differences in using ng-controller versus data-ng-controller?

When working with Angularjs, how do I determine whether to use data-ng-controller or ng-controller? In terms of current best practices for good software design, when is it appropriate to use each one? The information cited suggests that data-ng-controlle ...

Saving attribute values in AngularJS by default

My custom tags use 'repairwidth' with the 'width' attribute to get input. The width is determined by the size. The first repairwidth tag always has a width of 50. The second and third repairwidth tags have a dynamic width based on "{ ...

Guide on hiding the sidebar in mobile view and enabling toggling on click for both mobile and other devices with the use of vue.js and bootstrap4

I need assistance with transitioning my code from pure Bootstrap4 and JavaScript to Vue.js. When I tried implementing it in mobile view, the sidebar is not showing. Below is the code snippet that I am trying to change for Vue.js, but I keep encountering an ...

Sending selected option from bootstrap dropdown to the subsequent php page

Is there a way to pass the selected value from a dropdown in Bootstrap to the next page? I have multiple options to choose from and I don't want to create separate pages with the same layout for each option. How can I pass the dropdown value to the ne ...

What is the method for accessing two distinct values through a single checkbox?

Using a combination of HTML, PHP, and jQuery for my website development, I have implemented a checkbox within a form: <input type="checkbox" name="check_status" id="check_status" value="1"> Status I am looking to use the same checkbox for two diffe ...

Fit the image to fill the available space and position it in the center for maximum impact

I'm currently working on a single page application where I need to display an image that fills up as much available space as possible: Priority: maintain the aspect ratio Avoid cropping the image Stretch the image horizontally and/or vertically (with ...

Eliminate unnecessary white space on your webpage using CSS with the 960.gs grid system

As I work on building my portfolio website from scratch, I came across a CSS framework known as "960.gs". While I have experience with similar tools, this is my first time delving into a pure CSS framework, so I'm feeling a bit out of practice. Here ...

Issue with CSS positioning: Struggling to place images outside a div with floating properties

Here is what I need to design along with the code I have written, HTML: <div className='relative mt-64 mb-40 md:h-56 h-36 w-full gradient z-10'> <img className='bg-transparent w-20 h-28 absolute md:top-40 md:lef ...

What is the best method for caching inline SVG in web browsers?

Over the years, SVGs have remained popular due to their scalability. One key advantage of inline SVG is the ability to manipulate it with CSS and JS. Additionally, using the <use> tag allows for referencing the original element when repeating the sam ...

How can you alter the animation direction of a Bootstrap carousel slide?

Is it possible to create a reverse animation effect for a bootstrap carousel slide without changing the order of slides? 1 2 3 4 to 4 3 2 1 I just want the slides to appear in reverse order, is that achievable? The code snippet looks like this: < ...