gpt4 book ai didi

html - 如何实现自下而上的过渡

转载 作者:行者123 更新时间:2023-11-27 23:18:39 25 4
gpt4 key购买 nike

我想让标题和内容在悬停时向上移动到正确的位置。

问题是 Title 类的转换不起作用,悬停效果也不起作用。

我尝试做的是更改悬停,以便当我将鼠标悬停在 ImageText 类上时,标题和内容都转到 top: 0;position:relative;这有效,但转换无效。但这里的问题是我不应该将鼠标悬停在 ImageText 上。我应该将鼠标悬停在 Title 类上,但是当我尝试这个时,转换不起作用。

.Section {
display: grid;
grid-template-columns: 1fr 5fr 1fr;
transform: translateY(30px);
}

.Column2 {
grid-column: 2;
display: grid;
grid-template-rows: 200px 200px 200px;
grid-gap: 1em;
}

.two {
grid-row: 2;
display: grid;
grid-template-columns: 1fr 1fr 2fr;
grid-column-gap: 1em;
}

.ImageText {
position: relative;
background-size: 100%;
color: white;
overflow: hidden;
transition: 0.5s;
height: 100%;
}

.Title:hover+.Content {
position: relative;
top: 0;
}

.Content:hover {
position: relative;
top: 0;
}


/* .Title:hover {
position: relative;
top: 0;
} */

.Content:hover+.Title {
position: relative;
top: 0;
}

.Title {
background-color: rgba(0, 0, 0, 0.6);
font: caption;
position: absolute;
bottom: 0;
width: 100%;
transition: 0.5s;
}

.Content {
background-color: rgba(0, 0, 0, 0.6);
position: absolute;
top: 100%;
height: inherit;
transition: 0.5s;
}
<div class="Section">

<div class="Column2">

<div class="two">

<div class="ImageText" style="background-image:url(https://i.ibb.co/6Rvr53T/1.jpg)">

<div class="Title">
SpaceX's Next Starship Prototype Taking Shape
</div>

<div Class="Content">
Construction of the test craft is proceeding apace, as two new photos posted on Twitter today (Sept. 17) by company founder and CEO Elon Musk reveal.
</div>

</div>

<div class="ImageText" style="background-image:url(https://i.ibb.co/F87mkdk/3.jpg)">

<div class="Title">
NASA's Juno Mission Cheks Out Eclipse on Jupiter
</div>

<div Class="Content">
All is well on our largest neighbor; NASA's Juno spacecraft just managed to spot the shadow of Jupiter's moon, Io, passing over its marbled clouds.
</div>

</div>

<div class="ImageText" style="background-image:url(https://i.ibb.co/yRMWZQ5/4.jpg)">

<div class="Title">
Europe Wants Ideas for Cave-Spelumking Moon Robots
</div>

<div Class="Content">
As NASA makes a big push to land humans on the moon's surface by 2024, the European Space Agency (ESA) wants to learn more about the lunar caves that lie beneath.
</div>
</div>
</div>
</div>
</div>

结果应该是,当你将鼠标悬停在标题上时,标题和内容都应该上升到 top:0; 并且这个效果应该有 transtion:0.5s;

解决方案应该使用 CSS 而不是 JavaScript。

最好在运行代码片段时转到完整页面,以便更好地可视化问题。

最佳答案

试试这个或那个。将内容 block 放在标题 block 中。

    .Section {
display: grid;
grid-template-columns: 1fr 5fr 1fr;
transform: translateY(30px);
}

.Column2 {
grid-column: 2;
display: grid;
grid-template-rows: 200px 200px 200px;
grid-gap: 1em;
}

.two {
grid-row: 2;
display: grid;
grid-template-columns: 1fr 1fr 2fr;
grid-column-gap: 1em;
}

.ImageText {
position: relative;
background-size: 100%;
color: white;
overflow: hidden;
transition: 0.5s;
height: 100%;
}

.Title {
background-color: rgba(0, 0, 0, 0.6);
font: caption;
position: absolute;
bottom: 0;
width: 100%;
}

.Title .Content {
max-height: 0;
transition: max-height 0.25s;
overflow: hidden;
}

.Title:hover .Content {
max-height: 500px;
transition: max-height 0.5s;
overflow: hidden;
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<link rel="stylesheet" href="./Style.css" />
</head>

<body>


<div class="Section">

<div class="Column2">

<div class="two">

<div class="ImageText" style="background-image:url(https://thenypost.files.wordpress.com/2019/09/ap_19265088288587.jpg)">
<div class="Title">
SpaceX's Next Starship Prototype Taking Shape
<div class="Content">
Construction of the test craft is proceeding apace, as two new photos posted on Twitter today (Sept. 17) by
company founder and CEO Elon Musk reveal.
</div>
</div>
</div>

<div class="ImageText" style="background-image:url(https://thenypost.files.wordpress.com/2019/09/ap_19265088288587.jpg)">

<div class="Title">
NASA's Juno Mission Cheks Out Eclipse on Jupiter
<div Class="Content">
All is well on our largest neighbor; NASA's Juno spacecraft just managed to spot the shadow of Jupiter's
moon, Io,
passing over its marbled clouds.
</div>
</div>



</div>

<div class="ImageText" style="background-image:url(https://thenypost.files.wordpress.com/2019/09/ap_19265088288587.jpg)">

<div class="Title">
Europe Wants Ideas for Cave-Spelumking Moon Robots
<div Class="Content">
As NASA makes a big push to land humans on the moon's surface by 2024, the European Space Agency (ESA) wants
to learn
more about the lunar caves that lie beneath.
</div>
</div>

</div>
</div>
</div>
</div>
</body>

</html>

关于html - 如何实现自下而上的过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58140967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com