爬行的蜗牛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: golang Linux PHP
查看: 125|回复: 0

HTML+CSS+JS实现“个人资料卡片用户界面”

[复制链接]

134

主题

41

回帖

1031

积分

管理员

积分
1031
发表于 2024-11-23 19:29:08 | 显示全部楼层 |阅读模式
111.gif

在这个片段中,悬停效果只是众多功能中的一部分,但它极具吸引力。个人资料卡底部的标签设计巧妙,允许你在较小的设计元素中放入大量内容,玻璃态的使用也提升了视觉效果。
HTML
  1. <div class="card" data-state="#about">
  2.   <div class="card-header">
  3.     <div class="card-cover" style="background-image: url('https://images.unsplash.com/photo-1549068106-b024baf5062d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80')"></div>
  4.     <img class="card-avatar" src="https://images.unsplash.com/photo-1549068106-b024baf5062d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80" alt="avatar" />
  5.     <h1 class="card-fullname">William Rocheald</h1>
  6.     <h2 class="card-jobtitle">UI Developer</h2>
  7.   </div>
  8.   <div class="card-main">
  9.     <div class="card-section is-active" id="about">
  10.       <div class="card-content">
  11.         <div class="card-subtitle">ABOUT</div>
  12.         <p class="card-desc">Whatever tattooed stumptown art party sriracha gentrify hashtag intelligentsia readymade schlitz brooklyn disrupt.
  13.         </p>
  14.       </div>
  15.       <div class="card-social">
  16.         <a href="#"><svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
  17.             <path d="M15.997 3.985h2.191V.169C17.81.117 16.51 0 14.996 0c-3.159 0-5.323 1.987-5.323 5.639V9H6.187v4.266h3.486V24h4.274V13.267h3.345l.531-4.266h-3.877V6.062c.001-1.233.333-2.077 2.051-2.077z" /></svg></a>
  18.         <a href="#"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
  19.             <path d="M512 97.248c-19.04 8.352-39.328 13.888-60.48 16.576 21.76-12.992 38.368-33.408 46.176-58.016-20.288 12.096-42.688 20.64-66.56 25.408C411.872 60.704 384.416 48 354.464 48c-58.112 0-104.896 47.168-104.896 104.992 0 8.32.704 16.32 2.432 23.936-87.264-4.256-164.48-46.08-216.352-109.792-9.056 15.712-14.368 33.696-14.368 53.056 0 36.352 18.72 68.576 46.624 87.232-16.864-.32-33.408-5.216-47.424-12.928v1.152c0 51.008 36.384 93.376 84.096 103.136-8.544 2.336-17.856 3.456-27.52 3.456-6.72 0-13.504-.384-19.872-1.792 13.6 41.568 52.192 72.128 98.08 73.12-35.712 27.936-81.056 44.768-130.144 44.768-8.608 0-16.864-.384-25.12-1.44C46.496 446.88 101.6 464 161.024 464c193.152 0 298.752-160 298.752-298.688 0-4.64-.16-9.12-.384-13.568 20.832-14.784 38.336-33.248 52.608-54.496z" /></svg></a>
  20.         <a href="#"><svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
  21.             <path d="M301 256c0 24.852-20.148 45-45 45s-45-20.148-45-45 20.148-45 45-45 45 20.148 45 45zm0 0" />
  22.             <path d="M332 120H180c-33.086 0-60 26.914-60 60v152c0 33.086 26.914 60 60 60h152c33.086 0 60-26.914 60-60V180c0-33.086-26.914-60-60-60zm-76 211c-41.355 0-75-33.645-75-75s33.645-75 75-75 75 33.645 75 75-33.645 75-75 75zm86-146c-8.285 0-15-6.715-15-15s6.715-15 15-15 15 6.715 15 15-6.715 15-15 15zm0 0" />
  23.             <path d="M377 0H135C60.562 0 0 60.563 0 135v242c0 74.438 60.563 135 135 135h242c74.438 0 135-60.563 135-135V135C512 60.562 451.437 0 377 0zm45 332c0 49.625-40.375 90-90 90H180c-49.625 0-90-40.375-90-90V180c0-49.625 40.375-90 90-90h152c49.625 0 90 40.375 90 90zm0 0" /></svg></a>
  24.         <a href="#"><svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
  25.             <path d="M23.994 24v-.001H24v-8.802c0-4.306-.927-7.623-5.961-7.623-2.42 0-4.044 1.328-4.707 2.587h-.07V7.976H8.489v16.023h4.97v-7.934c0-2.089.396-4.109 2.983-4.109 2.549 0 2.587 2.384 2.587 4.243V24zM.396 7.977h4.976V24H.396zM2.882 0C1.291 0 0 1.291 0 2.882s1.291 2.909 2.882 2.909 2.882-1.318 2.882-2.909A2.884 2.884 0 002.882 0z" /></svg></a>
  26.       </div>
  27.     </div>
  28.     <div class="card-section" id="experience">
  29.       <div class="card-content">
  30.         <div class="card-subtitle">WORK EXPERIENCE</div>
  31.         <div class="card-timeline">
  32.           <div class="card-item" data-year="2014">
  33.             <div class="card-item-title">Front-end Developer at <span>JotForm</span></div>
  34.             <div class="card-item-desc">Disrupt stumptown retro everyday carry unicorn.</div>
  35.           </div>
  36.           <div class="card-item" data-year="2016">
  37.             <div class="card-item-title">UI Developer at <span>GitHub</span></div>
  38.             <div class="card-item-desc">Developed new conversion funnels and disrupt.</div>
  39.           </div>
  40.           <div class="card-item" data-year="2018">
  41.             <div class="card-item-title">Illustrator at <span>Google</span></div>
  42.             <div class="card-item-desc">Onboarding illustrations for App.</div>
  43.           </div>
  44.           <div class="card-item" data-year="2020">
  45.             <div class="card-item-title">Full-Stack Developer at <span>CodePen</span></div>
  46.             <div class="card-item-desc">Responsible for the encomposing brand expreience.</div>
  47.           </div>
  48.         </div>
  49.       </div>
  50.     </div>
  51.     <div class="card-section" id="contact">
  52.       <div class="card-content">
  53.         <div class="card-subtitle">CONTACT</div>
  54.         <div class="card-contact-wrapper">
  55.           <div class="card-contact">
  56.             <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  57.               <path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0118 0z" />
  58.               <circle cx="12" cy="10" r="3" /></svg>
  59.             Algonquin Rd, Three Oaks Vintage, MI, 49128
  60.           </div>
  61.           <div class="card-contact">
  62.             <svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  63.               <path d="M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07 19.5 19.5 0 01-6-6 19.79 19.79 0 01-3.07-8.67A2 2 0 014.11 2h3a2 2 0 012 1.72 12.84 12.84 0 00.7 2.81 2 2 0 01-.45 2.11L8.09 9.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45 12.84 12.84 0 002.81.7A2 2 0 0122 16.92z" /></svg>(269) 756-9809</div>
  64.           <div class="card-contact">
  65.             <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  66.               <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z" />
  67.               <path d="M22 6l-10 7L2 6" /></svg>
  68.             william@rocheald.com
  69.           </div>
  70.           <button class="contact-me">WORK TOGETHER</button>
  71.         </div>
  72.       </div>
  73.     </div>
  74.     <div class="card-buttons">
  75.       <button data-section="#about" class="is-active">ABOUT</button>
  76.       <button data-section="#experience">EXPERIENCE</button>
  77.       <button data-section="#contact">CONTACT</button>
  78.     </div>
  79.   </div>
  80. </div>
