0

0

现代CSS卡片

王林

王林

发布时间:2023-08-23 13:25:07

|

1256人浏览过

|

来源于tutorialspoint

转载

现代css卡片

如今,在网站上创建卡片非常重要,可以在网站上展示各种数据。例如,在TutorialsPoint网站的首页上,您会发现以卡片格式展示不同的课程,当您点击卡片时,它会将您重定向到该课程的特定页面。

此外,如果您访问任何电子商务商店,如亚马逊或Flipkart,它们会以卡片格式显示产品。创建卡片的主要好处是我们可以在图片上显示产品的简短信息,并在产品页面上提供完整信息。

在本教程中,我们将学习仅使用HTML和CSS创建不同的卡片。

Example 1 (Basic CSS Cards)

In the example below, we created the ‘card’ div element containing the single image and the ‘card-content’ div element. The ‘card-content’ div element contains the text information.

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

In CSS, we set the fixed dimensions for the card element. Also, we have given styles such as background color, border radius, and border, etc. Also, we apply the box-shadow effect on the card when users hover over the card.

Furthermore, we fixed the dimensions for the image and set the border radius for the top corners. Also, we set the font size of the text content. In the output, users can observe the resultant card.



   


   

Creating the basic cards using the CSS

Logo

Python

Python course by Shubham Vora

Join now

Example 2

的中文翻译为:

示例2

我们在下面的示例中创建了一个类似于第一个示例的卡片。在这里,我们为“card-image” div元素设置了背景图片。同时,我们通过从“Picsum”网站获取随机图片来设置图片。在这个卡片中,我们没有像第一个示例中那样添加“立即加入”的锚点标签。



   


   

Creating the basic cards using the CSS.

Random Image

This is an random image description.

Example 3

在下面的示例中,我们在卡片上添加了悬停效果,以显示额外的信息。

Here, we created the card container first to create a normal card and styled it using the CSS with ‘position: relative.’ We added the ‘card-first’ and ‘card-second’ div elements inside the card container. The ‘card-first’ div element contains the information on the card, and the ‘card-second’ div element contains the information to show whenever users hover over the card.

Furthermore, we set the dimensions for CSS's ‘card-first’ div element. Also, we set dimensions for the ‘card-second’ div element in the CSS and used the ‘transform: translate(100%)’ CSS property to hide the second part. When users hover over the card element, we use the ‘transform: translateX(-100%)’ CSS property to show the second part of the card.

Pixlr
Pixlr

Pixlr是一款2008年推出的在线图片编辑和AI图片处理工具,目前已推出AI 图像生成器、AI 生成填充、AI 删除背景、AI 删除对象和 AI 图像扩展等现代 AI 工具。

下载


   


   

Creating the hover effect on the card to show additional information.

Samsung s22

1,01,000 INR

6.4 inch display

8 GB RAM

128 GB Storage

64 MP Camera

Example 4

在下面的示例中,我们创建了一个名为'parent'的div元素。之后,我们添加了多个包含图片和卡片描述的卡片元素。

在CSS中,我们使用clamp()函数来设置卡片的宽度。clamp()函数接受三个参数。第一个是最小值,第二个是百分比值,第三个是最大值。在我们的例子中,如果屏幕尺寸的20%在300和500像素之间,卡片宽度将为20%。否则,它将是300像素或500像素。

此外,我们将“parent”容器设置为flexbox以正确显示所有卡片。



   


   

Creating the card with clamp() function to manage card dimensions according to the screen dimensions

Random image

Card 1

This is a card description.

Random image

Card 2

This is a card description.

Users learned to create modern cards using HTML and CSS. In the first two examples, we created the basic cards; in the third example, we created the cards with the hover effect. Also, we learned to use the clamp() function to handle the card size according to the device’s screen dimensions.

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

相关专题

更多
C++ 高级模板编程与元编程
C++ 高级模板编程与元编程

本专题深入讲解 C++ 中的高级模板编程与元编程技术,涵盖模板特化、SFINAE、模板递归、类型萃取、编译时常量与计算、C++17 的折叠表达式与变长模板参数等。通过多个实际示例,帮助开发者掌握 如何利用 C++ 模板机制编写高效、可扩展的通用代码,并提升代码的灵活性与性能。

10

2026.01.23

php远程文件教程合集
php远程文件教程合集

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

29

2026.01.22

PHP后端开发相关内容汇总
PHP后端开发相关内容汇总

本专题整合了PHP后端开发相关内容,阅读专题下面的文章了解更多详细内容。

21

2026.01.22

php会话教程合集
php会话教程合集

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

21

2026.01.22

宝塔PHP8.4相关教程汇总
宝塔PHP8.4相关教程汇总

本专题整合了宝塔PHP8.4相关教程,阅读专题下面的文章了解更多详细内容。

13

2026.01.22

PHP特殊符号教程合集
PHP特殊符号教程合集

本专题整合了PHP特殊符号相关处理方法,阅读专题下面的文章了解更多详细内容。

11

2026.01.22

PHP探针相关教程合集
PHP探针相关教程合集

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

8

2026.01.22

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

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

55

2026.01.22

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

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

9

2026.01.22

热门下载

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

精品课程

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

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