This article was inspired by one of my continuing education students, who delivered a final project with the effect you see above. His version used JavaScript, but I realized the same result could be achieved in pure CSS.

本文的灵感来自于我的一名继续教育学生,他们完成了一个最终项目,效果与您上面看到的一样。 他的版本使用JavaScript ,但是我意识到用纯CSS可以实现相同的结果。

This effect is best suited to a group of two dozen items or less. The goal is to filter the items by type, just as a true database would, only visually. In the example above, I’ve used travel photographs by Trey Radcliff.

此效果最适合两个或更少的项目。 目标是像虚拟数据库一样,仅在视觉上按类型过滤项目。 在上面的示例中,我使用了Trey Radcliff的旅行照片。

The gallery images could be organized in almost any way you wish: I’ve contained the photographs in a figure element, but an unordered list or div could work equally well. Each image receives a class that identifies it as being a member of a particular set. As the class is only used as a CSS reference, and not as an actual style: an HTML5 data attribute could be equally effective.

画廊的图像几乎可以按照您希望的任何方式进行组织:我将照片包含在一个figure元素中,但是无序列表或div也可以很好地工作。 每个图像都会收到一个class ,该class其标识为特定集合的成员。 由于class仅用作CSS引用,而不用作实际样式: HTML5 data属性可能同样有效。

The interesting part of the code lies immediately above the images. HTML5 allows form elements to be placed anywhere, so we can add a series of radio buttons with matching <label> tags immediately above the <img> elements. The for attribute on each <label> will turn the associated radio button with a matching id value on and off; as the buttons all share the same name value, activation of one button will turn the others off.

代码有趣的部分位于图像的上方。 HTML5允许将表单元素放置在任何位置,因此我们可以在<img>元素的正上方添加一系列带有匹配<label>标签的单选按钮 。 每个<label>上的for属性将打开和关闭具有匹配id值的关联单选按钮; 由于所有按钮共享相同的name值,因此激活一个按钮将关闭其他按钮。

<input type="radio" name="zoom" id="france">
<label for="france">France</label>
<input type="radio" name="zoom" id="japan">
<label for="japan">Japan</label>
<input type="radio" name="zoom" id="us">
<label for="us">United States</label><figure id="zoom-gallery"><img src="central-park-in-fall.jpg" alt="Central Park In Fall" class="us"><img src="kyoto-bamboo-walk.jpg" alt="Kyoto bamboo walk" class="japan"><img src="kyoto-forest-walk.jpg" alt="Kyoto forest walk" class="japan"><img src="paris-reflected.jpg" alt="Paris reflected" class="france"><img src="paris-skyline.jpg" alt="Paris skyline" class="france"><img src="yosemite-clouds.jpg"" alt="Yosemite clouds" class="us">
</figure>

Now for the CSS. We’ll start with a basic setup:

现在为CSS。 我们将从基本设置开始:

figure#zoom-gallery {margin: 0;padding: 0;
}
figure#zoom-gallery img {width: 40%;max-width: 300px;margin: 3%;transition: .7s all ease-in-out;
}
label {color: #fff;font-family: Futura, Arial, sans-serif;padding: 1em;
}

(I’ve removed vendor prefixes from the code to keep it clean.)

(我已从代码中删除了供应商前缀 ,以保持其干净。)

Starting with a variation of the :checked CSS I have talked about previously, we add a sibling selector to zoom images in a particular set. I’ll show one example, for the photographs taken in Japan:

从我之前讨论过的:checked CSS的变体开始,我们添加了一个同级选择器来缩放特定集合中的图像。 我将举例说明在日本拍摄的照片:

input#japan:checked ~ figure img.japan { transform: scale(1.1);
}

At the same time, we want to diminish any images in the gallery that are not in that particular set. Appropriately enough, we use the :not selector. Again, for the photographs from taken of Japan:

同时,我们希望减少画廊中不在该特定集合中的所有图像。 适当地,我们使用:not选择器。 同样,对于日本拍摄的照片:

input#japan:checked ~ figure img:not(.japan) { transform: scale(0.9);opacity: 0.6;
}

Optionally, you can hide the radio buttons by setting them to display: none, leveraging the accessibility of the label elements to allow the :checked declarations to operate regardless. If you add this, it makes sense to place a :hover effect on the labels to make it clear that they act as links:

(可选)可以通过将单选按钮设置为display: none来隐藏它们display: none ,利用label元素的可访问性允许:checked声明无论如何运行。 如果添加此选项,则在标签上放置:hover效果以使其清楚地充当链接是很有意义的:

input[type="radio"] {display: none;
}
label:hover {cursor: pointer;
}

While there are many possible improvements that could be made – I’ve added an animated box-shadow to the image elements – that’s essentially it. The only downside to this approach versus a JavaScript solution is that it does not scale, but that’s not an issue when the number of elements is small and unchanging.

尽管可以做出许多可能的改进-我在图像元素box-shadow添加了动画box-shadow -实质上就是如此。 与JavaScript解决方案相比,此方法的唯一缺点是它无法扩展,但是当元素数量很少且保持不变时,这不是问题。

翻译自: https://thenewcode.com/625/A-Visual-Database-Gallery-In-Pure-CSS

