Enlarge Django thumbnail when hovering over it in Django admin console

Looking to incorporate a CSS hover effect into this Django admin function that shows a thumbnail in the admin area. The goal is to enlarge the image when hovered over.

def image_tag(self):
        if self.image:
            return mark_safe('<img src="%s" style="width: 50px; height:40px;" />' % self.image.url)
        else:
            return 'No Image Found'
    image_tag.short_description = 'Image'

Answer №1

To ensure the image doesn't disrupt the layout when magnified, I suggest wrapping it in a or another element. You can then set the image's position to absolute on hover.

If you want to see an example of this in action, check out this codepen: https://codepen.io/darthrubens/pen/Zqgwoa

.profile-pic-wrapper {
  width: 60px;
  height: 90px;
  cursor: pointer;
}

.profile-pic-wrapper img {
  position: relative;
  width: 60px;
}

.profile-pic-wrapper:hover img {
  position: absolute;
  width: 120px;
}
<div class="profile-pic-wrapper">
  <img src="https://media.bizj.us/view/img/10179818/nicolascage2011cc*750xx617-823-17-0.jpg" />
</div>
<div>
  Some other content
</div>

Answer №2

To set up a static directory within your Django application, follow these steps: create a folder named "static" inside your app's directory, then another folder with the name of your app, followed by subfolders for CSS files (e.g., app_name/css/style.css).

In your admin.py, include the following code snippet to link the stylesheets:

class Media:   
    css = {
     'all': ('app_name/css/style.css',)
    }

This should be placed inside the model admin section. Here is an example:

class ModelNameAdmin(admin.ModelAdmin):
      class Media:   
             css = {
             'all': ('app_name/css/style.css',)
            }

You can now start writing your custom CSS within the designated files.

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

Learn how to dynamically toggle the visibility of tabs in CodeMirror with a simple button click

Currently, I am developing a Python editor for a website using the Code Mirror JavaScript library. There is a button called toggle invisibles that, when clicked, displays spaces and end-of-line markers. I also wanted to show tabs, which are not supported b ...

Laravel 4.2 email template not applying CSS inline style for text color

Working on setting up email functionality in Laravel 4.2 and I've got an email template ready to go. The data for the emails is stored in an array, but I'm running into an issue where if I pass a parameter like $variable, the styles are only bein ...

Making sure that a footer div is consistently positioned at the bottom of the container div, regardless of the dimensions of the other elements

I am facing a challenge with a container div which has child elements. <div class='wrapper'> <div class='content'></div> <div class='footer'></div> </div> The height o ...

Run Django fixtures when creating a table

Is there a way to run a Django fixture only when the relevant table is created? I have some initial data that needs to be inserted into the app tables, but after the tables are in place, I don't want the data to be refreshed every time ./manage.py syn ...

CSS positioning alignment

Could someone please explain to me why changing the position to relative causes the "facebook and Facebook helps you connect and share with the people in your life" text to display at the top of the page? I've only been studying CSS for three days. Th ...

Having trouble with the page background image link not functioning properly because of the wrapper

I am facing an issue with my HTML layout. I have a full background image set within the body tag, followed by a wrapper element: <body> <a href="#" id="bkimage">Background Image</a> <wrapper> ................. Here are the styles ...

Wrapper Div at the Center

I'm currently working on aligning my webpage in the center using the following CSS: .wrapper { display: flex; align-items: stretch; background: #fafafa; /*max-width: 1520px; */ box-shadow: 1px 1px 12px rgba(0, 0, 0, 0.1); text ...

Creating visual representations of data using graphs in PHP or HTML

I am in search of a very specific method. To sum it up: I require HTML code that can produce a line chart, similar to the one shown below (minus the background image, as it is irrelevant). However, I want to achieve this using only HTML, without relying ...

Can someone explain why I still see a broken image icon despite setting the content-type to "image/jpeg"?

Perhaps this question seems trivial, but I would really appreciate a helpful answer. I am familiar with what an http header is and how it can be modified using the header function in PHP. Let's say I have a PHP file named an_image.php with the followi ...

In the latest version of Bootstrap, the carousel has been redesigned to smoothly transition across the entire page, providing a

I am currently in the process of learning Bootstrap 5 and decided to create a simple carousel by referring to the official documentation on Bootstrap 5 Carousel. Following their instructions, I copied their code and integrated it into my template. Howeve ...

Looking for a way to exclude both parents and children from a list of relatives? Want to ensure that the

I've been struggling to align these list elements with their counterparts, but they seem to automatically create a margin for their child elements. It is essential for these list items to maintain the position:relative attribute so that the #dropdown ...

Embedding a CSS file into a PHP class

I've encountered a little issue that I can't seem to solve on my own. I've put together a "webengine" using multiple classes. The primary class responsible for obtaining a theme's internals is called "Logic". This Logic class contain ...

How to make a static div adjust its size in the presence of a neighboring div

I am looking to create a feature where the user can click a button to reveal a new div to the right of an existing one. Check out this Fiddle for reference: http://jsfiddle.net/AV2mZ/. While the functionality works fine when both divs are visible, resizin ...

Methods to validate CSS attributes specified within a class using React testing library

I am struggling to validate the CSS properties defined within a class in CSS using the React Testing Library. Unfortunately, I am facing challenges in doing so. Here are the simplified code snippets: import React from "react"; import { render, ...

Adjusting the content and style of a div element upon clicking, and restoring the original settings when clicked once more

There is a div with the id #increase-text-weight that displays the text "INCREASE TEXT WEIGHT". Upon clicking on it, the font weight of another div with the id #post-content should be changed to font-weight: 500 and the text inside #increase-text-weight s ...

What is the best way to style a tooltip in an ASP.NET application using CSS?

protected void grd_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { foreach (TableCell cell in e.Row.Cells) { ...

Issues with the FlexBox styling of Bootstrap 4 Modals in Internet Explorer causing malfunction

I have designed a confirmation dialog using Bootstrap 4 with the following code snippet: <div class="modal fade show" id="completeAlertDialogue" role="dialog" style="display: block;"> <div class="modal-dialog"> <div class="modal-co ...

Text overlapping image causing hover state interference

I'm feeling completely lost right now. My goal is to have the title of each project displayed in the center of the screen when you hover over the respective project images. I've resorted to using jQuery for this because it seems like the most str ...

What is the best method for designing a filtering menu with a "Narrow By" option?

Looking to create a sidebar menu similar to the functionality on mcmaster.com. This specific feature allows users to efficiently filter products and toggle through different options dynamically. Upon selecting the "metric" option, the entire page adjusts t ...

`When is the right time to get a new image?`

On my server, I have over 350 images stored. When a user attempts to view one of these images that is older than 5 minutes, I want my server to check with another website from which I am mirroring data (as they require me to mirror instead of hotlinking) i ...