search
HomeWeb Front-endCSS TutorialShare an example of using pure CSS to display image effects on mouse hover

Here I would like to recommend an example of using pure CSS to achieve the effect of displaying images on mouse hover. It is demonstrated in the simplest way of adding hover by moving the mouse to the tr tag. It is simple and clear. Friends who need it can refer to it.

Recently I am working on a network disk project, using the effect of moving the mouse up. This effect can be achieved with js. Today I will mainly share how to achieve this effect with pure css!

The effect is as shown below:
Share an example of using pure CSS to display image effects on mouse hover

html code

<table id="filelist" style="width:100%;">
   <tbody>
        <tr>
            <td class="filename ui-draggable ui-droppable"  width="30%;">
                <p class="name">
                    <span class="fileactions">
                        <a href="#" class="action action-download" data-action="Download" original-title="">
                            <img  class="svg lazy"  src="/static/imghwm/default1.png"  data-src="svg/download.svg"    alt="Share an example of using pure CSS to display image effects on mouse hover" >
                            <span>下载</span>
                        </a>
                        <a href="#" class="action action-share permanent" data-action="Share" original-title="">
                            <img  class="svg lazy"  src="/static/imghwm/default1.png"  data-src="svg/public.svg"    alt="Share an example of using pure CSS to display image effects on mouse hover" >
                            <span>已共享</span>
                        </a>
                    </span>
                </p>
            </td>
            <td class="filesize" style="color:rgb(-4780,-4780,-4780)">70.3 MB</td>
            <td class="date">
                <span class="modified" title="September 29, 2014 14:45" style="color:rgb(0,0,0)">2 分钟前</span>
                <a href="#" original-title="删除" class="action delete delete-icon"></a>
            </td>
        </tr>

        <tr >
            <td class="filename ui-draggable ui-droppable"  width="30%;">
                <p class="name" >
                    <span class="fileactions">
                        <a href="#" class="action action-download" data-action="Download">
                            <img  class="svg lazy"  src="/static/imghwm/default1.png"  data-src="svg/download.svg"    alt="Share an example of using pure CSS to display image effects on mouse hover" >
                            <span>下载</span>
                        </a>
                        <a href="#" class="action action-share" data-action="Share">
                            <img  class="svg lazy"  src="/static/imghwm/default1.png"  data-src="svg/share.svg"    alt="Share an example of using pure CSS to display image effects on mouse hover" >
                            <span>分享</span>
                        </a>
                    </span>
                </p>
            </td>
            <td class="filesize" style="color:rgb(159,159,159)">762 kB</td>
            <td class="date">
                <span class="modified" style="color:rgb(0,0,0)" original-title="September 29, 2014 16:36">2 分钟前</span>
                <a href="#" original-title="删除" class="action delete delete-icon"></a>
            </td>
        </tr>
        </tbody>
</table>

I copied the above code directly from the project, there may be a lot of redundancy css, everyone just takes a look at the general code!

Essential css

The general idea of ​​implementing the effect in the picture is to set it to opacity=0 at the beginning, and then display it after the mouse is moved up.

The code is as follows:

#filelist a.action {   
    display: inline;   
    padding: 18px 8px;   
    line-height: 50px;   
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";   
    filter: alpha(opacity=0);   
    opacity: 0;   
    display:none;   
}   
#filelist tr:hover a.action , #filelist a.action.permanent{   
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";   
    filter: alpha(opacity=50);   
    opacity: .5;   
    display:inline;   
}   
#filelist tr:hover a.action:hover {   
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";   
    filter: alpha(opacity=100);   
    opacity: 1;   
    display:inline;   
}

The above is the approximate essence of the code!

css skill analysis

Move the tr mouse up, and the a tag below shows that you can choose like this #filelist tr:hover a.action Add tr and move the mouse up to hover, Then the effect of moving the mouse up on the a tag under tr is also useful. Write like this: #filelist tr:hover a.action:hover

There is attr in jquery, and the attributes of the active tag, css can also be the same as jquery Similar options.

For example, in the following a tag

<a href="#"  data-action="Rename"  class="action"></a>

, we can write the style like this:

 a.action[data-action="Rename"]{   
    padding: 16px 14px 17px !important;   
    position: relative;   
    top: -21px;   
}

After reading this article, Did you gain something? I wonder if you have a closer understanding of CSS through this article!

The above is the detailed content of Share an example of using pure CSS to display image effects on mouse hover. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Feeling Like I Have No Release: A Journey Towards Sane DeploymentsFeeling Like I Have No Release: A Journey Towards Sane DeploymentsApr 23, 2025 am 09:19 AM

Deploying like an idiot comes down to a mismatch between the tools you use to deploy and the reward in complexity reduced versus complexity added.

So, You Want to Give Up CSS Pre- and Post-Processors...So, You Want to Give Up CSS Pre- and Post-Processors...Apr 23, 2025 am 09:18 AM

There was once upon a time when native CSS lacked many essential features, leaving developers to come up with all sorts of ways to make CSS easier to write over the years.

A New 'Web' Readiness ReportA New 'Web' Readiness ReportApr 23, 2025 am 09:14 AM

HTML 5 Readiness was a site that showed through a rainbow of colors the browser support for several web features. What about a new version?

Crafting Strong DX With Astro Components and TypeScriptCrafting Strong DX With Astro Components and TypeScriptApr 23, 2025 am 09:10 AM

One thing we can do to help teams code consistently is provide type-checking so that all of the configurable options for a specific component are available while coding. Bryan demonstrates how he does this with TypeScript when working with Astro comp

Simulating Mouse MovementSimulating Mouse MovementApr 22, 2025 am 11:45 AM

If you've ever had to display an interactive animation during a live talk or a class, then you may know that it's not always easy to interact with your slides

Powering Search With Astro Actions and Fuse.jsPowering Search With Astro Actions and Fuse.jsApr 22, 2025 am 11:41 AM

With Astro, we can generate most of our site during our build, but have a small bit of server-side code that can handle search functionality using something like Fuse.js. In this demo, we’ll use Fuse to search through a set of personal “bookmarks” th

Undefined: The Third Boolean ValueUndefined: The Third Boolean ValueApr 22, 2025 am 11:38 AM

I wanted to implement a notification message in one of my projects, similar to what you’d see in Google Docs while a document is saving. In other words, a

In Defense of the Ternary StatementIn Defense of the Ternary StatementApr 22, 2025 am 11:25 AM

Some months ago I was on Hacker News (as one does) and I ran across a (now deleted) article about not using if statements. If you’re new to this idea (like I

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)