如何在没有 "breaking" animation/effect 的情况下将 link 添加到此图库中的展开图像?
How can I add a link to the expanded images in this gallery without "breaking" the animation/effect?
我正在尝试使用代码笔片段 linked 来模仿投资组合类别页面。我想将 links 添加到图像或至少每个框中,但无论我在哪里放置相应的 href 元素和结束标记,它都会以一种或另一种方式破坏画廊。
我应该将 link 4 个部分的标签分别放置在哪里?
https://codepen.io/knyttneve/pen/YgZbLO
HTML:
<div class="container">
<div class="box">
<img src="https://source.unsplash.com/1000x800">
<span>CSS</span>
</div>
<div class="box">
<img src="https://source.unsplash.com/1000x802">
<span>Image</span>
</div>
<div class="box">
<img src="https://source.unsplash.com/1000x804">
<span>Hover</span>
</div>
<div class="box">
<img src="https://source.unsplash.com/1000x806">
<span>Effect</span>
</div>
</div>
CSS:
.container {
display: flex;
width: 100%;
padding: 4% 2%;
box-sizing: border-box;
height: 100vh;
}
.box {
flex: 1;
overflow: hidden;
transition: .5s;
margin: 0 2%;
box-shadow: 0 20px 30px rgba(0,0,0,.1);
line-height: 0;
}
.box > img {
width: 200%;
height: calc(100% - 10vh);
object-fit: cover;
transition: .5s;
}
.box > span {
font-size: 3.8vh;
display: block;
text-align: center;
height: 10vh;
line-height: 2.6;
}
.box:hover { flex: 1 1 50%; }
.box:hover > img {
width: 100%;
height: 100%;
}
假设您希望每个项目都有一个 link。
HTML 变化
为每个 .box
添加了锚标签 div
<a href="#"></a>
CSS 变化
.box {
position: relative;
}
.box>a {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.container {
display: flex;
width: 100%;
padding: 4% 2%;
box-sizing: border-box;
height: 100vh;
}
.box {
position: relative;
flex: 1;
overflow: hidden;
transition: 0.5s;
margin: 0 2%;
box-shadow: 0 20px 30px rgba(0, 0, 0, 0.1);
line-height: 0;
}
.box>img {
width: 200%;
height: calc(100% - 10vh);
-o-object-fit: cover;
object-fit: cover;
transition: 0.5s;
}
.box>a {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.box>span {
font-size: 3.8vh;
display: block;
text-align: center;
height: 10vh;
line-height: 2.6;
}
.box:hover {
flex: 1 1 50%;
}
.box:hover>img {
width: 100%;
height: 100%;
}
<div class="container">
<div class="box">
<a href="#"></a>
<img src="https://source.unsplash.com/1000x800">
<span>CSS</span>
</div>
<div class="box">
<a href="#"></a>
<img src="https://source.unsplash.com/1000x802">
<span>Image</span>
</div>
<div class="box">
<a href="#"></a>
<img src="https://source.unsplash.com/1000x804">
<span>Hover</span>
</div>
<div class="box">
<a href="#"></a>
<img src="https://source.unsplash.com/1000x806">
<span>Effect</span>
</div>
</div>
我正在尝试使用代码笔片段 linked 来模仿投资组合类别页面。我想将 links 添加到图像或至少每个框中,但无论我在哪里放置相应的 href 元素和结束标记,它都会以一种或另一种方式破坏画廊。
我应该将 link 4 个部分的标签分别放置在哪里?
https://codepen.io/knyttneve/pen/YgZbLO
HTML:
<div class="container">
<div class="box">
<img src="https://source.unsplash.com/1000x800">
<span>CSS</span>
</div>
<div class="box">
<img src="https://source.unsplash.com/1000x802">
<span>Image</span>
</div>
<div class="box">
<img src="https://source.unsplash.com/1000x804">
<span>Hover</span>
</div>
<div class="box">
<img src="https://source.unsplash.com/1000x806">
<span>Effect</span>
</div>
</div>
CSS:
.container {
display: flex;
width: 100%;
padding: 4% 2%;
box-sizing: border-box;
height: 100vh;
}
.box {
flex: 1;
overflow: hidden;
transition: .5s;
margin: 0 2%;
box-shadow: 0 20px 30px rgba(0,0,0,.1);
line-height: 0;
}
.box > img {
width: 200%;
height: calc(100% - 10vh);
object-fit: cover;
transition: .5s;
}
.box > span {
font-size: 3.8vh;
display: block;
text-align: center;
height: 10vh;
line-height: 2.6;
}
.box:hover { flex: 1 1 50%; }
.box:hover > img {
width: 100%;
height: 100%;
}
假设您希望每个项目都有一个 link。
HTML 变化
为每个 .box
添加了锚标签 div
<a href="#"></a>
CSS 变化
.box {
position: relative;
}
.box>a {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.container {
display: flex;
width: 100%;
padding: 4% 2%;
box-sizing: border-box;
height: 100vh;
}
.box {
position: relative;
flex: 1;
overflow: hidden;
transition: 0.5s;
margin: 0 2%;
box-shadow: 0 20px 30px rgba(0, 0, 0, 0.1);
line-height: 0;
}
.box>img {
width: 200%;
height: calc(100% - 10vh);
-o-object-fit: cover;
object-fit: cover;
transition: 0.5s;
}
.box>a {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.box>span {
font-size: 3.8vh;
display: block;
text-align: center;
height: 10vh;
line-height: 2.6;
}
.box:hover {
flex: 1 1 50%;
}
.box:hover>img {
width: 100%;
height: 100%;
}
<div class="container">
<div class="box">
<a href="#"></a>
<img src="https://source.unsplash.com/1000x800">
<span>CSS</span>
</div>
<div class="box">
<a href="#"></a>
<img src="https://source.unsplash.com/1000x802">
<span>Image</span>
</div>
<div class="box">
<a href="#"></a>
<img src="https://source.unsplash.com/1000x804">
<span>Hover</span>
</div>
<div class="box">
<a href="#"></a>
<img src="https://source.unsplash.com/1000x806">
<span>Effect</span>
</div>
</div>