Change a picture with a hover in css

huangapple go评论88阅读模式
英文:

Change a picture with a hover in css

问题

大家好
我在开发一个HTML文档中有一个卡片,它有一个设置的图像,但我想在鼠标悬停时将图像更改为另一个图像,当我移除鼠标时它恢复正常。
我该如何做到这一点,我已经阅读了其他帖子,但它们改变了卡片的背景,我希望在不修改卡片本身的情况下更改图像。

我尝试在卡片内部更改图像。

英文:

`Hello everyone
I have this card in an html document that I am developing, it has an image set but I want it to change the image to another when I mouse over it and when I remove it it returns to normal.
How can I do it, I have read other posts about it but they change the background of the card and I would like to change the image without modifying the card itself

 <div class="container">
                <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-6">
                    <!-- 1 Alexis -->
                    <div class="col" style="margin-bottom: 2rem;">
                        <div class="card  card-team h-100">
                            <div style="text-align: center;">
                                <img src="./src/img/nosotros/AlexisSanchez.jpeg"
                                    style="width: 150px; height: 150px; margin-top: 1rem;box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.1);"
                                    class="img-fluid rounded" alt="Alexis">
                            </div>
                            <div class="card-body">
                                <div class="title__card">
                                    <span>Alexis Sánchez León</span>
                                </div>
                                <div class="subtitle__card">
                                    <span>Desarrollador Java | Ing. Industrial</span>
                                </div>
                                <p class="card-text" style="text-align: justify;">Soy un desarrollador Java, enfocado en
                                    el frontend y en la gestión de proyectos con el marco de trabajo SCRUM para la
                                    entrega de valor oportuna.</p>
                            </div>
                            <!-- redes sociales -->
                            <div class="social__media card-footer ">
                                <a href="https://github.com/ALEXISSL10" target="_blank"><span><i
                                            class="bi bi-github social__media__icon"></i></span></a>
                                <a href="https://www.linkedin.com/in/alexis-s%C3%A1nchez-le%C3%B3n"
                                    target="_blank"><span><i class="bi bi-linkedin social__media__icon"></i></span></a>
                            </div>
                        </div>
                    </div>

`

I try to change the image inside the card

答案1

得分: 0

<!-- 开始代码片段:js 隐藏:false 控制台:true babel:false -->

<!-- 语言:lang-css -->
.static {
    position:absolute;
    background: white;
}

.static:hover {
    opacity:0;
}

<!-- 语言:lang-html -->
<div class="col" style="margin-bottom: 2rem;">
    <div class="card  card-team h-100">
        <div style="text-align: center;">
            <img src="src/img/nosotros/alexis-normal.jpg" style="width: 150px; height: 150px; margin-top: 1rem;box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.1);"
            class="img-fluid rounded static" alt="Alexis"><img class="active" src="src/img/nosotros/alexis-pintado.jpg" style="width: 150px; height: 150px; margin-top: 1rem;box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.1);"
            class="img-fluid rounded" alt="Alexis">
        </div>
        <div class="card-body">
            <div class="title__card">
                <span>Alexis Sánchez León</span>
            </div>
            <div class="subtitle__card">
                <span>Desarrollador Java | Ing. Industrial</span>
            </div>
            <p class="card-text" style="text-align: justify;">Soy un desarrollador Java, enfocado en
                el frontend y en la gestión de proyectos con el marco de trabajo SCRUM para la
                entrega de valor oportuna.</p>
        </div>
        <!-- redes sociales -->
        <div class="social__media card-footer ">
            <a href="https://github.com/ALEXISSL10" target="_blank"><span><i
                        class="bi bi-github social__media__icon"></i></span></a>
            <a href="https://www.linkedin.com/in/alexis-s%C3%A1nchez-le%C3%B3n"
                target="_blank"><span><i class="bi bi-linkedin social__media__icon"></i></span></a>
        </div>
    </div>
</div>

<!-- 结束代码片段 -->
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.static {
position:absolute;
background: white;
}
.static:hover {
opacity:0;
}

<!-- language: lang-html -->

&lt;div class=&quot;col&quot; style=&quot;margin-bottom: 2rem;&quot;&gt;
&lt;div class=&quot;card  card-team h-100&quot;&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;img src=&quot;src/img/nosotros/alexis-normal.jpg&quot; style=&quot;width: 150px; height: 150px; margin-top: 1rem;box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.1);&quot;
class=&quot;img-fluid rounded static&quot; alt=&quot;Alexis&quot;&gt;&lt;img class=&quot;active&quot; src=&quot;src/img/nosotros/alexis-pintado.jpg&quot; style=&quot;width: 150px; height: 150px; margin-top: 1rem;box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.1);&quot;
class=&quot;img-fluid rounded&quot; alt=&quot;Alexis&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;card-body&quot;&gt;
&lt;div class=&quot;title__card&quot;&gt;
&lt;span&gt;Alexis S&#225;nchez Le&#243;n&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;subtitle__card&quot;&gt;
&lt;span&gt;Desarrollador Java | Ing. Industrial&lt;/span&gt;
&lt;/div&gt;
&lt;p class=&quot;card-text&quot; style=&quot;text-align: justify;&quot;&gt;Soy un desarrollador Java, enfocado en
el frontend y en la gesti&#243;n de proyectos con el marco de trabajo SCRUM para la
entrega de valor oportuna.&lt;/p&gt;
&lt;/div&gt;
&lt;!-- redes sociales --&gt;
&lt;div class=&quot;social__media card-footer &quot;&gt;
&lt;a href=&quot;https://github.com/ALEXISSL10&quot; target=&quot;_blank&quot;&gt;&lt;span&gt;&lt;i
class=&quot;bi bi-github social__media__icon&quot;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a href=&quot;https://www.linkedin.com/in/alexis-s%C3%A1nchez-le%C3%B3n&quot;
target=&quot;_blank&quot;&gt;&lt;span&gt;&lt;i class=&quot;bi bi-linkedin social__media__icon&quot;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年8月9日 07:24:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76863698.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定