简体   繁体   English

当我悬停 img 标签以在他下方显示文本时如何制作动画

[英]How to make animation when I hover img tag to show text under him

I need to make animation when I hover img tag to show text under him (must be animate showing text, slowly) but that is not all It must also move other content down when text show and to return when text is gone (when is not hover).当我将鼠标悬停在 img 标签以在他下方显示文本时,我需要制作动画(必须是动画显示文本,缓慢地)但这还不是全部当文本显示时还必须将其他内容向下移动并在文本消失时返回(当不是徘徊)。 Very Important showing text must be animate and going back.非常重要的显示文本必须是动画的并且可以返回。 I don't care if it works with jq or css or both just need work.我不在乎它是否适用于 jq 或 css 或两者都需要工作。 I am a beginner so maybe it is obviously I just don't see it.我是初学者,所以也许很明显我只是没有看到它。

HTML: HTML:

    <div class="first-block"></div>
    <div class="secend-block">
        <div class="box">
            <img src="/Test/beach.jpg" alt="beach" width="200px" height="200px">
            <p>asdasdasssssssssssssssssssssss
                asdddddddddddddddddddddd
                asdaaaadsssssssssssadsadsdasd
                adsssssssssssssssssadsadsadsa
            </p>
        </div>
    </div>
    <div class="third-block">
        <h1>some content</h1>
        <h1>some content</h1>
        <h1>some content</h1>
        <h1>some content</h1>
    </div>

CSS: CSS:

 .first-block{
    width: 99%;
    height: 100px;
    background: #f10000;
}

.secend-block{
    width: 99%;
    height: auto;
    background: #ffffff;

}

.secend-block .box{
    width: 200px;
    padding-top: 10px;
    margin: 0px auto;
}

.secend-block .box p{
    display: none;
}

.third-block{
    width: 99%;
    height: auto;
    background: #4400ff;
}

Use .class:hover使用.class:hover

Basically, when .image is hovered, we want to change the styles of .text .基本上,当.image被悬停时,我们想要改变.text的样式。 The CSS query .image:hover + .text selects the .text the element where there is an image that is being hovered right before it. CSS 查询.image:hover + .text选择.text元素,其中有一个图像悬停在它之前。

 .image { width: 250px; } .text { max-height: 0px; overflow: hidden; transition: max-height 1s; } .image:hover + .text { max-height: 32px; }
 <div class="wrapper"> <img class="image" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg" /> <p class="text">This is some text</p> </div> <div class="wrapper"> <img class="image" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg" /> <p class="text">This is some text</p> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM