Please click on the element located in the top right corner of the image

I am attempting to place a font icon in the top right corner of some images, with the intention of only triggering an event when I click on the icon. However, my current setup causes the entire image to trigger the click event. How can I restructure this to achieve the desired functionality?

<div class="col-3">
    <h5>Dashboard Background</h5>
    <div class="image">
        <div class="icon-image-delete">
            <img class="img-thumbnail img-fluid" src="@Url.Action("Render", "Image", new { type = PreferenceImageType.DashboardBackground })" alt="No Background" />
        </div>
    </div>
</div>

CSS

.icon-image-delete {
    position: relative;
    vertical-align: middle;
    display: inline-block;
}

.icon-image-delete:after {
    font-family: FontAwesome;
    content: '\f014';
    font-size: 20px;
    position: absolute;
    right: 0;
    height: 30px;
    width: 30px;
    background: #f5f5f5;
    color: #ff0000;
    cursor: pointer;
    border-radius: 2px;
}

Answer №1

Check out this different placement of icon and image: https://jsfiddle.net/jthy3q0o/2/

HTML

<div class="col-3">
    <h5>Dashboard Background</h5>
    <div class="image">
        <span class="icon-image-delete"></span>
        <img class="img-thumbnail img-fluid" src="https://1.img-dpreview.com/files/p/TC190x190S190x190~sample_galleries/9912837935/2779432071.jpg" alt="No Background" />
    </div>
</div>

CSS

.image {
  position: relative;
  width: 190px;
  height:190px;
}

.icon-image-delete:before {
    position: relative;
    vertical-align: middle;
    display: inline-block;
    font-family: FontAwesome;
    content: "\f014";
    font-size: 20px;
    position: absolute;
    padding: 10px;
    right: 0;
    background: #f5f5f5;
    color: #ff0000;
    cursor: pointer;
    border-radius: 2px;
}

Answer №2

Getting closer! Almost there. Just remember to include the following in .icon-image-delete:after

text-align: center;
top: 0;

The text-align: center property centers the icon

And don't forget top: 0; to position it on top (since you already have right: 0 for top right positioning)

.icon-image-delete {
  position: relative;
  vertical-align: middle;
  display: inline-block;
}

