代码应用场景介绍

该代码适用于需要实现用户个人中心侧边栏导航功能的场景,例如:

  • 用户个人资料管理系统
  • 电商平台的用户中心
  • 社交媒体平台的用户设置页面

代码基本功能介绍

该代码的基本功能是生成一个侧边栏导航菜单,其中包含多个可点击的选项。当用户点击选项时,页面将切换到相应的页面或部分。

功能实现步骤及关键代码分析说明

1. HTML 结构

<div class="max-w-3xl mx-auto">
  <div class="flex items-center justify-between py-4 border-b border-gray-200 dark:border-gray-700">
    <div class="flex items-center space-x-4">
      <a href="#" class="block relative">
        <img alt="profile picture" src="https://source.unsplash.com/random/100x100" class="mx-auto object-cover rounded-full h-10 w-10 " />
      </a>
      <div class="text-white font-semibold text-lg">
        <p>Ram Siyaram</p>
        <p class="text-sm font-medium text-gray-400">Pro member</p>
        <p class="text-sm font-medium text-gray-400">eth 2347</p>
      </div>
    </div>
    <div>
      <a href="#" class="inline-flex items-center justify-center px-4 py-2 border border-transparent rounded-md shadow-sm text-base font-medium text-white bg-indigo-600 hover:bg-indigo-700">
        <svg xmlns="http://www.w3.org/2000/svg" class="-ml-1 mr-2 h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h5a2 2 0 002-2V7a2 2 0 00-2-2zM10 10a1 1 0 00-1 1v3a1 1 0 001 1h3a1 1 0 001-1v-3a1 1 0 00-1-1z" />
        </svg>
        Edit
      </a>
    </div>
  </div>
  <div class="py-4">
    <ul class="space-y-4">
      <li>
        <a href="#" class="flex items-center space-x-4 rounded-md px-4 py-3 border border-transparent text-base font-medium text-white bg-indigo-600 hover:bg-indigo-700">
          <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6z" />
          </svg>
          <span>Accounts</span>
          <svg xmlns="http://www.w3.org/2000/svg" class="ml-auto h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
          </svg>
        </a>
      </li>
      <li>
        <a href="#" class="flex items-center space-x-4 rounded-md px-4 py-3 border border-transparent text-base font-medium text-white bg-indigo-600 hover:bg-indigo-700">
          <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 11c0 3 1 5 4 5h2m8-9v10m8 3v1m-8-7v4m0 0h2m-2 0h2m-2 0h2m-2 0h2m-2 0h2m-2 0h2m-2 0h2m-2 0h2m-2 0h2m-2 0h2" />
          </svg>
          <span>Change Password</span>
          <svg xmlns="http://www.w3.org/2000/svg" class="ml-auto h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
          </svg>
        </a>
      </li>
      <li>
        <a href="#" class="flex items-center space-x-4 rounded-md px-4 py-3 border border-transparent text-base font-medium text-white bg-indigo-600 hover:bg-indigo-700">
          <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.44 2.5 1.125l.5.625c.415.535.5 1.35.25 2.062l-.125.25c-.25.5-1.037 1.399-2.5 2.5l-.625.5c-.535.414-1.35.5-2.063.25l-.25-.125c-.5-.25-1.399-1.037-2.5-2.5l-.5-.625c-.414-.535-.5-1.35-.25-2.062l.125-.25c.25-.5 1.037-1.399 2.5-2.5l.625-.5c.535-.415 1.35-.5 2.063-.25l.25.125c.5.25 1.399 1.037 2.5 2.5l.5.625c.415.535.5 1.35.25 2.062l-.125.25c-.25.5-1.037 1.399-2.5 2.5l-.625.5c-.535.414-1.35.5-2.063.25l-.25-.125z" />
          </svg>
          <span>Transaction History</span>
          <svg xmlns="http://www.w3.org/2000/svg" class="ml-auto h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
            <path stroke-linecap="round" stroke-linejoin="round"
Login
ECHO recommendation
ScriptEcho.ai
User Annotations

“个人中心”