day12-Faq Collapse(问题折叠)

2023-11-21 07:50
文章标签 问题 day12 折叠 collapse faq

本文主要是介绍day12-Faq Collapse(问题折叠),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

50 天学习 50 个项目 - HTMLCSS and JavaScript

day12-Faq Collapse(问题折叠)

效果

在这里插入图片描述

index.html

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><!-- 字体图标 --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css"integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog=="crossorigin="anonymous" /><link rel="stylesheet" href="style.css" /><title>FAQ</title>
</head><body><!-- 标题 --><h1>Frequently Asked Questions-常见问题</h1><!-- 问题容器 --><div class="faq-container"><!-- 问题 --><div class="faq active"><!-- 问题内容 --><h3 class="faq-title">Why shouldn't we trust atoms?-我们为什么不能相信原子呢?</h3><!-- 问题答案 --><p class="faq-text">They make up everything-他们编造一切</p><!-- 显示、隐藏 字体图标 --><button class="faq-toggle"><i class="fas fa-chevron-down"></i><i class="fas fa-times"></i></button></div><div class="faq"><h3 class="faq-title">What do you call someone with no body and no nose?-你怎么称呼一个没有身体和鼻子的人?</h3><p class="faq-text">Nobody knows.-没有人知道。</p><button class="faq-toggle"><i class="fas fa-chevron-down"></i><i class="fas fa-times"></i></button></div><div class="faq"><h3 class="faq-title">What's the object-oriented way to become wealthy?-面向对象的致富方式是什么?</h3><p class="faq-text">Inheritance.-继承。</p><button class="faq-toggle"><i class="fas fa-chevron-down"></i><i class="fas fa-times"></i></button></div><div class="faq"><h3 class="faq-title">How many tickles does it take to tickle an octopus?-要挠章鱼几下才行?</h3><p class="faq-text">Ten-tickles!-10下</p><button class="faq-toggle"><i class="fas fa-chevron-down"></i><i class="fas fa-times"></i></button></div><div class="faq"><h3 class="faq-title">What is: 1 + 1?-1 + 1是什么?</h3><p class="faq-text">Depends on who are you asking.-这取决于你问的是谁</p><button class="faq-toggle"><i class="fas fa-chevron-down"></i><i class="fas fa-times"></i></button></div></div><script src="script.js"></script>
</body></html>

style.css

@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');/* 引入字体 */
* {box-sizing: border-box;
}body {font-family: 'Muli', sans-serif;background-color: rgba(127, 126, 126, 0.1);
}/* 标题 */
h1 {margin: 50px 0 30px;text-align: center;
}/*  问题容器*/
.faq-container {max-width: 600px;margin: 0 auto;
}/* 问题 */
.faq {background-color: transparent;border: 1px solid #4aa5ee;border-radius: 10px;margin: 20px 0;padding: 30px;position: relative;overflow: hidden;transition: 0.3s ease;
}/* 交集选择器 */
.faq.active {background-color: #fff;box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1), 0 3px 6px rgba(0, 0, 0, 0.1);
}/* 伪元素 字体图标 */
.faq.active::before,
.faq.active::after {content: '\f075';font-family: 'Font Awesome 5 Free';color: #2ecc71;font-size: 7rem;position: absolute;opacity: 0.2;top: 20px;left: 20px;z-index: 0;
}.faq.active::before {color: #3498db;top: -10px;left: -30px;/* 旋转180度 */transform: rotateY(180deg);
}/* 问题内容 */
.faq-title {margin: 0 35px 0 0;
}/* 问题答案 */
.faq-text {display: none;margin: 30px 0 0;
}/* active时,显示问题答案 */
.faq.active .faq-text {display: block;
}/* 显示、隐藏 字体图标 */
.faq-toggle {background-color: transparent;border: 0;border-radius: 50%;cursor: pointer;display: flex;align-items: center;justify-content: center;font-size: 16px;padding: 0;position: absolute;top: 30px;right: 30px;height: 30px;width: 30px;outline: 0;
}/* 向下箭头默认不显示 */
.faq-toggle .fa-times {display: none;
}
/* active时,x 显示 */
.faq.active .faq-toggle .fa-times {color: #fff;display: block;
}
/* active时,向下箭头 不显示 */
.faq.active .faq-toggle .fa-chevron-down {display: none;
}
/* active时,颜色改变 */
.faq.active .faq-toggle {background-color: #306ea0;
}

