使用CSS常见问题解答卡片

12 篇文章 0 订阅

常见问题解答卡片

效果展示

在这里插入图片描述

CSS 知识点

  • CSS 选择器的使用
  • background 渐变背景色运用
  • CSS 综合知识运用

页面整体布局

<div class="container">
  <h1>经常问的问题</h1>
  <!-- 这里只是展示一个项目 -->
  <div class="tab">
    <input type="radio" name="acc" id="acc1" />
    <label for="acc1">
      <h2>01</h2>
      <h3>权限申请目的不明</h3>
    </label>
    <div class="content">
      <p>
        未告知申请目的。App申请系统权限时未说明权限的申请目的,例如仅通过操作系统弹窗向用户申请系统权限,未通过App额外弹窗提示或在系统弹窗中编辑目的等方式,告知用户权限申请目的。
      </p>
    </div>
  </div>
</div>

实现基础结构样式

.container {
  margin: 0 40px;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.container h1 {
  color: #333;
}

.container .tab {
  position: relative;
  background: #fff;
  padding: 0 20px 20px;
  box-shadow: 0 15px 15px rgba(0, 0, 0, 0.05);
  border-radius: 5px;
  overflow: hidden;
}

修改单选按钮样式

.container .tab input {
  appearance: none;
}

.container .tab label {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.container .tab label::after {
  content: "+";
  position: absolute;
  right: 20px;
  font-size: 1.4em;
  color: rgba(0, 0, 0, 0.1);
  transition: transform 1s;
}

.container .tab:hover label::after {
  color: #333;
}

编写编号样式

.container .tab label h2 {
  width: 40px;
  height: 40px;
  background: #333;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-size: 1.25em;
  border-radius: 5px;
  margin-right: 10px;
}

编写单选按钮激活状态下的样式

.container .tab label h3 {
  position: relative;
  font-weight: 500;
  color: #333;
  z-index: 10;
}

.container .tab .content {
  max-height: 0;
  transition: 1s;
  overflow: hidden;
}

.container .tab input:checked ~ .content {
  max-height: 100vh;
}

实现上述代码后,效果如下:

在这里插入图片描述

升级编号的样式

.container .tab .content p {
  position: relative;
  padding: 10px 0;
  color: #333;
  z-index: 10;
  line-height: 25px;
}

.container .tab:nth-child(2) label h2 {
  background: linear-gradient(135deg, #70f570, #49c628);
}

.container .tab:nth-child(3) label h2 {
  background: linear-gradient(135deg, #3c8ce7, #00eaff);
}

.container .tab:nth-child(4) label h2 {
  background: linear-gradient(135deg, #ff96f9, #c32bac);
}

.container .tab:nth-child(5) label h2 {
  background: linear-gradient(135deg, #fd6e6a, #ffc600);
}

实现激活状态下的卡片背景样式

.container .tab input:checked ~ label h2 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  color: rgba(255, 255, 255, 0.2);
  font-size: 8em;
  justify-content: flex-end;
  padding: 20px;
}

.container .tab input:checked ~ label h3 {
  background: #fff;
  padding: 4px 15px;
  color: #333;
  border-radius: 4px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.container .tab input:checked ~ .content p {
  color: #fff;
}

完整代码下载

完整代码下载

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值