我希望在 HTML/CSS 手风琴上添加指向影像的单个链接 - 但是,每次我将 img-source 包装在标签中时,影像块的格式都会受到影响。
不带标签的代码如下:
https://codepen.io/knyttneve/pen/YgZbLO
<style>
.container {
display: flex;
width: 100%;
padding: 4% 2%;
box-sizing: border-box;
height: 100vh;
}
.box {
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 > 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%;
}
</style>
<h1>Accordion Slider</h1>
<div class="accordion">
<!-- BOX 1 -->
<div class="box a1">
<div class="image_1">
<div class="text">
<h2>Lorem Ipsum</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum iaculis nisl sed dictum aliquam.
</p>
</div>
</div>
</div>
<!-- BOX 2 -->
<div class="box a2">
<div class="image_2">
<div class="text">
<h2>Lorem Ipsum</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum iaculis nisl sed dictum aliquam.
</p>
</div>
</div>
</div>
<!-- BOX 3 -->
<div class="box a3">
<div class="image_3">
<div class="text">
<h2>Lorem Ipsum</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum iaculis nisl sed dictum aliquam.
</p>
</div>
</div>
</div>
<!-- BOX 1 -->
<div class="box a4">
<div class="image_4">
<div class="text">
<h2>Lorem Ipsum</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum iaculis nisl sed dictum aliquam.
</p>
</div>
</div>
</div>
<!-- BOX 5 -->
<div class="box a5">
<div class="image_5">
<div class="text">
<h2>Lorem Ipsum</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum iaculis nisl sed dictum aliquam.
</p>
</div>
</div>
</div>
</div>
这是带有标签的样子: Accordion Error
在不影响块格式的情况下,添加图片源链接的方法是什么?
uj5u.com热心网友回复:
.box > img
属性转到包装锚标记。并且.box:hover > img
必须更改为.box:hover > a
. 仅包含 CSS 的更改部分。
<div class="container">
<div class="box">
<a href="#">
<img src="https://source.unsplash.com/1000x800">
</a>
<span>CSS</span>
</div>
<div class="box">
<a href="#">
<img src="https://source.unsplash.com/1000x802">
</a>
<span>Image</span>
</div>
<div class="box">
<a href="#"><img src="https://source.unsplash.com/1000x804"></a>
<span>Hover</span>
</div>
<div class="box">
<a href="#"> <img src="https://source.unsplash.com/1000x806"></a>
<span>Effect</span>
</div>
</div>
.box > a {
display: inline-block;
width: 200%;
height: calc(100% - 10vh);
transition: .5s;
}
.box > a > img {
width: 100%;
height: 100%;
object-fit: cover;
transition: .5s;
}
.box:hover > a {
width: 100%;
height: 100%;
}
uj5u.com热心网友回复:
而不是扭曲你的盒子作为<div>
用标签包装它<a>
并将box
类添加到它,这应该作业。
0 评论