.icon-image-delete:after {
  font-family: FontAwesome;
  content: '\f014';
  font-size: 20px;
  position: absolute;
  text-align: center;
  top: 0;
  right: 0;
  height: 30px;
  width: 30px;
  background: #f5f5f5;
  color: #ff0000;
  cursor: pointer;
  border-radius: 2px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />

<div class="col-3">
  <h5>Dashboard Background</h5>
  <div class="image">
    <div class="icon-image-delete">
      <img class="img-thumbnail img-fluid" src="http://placehold.it/550x450" alt="No Background" />
    </div>
  </div>
</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

What is the best way to retrieve JSON data values for buttons that have been clicked and files that have

Is there a way to retrieve JSON data only for clicked buttons and uploaded files? Currently, I am receiving all button values, whether clicked or not, in one instance, and file paths with fake paths like C:\\fakepath\\test.txt in anothe ...

Employing negative margin to connect div1 to the left side of div2

Is there a way to attach a dismiss button to the left of a contact in a sidebar? I am trying to achieve a layout similar to the one shown in this image: https://i.sstatic.net/jJE3h.png I attempted using margin-left: -50px; or left: -50px;, but the dismiss ...

Having difficulty changing placeholder text style in Scss

I'm a newcomer to SCSS and I'm attempting to customize the color of my placeholder text from light gray to dark gray. Below is the HTML code snippet: <div class="form-group"> <textarea class="thread-textarea" ng-maxlength="255" ma ...

Develop a stylish contact form using a mixture of HTML5, Bootstrap, and Php

On my website, I have created a contact us form using HTML, Bootstrap, and PHP. The form functions correctly, and messages are successfully received. However, the issue is that upon clicking the submit button, a new page opens up displaying a "Thank you me ...

difficulties encountered when implementing a sticky footer with two distinct footer sections

Currently, I am teaching myself web development and reconstructing a website from scratch. The layout should resemble the following: ===========Navigation Bar=========== =========Website Content=========== ===========Footer #1============ ===========Fo ...

Hide the border on a table with CSS

I recently installed a Wordpress Template and customized the table's background and text colors. However, I am struggling to remove the border around the table. Despite searching for solutions, my limited CSS knowledge has not led me to a fix that wor ...

Achieving Perfect Alignment in HTML Tables

I have created a simple HTML table and I am trying to center it vertically in the middle of the page based on the user's device height. So far, I have tried adding a div with 100% height and width, positioning the table at 50% from the top and left, b ...

`Animate your divs with slide in and slide out effects using

Currently, I am in the process of replicating a website and facing some challenges. This site is my inspiration for the project. I have managed to create a sliding effect using CSS, making the div slide in and out from the same direction. However, I want ...

If the value stored in $_SESSION['uname'] is not "teacher", redirect back to the homepage

I am currently working on a webpage and I want to restrict access to only users with the username "teacher". I came across this code snippet: <?php session_start(); if(!isset($_SESSION['uname'])){ header('location:(main p ...

What is the best way to change the folder name when hovering over it?

Typically, my website displays categories with images from the /thumb-min/ directory. For example, 95-IMG_6509.JPG is loaded like this: /thumb-min/95-IMG_6509.JPG When I navigate to the details page, it loads the image from: /thumb-medium/95-IMG_6509.JP ...

How come the hidden container does not reappear after I click on it?

I'm having an issue with a hidden container that holds comments. Inside the container, there is a <div> element with a <p> tag that says "Show all comments". When I click on this element, it successfully displays the comments. However, cli ...

The Jade template is not rendering the page correctly as anticipated

I'm working with Node.js & express, using the Jade template for the view. My issue is that the Test text is currently hidden under the black navigation bar. How can I move it to the bottom, below the navbar? What am I missing in my code? Here is the ...

How can you declare variables in CSS using LESS?

I am facing a challenge where I need to dynamically change the branding color and other styling variables on the portal based on certain conditions at runtime. I have successfully implemented this functionality using CSS with the code snippet provided be ...

Creating a dynamic PHP navigation menu with Bootstrap 4 sub-menus

ORIGINAL QUESTION I am struggling with creating a navigation menu in PHP using Bootstrap 4. The issue I'm facing is that one of the <li> elements, specifically the one with the class dropdown, is not behaving as expected. Instead of turning int ...

Tips for correcting the sentence that extends beyond the boundaries of the Material UI box

Utilizing Material UI for my project... I am trying to contain the text within a box but facing issues with responsiveness as the text is overflowing outside of the box. Note: I have attempted various solutions from Stack Overflow such as word-wrap, max- ...

Clicking on a specific month results in displaying only one row from the database rather than showing all rows associated with that particular month

I am facing an issue with my calendar feature on the website. The problem is that when I click on a specific month, it should display all the data associated with that particular month. However, the current code does not seem to work as expected. For insta ...

Looking for a way to manipulate the items in my cart by adding, removing, increasing quantity, and adjusting prices accordingly. Created by Telmo

I am currently working on enhancing telmo sampiao's shopping cart series code by adding functionality for removing items and implementing increment/decrement buttons, all while incorporating local storage to store the data. function displayCart(){ ...

Tips for altering the appearance of a button when moving to a related page

I have a master page with four buttons that have a mouse hover CSS property. Each button's corresponding response page is defined on the same master page. Now, I want to change the button style when the user is on the corresponding page. How can this ...

Is the Bootstrap Carousel not automatically scrolling when navigating back in Angular?

Whenever I launch my Angular application, the image slider implemented using Bootstrap carousel functions properly. However, upon navigating to another view and returning to the image slider, it no longer auto-slides. Even though I can manually navigate th ...

Tips on showcasing Javascript filter outcomes after at least 2 characters have been entered

Currently, I have implemented a filter search box that displays results as soon as a single letter is inputted. However, due to the large amount of data that needs to be filtered through, I would like the search to only show results when a minimum of two l ...