0

0

使用HTML和CSS编写幻灯片展示

WBOY

WBOY

发布时间:2023-08-19 20:25:12

|

1908人浏览过

|

来源于tutorialspoint

转载

使用html和css编写幻灯片展示

Generally, the developer uses JavaScript to add the behaviour to the HTML code. Sometimes, we can also add behaviour to the HTML code using CSS. For example, we can create a slideshow using HTML and CSS rather than using JavaScript with HTML.

We can create custom keyframes to animate the slides and create a slideshow.

语法

用户可以按照以下语法,仅使用HTML和CSS来创建幻灯片。

.slides {
   width: calc(716px * 2);
   animation: slideShow 10s ease infinite;
}
@keyframes slideShow {
   30% {margin-left: 0px;}
   70% {margin-left: calc(-716px * 1);}
}

在上述语法中,'slides' div 包含多个幻灯片。我们根据 'slides' div 包含的幻灯片总数定义了 'slides' div 的宽度。此外,我们还为幻灯片 div 添加了动画。

立即学习前端免费学习笔记(深入)”;

In the slideshow keyframes, we change the value of the ‘margin-left’ CSS property to change the slide.

步骤

步骤1 - 创建一个div元素,并给它一个'parent'类名。

Step 2 – Create a nested div element and give the ‘slides’ class name. Furthermore, create multiple nested div elements with the ‘element’ class name representing the slides.

Step 3 – Also, add the content of the slide to the div element with the class name ‘element’.

仿虎嗅网在线视频教育门户源码2.0
仿虎嗅网在线视频教育门户源码2.0

仿虎嗅商学院在线视频教育门户网站源码,织梦内核,页面简洁,容易维护修改;适合做在线教育类网站,网站模板修改简单,网站设置多个广告位方便放置广告。适用于视频网站,在线教育、在线商学院;图片展示效果极佳;网站手工div+css,代码精简,首页排版整洁大方、布局合理、利于SEO、图文并茂、静态HTML;首页和全局重新做了全面优化,方便大家无缝使用。

下载

Step 4 – Now, we require to add the CSS code for the slideshow. Give the fixed width and height to the ‘parent’ div element.

Step 5 – Set the fixed width and height for the ‘element’ div, which is our slide.

Step 6 – For the ‘slides’ div, calculate the total width according to the total number of slides it contains, and add a ‘slideshow’ animation for a particular duration.

Step 7 – Create a ‘slideshow’ keyframe which should change the value of the ‘margin-left’ CSS property to change the slides. Also, we have breakdown the percentage in the gap of 20, as we have 4 slides.

Example

在下面的示例中,我们创建了4个不同的幻灯片并添加了文本内容。此外,我们使用了“n-th child”伪选择器来选择第n个幻灯片并更改其字体大小和文本颜色。



   


   

Programming a slideshow using the HTML and CSS only

This is a slide 1.

This is a slide 2.

This is a slide 3.

This is a slide 4.

In the output, users can see the slideshow of 10 seconds.

Example

在下面的示例中,我们将图像添加为幻灯片的内容。此外,我们将图像的尺寸设置为“element” div 的完整尺寸。



   


   

Programming a slideshow using the HTML and CSS only

@@##@@
@@##@@
@@##@@
@@##@@

在输出中,用户可以观察图像的幻灯片播放。

结论

用户学会了仅使用HTML和CSS创建幻灯片。然而,建议使用JavaScript来创建幻灯片,因为我们可以更灵活地操作它。例如,如果我们有100多个幻灯片并且需要创建幻灯片播放,CSS代码可能会变得更复杂,因为我们需要在关键帧中添加硬编码的百分比值来实现幻灯片的动画效果。

image 1image 2image 3image 4

相关文章

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
菜鸟裹裹入口以及教程汇总
菜鸟裹裹入口以及教程汇总

本专题整合了菜鸟裹裹入口地址及教程分享,阅读专题下面的文章了解更多详细内容。

0

2026.01.22

Golang 性能分析与pprof调优实战
Golang 性能分析与pprof调优实战

本专题系统讲解 Golang 应用的性能分析与调优方法,重点覆盖 pprof 的使用方式,包括 CPU、内存、阻塞与 goroutine 分析,火焰图解读,常见性能瓶颈定位思路,以及在真实项目中进行针对性优化的实践技巧。通过案例讲解,帮助开发者掌握 用数据驱动的方式持续提升 Go 程序性能与稳定性。

9

2026.01.22

html编辑相关教程合集
html编辑相关教程合集

本专题整合了html编辑相关教程合集,阅读专题下面的文章了解更多详细内容。

56

2026.01.21

三角洲入口地址合集
三角洲入口地址合集

本专题整合了三角洲入口地址合集,阅读专题下面的文章了解更多详细内容。

51

2026.01.21

AO3中文版入口地址大全
AO3中文版入口地址大全

本专题整合了AO3中文版入口地址大全,阅读专题下面的的文章了解更多详细内容。

397

2026.01.21

妖精漫画入口地址合集
妖精漫画入口地址合集

本专题整合了妖精漫画入口地址合集,阅读专题下面的文章了解更多详细内容。

118

2026.01.21

java版本选择建议
java版本选择建议

本专题整合了java版本相关合集,阅读专题下面的文章了解更多详细内容。

3

2026.01.21

Java编译相关教程合集
Java编译相关教程合集

本专题整合了Java编译相关教程,阅读专题下面的文章了解更多详细内容。

16

2026.01.21

C++多线程相关合集
C++多线程相关合集

本专题整合了C++多线程相关教程,阅读专题下面的的文章了解更多详细内容。

11

2026.01.21

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Sass 教程
Sass 教程

共14课时 | 0.8万人学习

Bootstrap 5教程
Bootstrap 5教程

共46课时 | 3万人学习

CSS教程
CSS教程

共754课时 | 22.2万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号