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

相关专题

更多
Java 桌面应用开发(JavaFX 实战)
Java 桌面应用开发(JavaFX 实战)

本专题系统讲解 Java 在桌面应用开发领域的实战应用,重点围绕 JavaFX 框架,涵盖界面布局、控件使用、事件处理、FXML、样式美化(CSS)、多线程与UI响应优化,以及桌面应用的打包与发布。通过完整示例项目,帮助学习者掌握 使用 Java 构建现代化、跨平台桌面应用程序的核心能力。

37

2026.01.14

php与html混编教程大全
php与html混编教程大全

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

19

2026.01.13

PHP 高性能
PHP 高性能

本专题整合了PHP高性能相关教程大全,阅读专题下面的文章了解更多详细内容。

37

2026.01.13

MySQL数据库报错常见问题及解决方法大全
MySQL数据库报错常见问题及解决方法大全

本专题整合了MySQL数据库报错常见问题及解决方法,阅读专题下面的文章了解更多详细内容。

19

2026.01.13

PHP 文件上传
PHP 文件上传

本专题整合了PHP实现文件上传相关教程,阅读专题下面的文章了解更多详细内容。

16

2026.01.13

PHP缓存策略教程大全
PHP缓存策略教程大全

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

6

2026.01.13

jQuery 正则表达式相关教程
jQuery 正则表达式相关教程

本专题整合了jQuery正则表达式相关教程大全,阅读专题下面的文章了解更多详细内容。

3

2026.01.13

交互式图表和动态图表教程汇总
交互式图表和动态图表教程汇总

本专题整合了交互式图表和动态图表的相关内容,阅读专题下面的文章了解更多详细内容。

45

2026.01.13

nginx配置文件详细教程
nginx配置文件详细教程

本专题整合了nginx配置文件相关教程详细汇总,阅读专题下面的文章了解更多详细内容。

9

2026.01.13

热门下载

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

精品课程

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

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