复制代码
  1. @import url("https://fonts.googleapis.com/css?family=DM+Sans:400,500|Jost:400,500,600&display=swap");

  2. * {
  3.   box-sizing: border-box;
  4. }
  5. body {
  6.   color: #2b2c48;
  7.   font-family: "Jost", sans-serif;
  8.   background-image: url(https://images.unsplash.com/photo-1566738780863-f9608f88f3a9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2378&q=80);

  9.   background-repeat: no-repeat;
  10.   background-size: cover;
  11.   background-position: center;
  12.   background-attachment: fixed;
  13.   min-height: 100vh;
  14.   display: flex;
  15.   flex-wrap: wrap;
  16.   padding: 20px;
  17. }

  18. .card {
  19.   max-width: 340px;
  20.   margin: auto;
  21.   overflow-y: auto;
  22.   position: relative;
  23.   z-index: 1;
  24.   overflow-x: hidden;
  25.   background-color: rgba(255, 255, 255, 1);
  26.   display: flex;
  27.   transition: 0.3s;
  28.   flex-direction: column;
  29.   border-radius: 10px;
  30.   box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.2);
  31. }

  32. .card[data-state="#about"] {
  33.   height: 450px;
  34.   .card-main {
  35.     padding-top: 0;
  36.   }
  37. }

  38. .card[data-state="#contact"] {
  39.   height: 430px;
  40. }

  41. .card[data-state="#experience"] {
  42.   height: 550px;
  43. }

  44. .card.is-active {
  45.   .card-header {
  46.     height: 80px;
  47.   }

  48.   .card-cover {
  49.     height: 100px;
  50.     top: -50px;
  51.   }

  52.   .card-avatar {
  53.     transform: none;
  54.     left: 20px;
  55.     width: 50px;
  56.     height: 50px;
  57.     bottom: 10px;
  58.   }

  59.   .card-fullname,
  60.   .card-jobtitle {
  61.     left: 86px;
  62.     transform: none;
  63.   }

  64.   .card-fullname {
  65.     bottom: 18px;
  66.     font-size: 19px;
  67.   }

  68.   .card-jobtitle {
  69.     bottom: 16px;
  70.     letter-spacing: 1px;
  71.     font-size: 10px;
  72.   }
  73. }

  74. .card-header {
  75.   position: relative;
  76.   display: flex;
  77.   height: 200px;
  78.   flex-shrink: 0;
  79.   width: 100%;
  80.   transition: 0.3s;

  81.   * {
  82.     transition: 0.3s;
  83.   }
  84. }

  85. .card-cover {
  86.   width: 100%;
  87.   height: 100%;
  88.   position: absolute;
  89.   height: 160px;
  90.   top: -20%;
  91.   left: 0;
  92.   will-change: top;
  93.   background-size: cover;
  94.   background-position: center;
  95.   filter: blur(30px);
  96.   transform: scale(1.2);
  97.   transition: 0.5s;
  98. }

  99. .card-avatar {
  100.   width: 100px;
  101.   height: 100px;
  102.   box-shadow: 0 8px 8px rgba(0, 0, 0, 0.2);
  103.   border-radius: 50%;
  104.   object-position: center;
  105.   object-fit: cover;
  106.   position: absolute;
  107.   bottom: 0;
  108.   left: 50%;
  109.   transform: translateX(-50%) translateY(-64px);
  110. }

  111. .card-fullname {
  112.   position: absolute;
  113.   bottom: 0;
  114.   font-size: 22px;
  115.   font-weight: 700;
  116.   text-align: center;
  117.   white-space: nowrap;
  118.   transform: translateY(-10px) translateX(-50%);
  119.   left: 50%;
  120. }

  121. .card-jobtitle {
  122.   position: absolute;
  123.   bottom: 0;
  124.   font-size: 11px;
  125.   white-space: nowrap;
  126.   font-weight: 500;
  127.   opacity: 0.7;
  128.   text-transform: uppercase;
  129.   letter-spacing: 1.5px;
  130.   margin: 0;
  131.   left: 50%;
  132.   transform: translateX(-50%) translateY(-7px);
  133. }

  134. .card-main {
  135.   position: relative;
  136.   flex: 1;
  137.   display: flex;
  138.   padding-top: 10px;
  139.   flex-direction: column;
  140. }

  141. .card-subtitle {
  142.   font-weight: 700;
  143.   font-size: 13px;
  144.   margin-bottom: 8px;
  145. }

  146. .card-content {
  147.   padding: 20px;
  148. }

  149. .card-desc {
  150.   line-height: 1.6;
  151.   color: #636b6f;
  152.   font-size: 14px;
  153.   margin: 0;
  154.   font-weight: 400;
  155.   font-family: "DM Sans", sans-serif;
  156. }

  157. .card-social {
  158.   display: flex;
  159.   align-items: center;
  160.   padding: 0 20px;
  161.   margin-bottom: 30px;
  162.   svg {
  163.     fill: rgb(165, 181, 206);
  164.     width: 16px;
  165.     display: block;
  166.     transition: 0.3s;
  167.   }
  168.   a {
  169.     color: #8797a1;
  170.     height: 32px;
  171.     width: 32px;
  172.     border-radius: 50%;
  173.     display: inline-flex;
  174.     align-items: center;
  175.     justify-content: center;
  176.     transition: 0.3s;
  177.     background-color: rgba(93, 133, 193, 0.05);
  178.     border-radius: 50%;
  179.     margin-right: 10px;

  180.     &:hover {
  181.       svg {
  182.         fill: darken(rgb(165, 181, 206), 20%);
  183.       }
  184.     }

  185.     &:last-child {
  186.       margin-right: 0;
  187.     }
  188.   }
  189. }

  190. .card-buttons {
  191.   display: flex;
  192.   background-color: #fff;
  193.   margin-top: auto;
  194.   position: sticky;
  195.   bottom: 0;
  196.   left: 0;

  197.   button {
  198.     flex: 1 1 auto;
  199.     user-select: none;
  200.     background: 0;
  201.     font-size: 13px;
  202.     border: 0;
  203.     padding: 15px 5px;
  204.     cursor: pointer;
  205.     color: #5c5c6d;
  206.     transition: 0.3s;
  207.     font-family: "Jost", sans-serif;
  208.     font-weight: 500;
  209.     outline: 0;
  210.     border-bottom: 3px solid transparent;

  211.     &.is-active,
  212.     &:hover {
  213.       color: #2b2c48;
  214.       border-bottom: 3px solid #8a84ff;
  215.       background: linear-gradient(
  216.         to bottom,
  217.         rgba(127, 199, 231, 0) 0%,
  218.         rgba(207, 204, 255, 0.2) 44%,
  219.         rgba(211, 226, 255, 0.4) 100%
  220.       );
  221.     }
  222.   }
  223. }

  224. .card-section {
  225.   display: none;
  226.   &.is-active {
  227.     display: block;
  228.     animation: fadeIn 0.6s both;
  229.   }
  230. }

  231. @keyframes fadeIn {
  232.   0% {
  233.     opacity: 0;
  234.     transform: translatey(40px);
  235.   }
  236.   100% {
  237.     opacity: 1;
  238.   }
  239. }

  240. .card-timeline {
  241.   margin-top: 30px;
  242.   position: relative;
  243.   &:after {
  244.     background: linear-gradient(
  245.       to top,
  246.       rgba(134, 214, 243, 0) 0%,
  247.       rgba(81, 106, 204, 1) 100%
  248.     );
  249.     content: "";
  250.     left: 42px;
  251.     width: 2px;
  252.     top: 0;
  253.     height: 100%;
  254.     position: absolute;
  255.     content: "";
  256.   }
  257. }

  258. .card-item {
  259.   position: relative;
  260.   padding-left: 60px;
  261.   padding-right: 20px;
  262.   padding-bottom: 30px;
  263.   z-index: 1;
  264.   &:last-child {
  265.     padding-bottom: 5px;
  266.   }

  267.   &:after {
  268.     content: attr(data-year);
  269.     width: 10px;
  270.     position: absolute;
  271.     top: 0;
  272.     left: 37px;
  273.     width: 8px;
  274.     height: 8px;
  275.     line-height: 0.6;
  276.     border: 2px solid #fff;
  277.     font-size: 11px;
  278.     text-indent: -35px;
  279.     border-radius: 50%;
  280.     color: rgba(#868686, 0.7);
  281.     background: linear-gradient(
  282.       to bottom,
  283.       lighten(#516acc, 20%) 0%,
  284.       #516acc 100%
  285.     );
  286.   }
  287. }

  288. .card-item-title {
  289.   font-weight: 500;
  290.   font-size: 14px;
  291.   margin-bottom: 5px;
  292. }

  293. .card-item-desc {
  294.   font-size: 13px;
  295.   color: #6f6f7b;
  296.   line-height: 1.5;
  297.   font-family: "DM Sans", sans-serif;
  298. }

  299. .card-contact-wrapper {
  300.   margin-top: 20px;
  301. }

  302. .card-contact {
  303.   display: flex;
  304.   align-items: center;
  305.   font-size: 13px;
  306.   color: #6f6f7b;
  307.   font-family: "DM Sans", sans-serif;
  308.   line-height: 1.6;
  309.   cursor: pointer;

  310.   & + & {
  311.     margin-top: 16px;
  312.   }

  313.   svg {
  314.     flex-shrink: 0;
  315.     width: 30px;
  316.     min-height: 34px;
  317.     margin-right: 12px;
  318.     transition: 0.3s;
  319.     padding-right: 12px;
  320.     border-right: 1px solid #dfe2ec;
  321.   }
  322. }

  323. .contact-me {
  324.   border: 0;
  325.   outline: none;
  326.   background: linear-gradient(
  327.     to right,
  328.     rgba(83, 200, 239, 0.8) 0%,
  329.     rgba(81, 106, 204, 0.8) 96%
  330.   );
  331.   box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
  332.   color: #fff;
  333.   padding: 12px 16px;
  334.   width: 100%;
  335.   border-radius: 5px;
  336.   margin-top: 25px;
  337.   cursor: pointer;
  338.   font-size: 14px;
  339.   font-weight: 500;
  340.   font-family: "Jost", sans-serif;
  341.   transition: 0.3s;
  342. }
复制代码
  1. const buttons = document.querySelectorAll(".card-buttons button");
  2. const sections = document.querySelectorAll(".card-section");
  3. const card = document.querySelector(".card");

  4. const handleButtonClick = (e) => {
  5.   const targetSection = e.target.getAttribute("data-section");
  6.   const section = document.querySelector(targetSection);
  7.   targetSection !== "#about"
  8.     ? card.classList.add("is-active")
  9.     : card.classList.remove("is-active");
  10.   card.setAttribute("data-state", targetSection);
  11.   sections.forEach((s) => s.classList.remove("is-active"));
  12.   buttons.forEach((b) => b.classList.remove("is-active"));
  13.   e.target.classList.add("is-active");
  14.   section.classList.add("is-active");
  15. };

  16. buttons.forEach((btn) => {
  17.   btn.addEventListener("click", handleButtonClick);
  18. });
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表