Remove option located on the upper right corner

My goal is to display a delete icon when the user hovers over an image. The hover effect is working fine, but I'm struggling to position the x button in the top right corner of the image.

HTML

<div class="photos">
    <div id="images">
        <a href=# data-lightbox="roadtrip">
            <img class=img width=100 height=100 alt='Unable to View' src=""></a>

        <a href="#" class="del_photo" id=""><img src="images/icon_del.gif" border="0" /></a>
    </div>
</div>

CSS

#images {
    display: inline-block;
    float: left;
    width: 100px;
    height: 100px
}

.del_photo {
    display: inline-block;
    float:right;
    margin:5px 5px 0 0;
}

http://jsfiddle.net/jHG9v/

Answer №1

To make things simpler, consider using a relative position for your container and placing the close button in an absolute position (refer to this example):

#images {
    display: inline-block;
    float: left;
    width: 100px;
    height: 100px;
    position: relative;
}

.del_photo {
    display: inline-block;
    float:right;
    margin:5px 5px 0 0;
    position: absolute;
    top: 0;
    right: 0;
}

Answer №2

Utilize position:relative; and position:absolute; as demonstrated in this sample: http://jsfiddle.net/Y75va/

update

Refer to @Alexander Kludt's response for the complete code and further details.

Answer №3

Update your CSS with the following code.

#gallery {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 200px;
    height: 200px;
}

.remove_image {
    position: absolute;
    top: 0;
    right: 0;
}

Answer №4

If you're looking to experiment with CSS, check out this code snippet

Here's a sample of CSS code:

#images {

    float: left;
    width: 100px;
    height: 100px;
    position: relative
}

.del_photo {
    position: absolute;
    right: 0;
    top: 0;
    float:right;
    margin:5px 5px 0 0;
}

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

Displaying a specific section of HTML only if a certain resource bundle key is present

Working with JSF and needing to load a bundle named Extra, I have encountered an issue. <f:loadBundle basename="com.ni.lib.extra.delivery.ExtraBundle" var="extra" /> Within the variable "extra", there exists a value known as downtime_notice. To imp ...

Is there a way to distinguish between two URL requests originating from separate HTML pages but sharing the same namespace within views.py?

In order to familiarize myself with django, I am in the process of creating a basic e-commerce website similar to eBay. To allow users to remove an item from their watchlist, I have included two identical links in separate HTML files. These links enable us ...

Tips for adjusting text color in a paragraph based on its content

I have a paragraph or h1 with phrases like "the color of this item is Magenta" or "this output is Red". These color-specific words (red, black, cyan, magenta or yellow) may appear within the paragraph or h1 tag. Here is my current code snippet: HTML < ...

What is the best way to center a Bootstrap login form within the viewport?

Struggling to get the login view centered on the screen, no matter what I try. As a newcomer to Bootstrap and coding, it's proving to be a challenge. Attempts to use align items center and justify haven't yielded the desired result. <h2 style ...

Guide on integrating React.js into an HTML development webpage

I can't seem to get this code to work properly. I have saved it as an .html file on my computer, but it's not displaying anything when I try to open it in Google Chrome. <DOCTYPE! html> <html> <head> <script src= ...

Extremely efficient CSS utility classes for supreme performance

I've noticed the rise of CSS utility classes and I'm curious about their impact on performance. Is there a better approach? Option One - creating HTML elements with multiple utility classes like: <div class="padding flex justifyCenter align ...

What is the best way to ensure that my Bootstrap 4 columns occupy the full width of the row?

I started by creating a dynamic full-width border gradient. Now, I'm trying to replicate the layout with two large containers side by side, just like in Adobe XD. However, I'm facing an issue with increasing the width of the containers. Here are ...

Tips for activating list-groups upon clicking in Angular 5

I am currently experimenting with Bootstrap list-groups and Angular 5. I have encountered an issue where clicking on a specific item in the list-group activates all items instead of just the one clicked. Is there a way to enable only the clicked item in ...

Styling the Web with CSS in Django 2.0

I have a teammate who wrote some HTML code with CSS/Bootstrap. Now I am trying to render it in Django, but it's not displaying properly. It works fine as an HTML file, though. <meta charset="utf-8"> <meta name="viewport" content="width=devic ...

Numerous attributes for displaying ngOption values

I have an item that resembles the following: $scope.team = [ { name: "John", number: 1 }, { name: "Emma", number: 2 } ]; Currently, in my HTML code, I am using ngOption to populate a dropdown menu with values from the object. < ...

Developing a vertical accordion menu with AngularJS

Looking to create a sleek vertical accordion menu using a combination of angularjs, jquery, and css. If anyone has expertise in this area, I would greatly appreciate some guidance on how to integrate these technologies seamlessly. Your assistance is much ...

"Exploring the World of String Slicing in JavaScript

export class PricingValues{ amount : string; } const PRICING_VALUES : PricingValues[] =[ {amount :'$10,000'},{amount :'$20,000'},{amount :'$30,000'},{amount :'$40,000'},{amount :'$50,000'} ...

I am looking to remove the target attribute from an anchor tag if it does not have a value assigned

To ensure W3C validation, I must remove the target attribute from all anchors where the target value is null. Here is the code snippet inside the body: <div> <a href="#" target="">home empty</a> <a href="#" target="blank">home&l ...

Clicking the button will remove any previously applied CSS style using jQuery

Is there a way to remove the background color that was applied to a previously clicked button when clicking on another button? The current code successfully changes the background color of the clicked button upon hover, but it doesn't reset or remove ...

Using Javascript or jQuery to trigger a Bootstrap Alert when a button is clicked

I have developed a registration form page using asp.net. Upon clicking the Submit button, I want to display a Bootstrap alert message at the top of the page for 5 seconds, saying "Registered Successfully"". If the user attempts to submit without filling ...

Utilizing personalized icons through importing a font in CSS

Looking to incorporate an icon into my CSS using the @import feature from a specific font found on . However, I'm encountering issues with the icon not loading properly. Any suggestions on what might be going wrong here? Thank you in advance! <div ...

Positioning a logo in HTML/CSS so that it remains fixed at the top left corner regardless of the screen size

So, I'm facing a bit of a challenge here! I'm working on coding a website with HTML/CSS and I want the logo to remain fixed at the top left corner. The issue arises when resizing the browser window on a Windows machine – my logo ends up getting ...

Retrieve the content of a single text box and display it in a div named "output" by clicking a button using ajax

<script type="text/javascript"> document.getElementById('s1').onclick=function() { var value1 = document.getElementById('input').value; var aj; if(window.ActiveXObject) { aj=new ActiveXObject("Microsoft.XMLHTTP"); } if(window. ...

Continuous loop of rotating background images

I've created a design with an image in the background using the following CSS: body { width: 1000px; margin: 0 auto; background: url('/images/bg.jpg') top center no-repeat; background-attachment: scroll; } The image is 2000px in wi ...

Child Component featuring an Accordion group implemented with ngx-bootstrap

Primary Component <input type="button" class="btn btn-primary" (click)="allExpanded = !allExpanded" [attr.value]="allExpanded ? 'Collapse All': 'Expand All'" > <div class=& ...