css - Tailwind CSS:在图像悬停时显示文本
问题描述
如何使用 Tailwind CSS 在图像悬停时显示文本:在图像悬停时显示文本?
这是我的头像?我希望在用户悬停图像时显示文本“哺乳动物”?
<img src="/img/cat/categories/mammals.png" alt="mammals" class="max-w-full max-h-full">
解决方案
我更喜欢使用相对位置和绝对位置,因为它给了我更多的选择。查看此代码在悬停时显示文本
<div class="w-64 h-64 bg-red-100 relative">
<div class="absolute inset-0 bg-cover bg-center z-0" style="background-image: url('https://upload.wikimedia.org/wikipedia/en/3/3c/JumanjiTheNextLevelTeaserPoster.jpg')"></div>
<div class="opacity-0 hover:opacity-100 duration-300 absolute inset-0 z-10 flex justify-center items-center text-6xl text-white font-semibold">Dwayne</div>
</div>
推荐阅读
- javascript - 即使刷新内容,如何保留内容?
- node.js - 使用共享库的舒适方式
- php - Laravel 8:多重身份验证保护它仍然将我重定向到登录页面?
- reactjs - 如何更改 MaterialTopTabNavigator 中的活动 labelStyle?
- export - 使用 ExtendScript for Adobe Illustrator 以特定文件大小导出 PNG
- stenciljs - 模板组件的维度为零
- ruby-on-rails - YAML.load_file 无法正确读取 ENV 变量
- javascript - 在类的构造函数之外写一个字段是什么意思?
- python - 如何使用 Python Selenium 点击第一个 Yahoo 搜索结果
- javascript - 如何创建一个在 2 个事件之间跳过排放的 observable