script.js

// 重点是 transition 定位 字体图标 的应用// 1.获取元素节点
const toggles = document.querySelectorAll('.faq-toggle');//字体图标按钮
// 2.点击事件 切换active类
toggles.forEach(toggle => {toggle.addEventListener('click', () => {// faqtoggle.parentNode.classList.toggle('active');})
})

这篇关于day12-Faq Collapse(问题折叠)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/400922

相关文章

Spring的RedisTemplate的json反序列泛型丢失问题解决

《Spring的RedisTemplate的json反序列泛型丢失问题解决》本文主要介绍了SpringRedisTemplate中使用JSON序列化时泛型信息丢失的问题及其提出三种解决方案,可以根据性... 目录背景解决方案方案一方案二方案三总结背景在使用RedisTemplate操作redis时我们针对

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

nginx中端口无权限的问题解决

《nginx中端口无权限的问题解决》当Nginx日志报错bind()to80failed(13:Permissiondenied)时,这通常是由于权限不足导致Nginx无法绑定到80端口,下面就来... 目录一、问题原因分析二、解决方案1. 以 root 权限运行 Nginx(不推荐)2. 为 Nginx

解决1093 - You can‘t specify target table报错问题及原因分析

《解决1093-Youcan‘tspecifytargettable报错问题及原因分析》MySQL1093错误因UPDATE/DELETE语句的FROM子句直接引用目标表或嵌套子查询导致,... 目录报js错原因分析具体原因解决办法方法一:使用临时表方法二:使用JOIN方法三:使用EXISTS示例总结报错原

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

SpringSecurity整合redission序列化问题小结(最新整理)

《SpringSecurity整合redission序列化问题小结(最新整理)》文章详解SpringSecurity整合Redisson时的序列化问题,指出需排除官方Jackson依赖,通过自定义反序... 目录1. 前言2. Redission配置2.1 RedissonProperties2.2 Red

nginx 负载均衡配置及如何解决重复登录问题

《nginx负载均衡配置及如何解决重复登录问题》文章详解Nginx源码安装与Docker部署,介绍四层/七层代理区别及负载均衡策略,通过ip_hash解决重复登录问题,对nginx负载均衡配置及如何... 目录一:源码安装:1.配置编译参数2.编译3.编译安装 二,四层代理和七层代理区别1.二者混合使用举例

怎样通过分析GC日志来定位Java进程的内存问题

《怎样通过分析GC日志来定位Java进程的内存问题》:本文主要介绍怎样通过分析GC日志来定位Java进程的内存问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、GC 日志基础配置1. 启用详细 GC 日志2. 不同收集器的日志格式二、关键指标与分析维度1.

Java 线程安全与 volatile与单例模式问题及解决方案

《Java线程安全与volatile与单例模式问题及解决方案》文章主要讲解线程安全问题的五个成因(调度随机、变量修改、非原子操作、内存可见性、指令重排序)及解决方案,强调使用volatile关键字... 目录什么是线程安全线程安全问题的产生与解决方案线程的调度是随机的多个线程对同一个变量进行修改线程的修改操

Redis出现中文乱码的问题及解决

《Redis出现中文乱码的问题及解决》:本文主要介绍Redis出现中文乱码的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 问题的产生2China编程. 问题的解决redihttp://www.chinasem.cns数据进制问题的解决中文乱码问题解决总结