gpt4 book ai didi

html - 在幻灯片图像旁边添加文本

转载 作者:太空宇宙 更新时间:2023-11-04 07:37:36 25 4
gpt4 key购买 nike

这是一段代码,我对其进行了一些修改,以便仅使用 HTML 和 CSS 制作带有图像的简单幻灯片:

(此为部分代码,查看全部请点击demo)

代码:

.slideshow {
width: 800px;
margin: 0 auto;
overflow: hidden;
border: solid 1px white;
}

.slideshow-container {
width: 2500px;
font-size: 0;
transition: 1s ease;
height: 225px;
}

@keyframes slide {
0% {
transform: translateX(0%);
}
12.5% {
transform: translateX(0%);
}
25% {
transform: translateX(-25%);
}
37.5% {
transform: translateX(-25%);
}
50% {
transform: translateX(-50%);
}
62.5% {
transform: translateX(-50%);
}
75% {
transform: translateX(-75%);
}
87.5% {
transform: translateX(-75%);
}
99% {
transform: translateX(-75%);
}
100% {
transform: translateX(0);
}
}
<section class="slideshow">
<div class="slideshow-container slide">
<img src="http://placeimg.com/625/225/any" />
<img src="http://placeimg.com/625/225/animals" />
<img src="http://placeimg.com/625/225/arch" />
</div>
</section>

demo

我想在每个图像旁边添加一个文本,所以在框架中我将有一半图像和另一半文本。我怎样才能做到这一点?

最佳答案

您会将imagetext 部分包装到.item div 中。

display:flex 应用于父级 .slideshow-container 以连续设置 .item

然后只需将 width:50% 应用到您的 img.caption div 以使它们与屏幕的一半对齐

还根据连续3项更改了动画动画分区值

Fiddle Link

堆栈片段

/*general styles*/

body {
padding: 3em;
background-color: #ccc;
}

html {
box-sizing: border-box;
}

*,
*:before,
*:after {
box-sizing: inherit;
}


/*slideshow styles*/

.slideshow {
width: 800px;
margin: 0 auto;
overflow: hidden;
border: solid 1px white;
}

.item {
display: flex;
width: 800px;
align-items: center;
}

.slideshow-container {
width: 2400px;
transition: 1s ease;
display: flex;
}

.slideshow-container:hover {
animation-play-state: paused;
}

.slide {
animation: slide 24s ease infinite;
}

@keyframes slide {
0% {
transform: translateX(0%);
}
25% {
transform: translateX(0);
}
37.5% {
transform: translateX(-33.333%);
}
62.5% {
transform: translateX(-33.333%);
}
75% {
transform: translateX(-66.667%);
}
99% {
transform: translateX(-66.667%);
}
100% {
transform: translateX(0);
}
}

.item img {
width: 50%
}

.item .caption {
width: 50%
}
<!--hovering over the images will pause the slideshow -->

<section class="slideshow">
<div class="slideshow-container slide">
<div class="item">
<img src="http://placeimg.com/625/225/any" />
<div class="caption">Text</div>
</div>
<div class="item">
<img src="http://placeimg.com/625/225/animals" />
<div class="caption">Text</div>
</div>

<div class="item">
<img src="http://placeimg.com/625/225/arch" />
<div class="caption">Text</div>
</div>
</div>
</section>

关于html - 在幻灯片图像旁边添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48809966/

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