纯CSS中的可视数据库库相关推荐

  1. 纯 CSS 中的简单响应式汉堡菜单

    欢迎阅读有关如何创建简单的响应式纯 CSS 汉堡菜单的教程.是的,互联网上有很多其他的汉堡菜单,但其中一些仍然需要使用 Javascript.所以这里是一个纯 CSS 驱动的菜单,而不是一行 Java ...

  2. 【web组件库系列】纯CSS实现典型网页数据分页器

    使用CSS实现分页器 CSDN:jcLee95 邮箱 :291148484@163.com 本文地址:https://blog.csdn.net/qq_28550263/article/details ...

  3. html鼠标经过自动下拉菜单,操作方法:在鼠标经过后使用纯CSS实现下拉菜单,并附有示例说明(代码)...

    纯CSS实现鼠标移动到按钮上打开下拉菜单. CSS部分: .dropbtn { background-color: #4CAF50; color: white; padding: 16px; font ...

  4. mfc显示html单元格,HTML/CSS中可直接输数据的表格

    HTML/CSS中可直接输数据的表格-1.jpg (18.44 KB, 下载次数: 0) 2018-9-23 21:35 上传 HTML/CSS中可直接输数据的表格-2.jpg (41.92 KB, ...

  5. css 查看更多_在Scrapy中如何利用CSS选择器从网页中采集目标数据——详细教程(上篇)...

    /前言/ 今天小编给大家介绍Scrapy中另外一种选择器,即大家经常听说的CSS选择器. /CSS基础/ CSS选择器和Xpath选择器的功能是一致的,都是帮助我们去定位网页结构中的某一个具体的元素, ...

  6. 纯css实现div中未知尺寸图片的垂直居中

    1.淘宝的方法 在曾经的"淘宝UED招聘"中有这样一道题目: "使用纯CSS实现未知尺寸的图片(但高宽都小于200px)在200px的正方形容器中水平和垂直居中.&quo ...

  7. html 数据交互动画,纯css实现可交互的动画

    如题,不借助JavaScript,只利用CSS,如何实现可交互式的动画呢?或许该需求仅此一种解决方案,绝无仅有.不知该方案是否是第一次找到. 什么是可交互动画? 就是可以响应用户的动画,直接上图吧,更 ...

  8. Vue中使用纯CSS实现全屏网格加渐变色背景布局

    Vue中使用纯CSS实现全屏网格加渐变色背景布局 CSDN:jcLee95 邮箱:291148484@163.com 本文地址:https://blog.csdn.net/qq_28550263/ar ...

  9. html中怎么制作太阳月亮交替,使用纯CSS实现太阳和地球和月亮运转模型动画的方法...

    使用纯CSS实现太阳和地球和月亮运转模型动画的方法 发布时间:2020-09-22 10:42:05 来源:亿速云 阅读:140 作者:小新 使用纯CSS实现太阳和地球和月亮运转模型动画的方法?这个问 ...

  10. html中轮播图跳转,纯 CSS 实现轮播图

    大家好,我是 Steven. 今集我们会尝试只用 HTML 和 CSS,实现基础的轮播图效果,当然会有一些功能的缺失,例如不能自动跳转,但我们来看看用 CSS 可以实现到多少. HTML 的部分 打开 ...

最新文章

  1. 图灵奖得主Raj Reddy:以历史的视角重新审视“人工智能”
  2. 如何使用Java代码给图片增加倒影效果
  3. 计算代码重复率_了解了知网大学生论文查重原理,重复率想高于6%都难!
  4. 3周第4次课 df、du命令 fdisk磁盘分区
  5. java 采样_java 采集数据
  6. C++运算符重载 实现有理数(分数)的加减法
  7. 跳跃问题(Java)
  8. vue 简单实用的elementUI表格封装
  9. VS2013+OSG3.4.0+Qt5.5.1编译(超详)
  10. avedev matlab,avedev(avedev是什么函数)
  11. Codeforces Round #799 (Div. 4) (AK代码)
  12. win10搭建无盘服务器配置,win10系统无盘安装教程
  13. “github中文版”来了,这个神器一键帮你汉化
  14. 板簧的弹性系数如何计算_一种板簧总成的刚度计算方法、系统及可读存储介质与流程...
  15. HDU-2669 Romantic (欧几里得定理)
  16. [渝粤教育] 厦门大学 大学生心理健康 参考 资料
  17. 百战RHCE(第一战:Linux基础命令1)
  18. 鞍山c语言培训,10_鞍山科技大学:C语言与数据结构_ppt_大学课件预览_高等教育资讯网...
  19. latex 中表格怎么指定编号_科学网—latex中简单表格制作+标题+编号+固定位置 - 江亿平的博文...
  20. PHP取出数组中随机一条字符串

热门文章

  1. 计算机动漫设计与游戏制作课程,有关计算机动漫与游戏制作专业介绍
  2. Excel--Vlookup与match、index函数
  3. 详解电商订单逻辑流程图
  4. 硬件系统工程师需要具备哪些技能
  5. 形状超链接html,ppt中标注形状超链接怎么做
  6. Mysql如何解决幻读:
  7. Polkadot的PLO第一阶段: Equilibrium在DOT上筹集了850万美元
  8. 2022 开源之夏 | Serverless Devs 陪你“变得更强”
  9. javascript有效的anagram挑战
  10. Linux 服务器配置 ASF 云挂卡