最简单的登录界面

请使用 HTML 和 CSS 实现一个简单的登录页面,页面包含用户名和密码输入框,以及一个登录按钮。要求登录按钮有鼠标悬停效果,且输入框在聚焦时要有特定的样式。同时,实现当点击登录按钮时,检查用户名和密码是否为空,如果为空则给出提示,否则在控制台输出“登录成功”。

<template>
  <div class="login-container">
    <div class="input-group">
      <input type="text" v-model="username" />
      <label>用户名</label>
    </div>
    <div class="input-group">
      <input type="password" v-model="password" />
      <label>密码</label>
    </div>
    <button @click="login">登录</button>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const username = ref('');
const password = ref('');

const login = () => {
  if (!username.value ||!password.value) {
    alert('用户名或密码不能为空');
    return;
  }
  console.log('登录成功');
};
</script>

<style scoped>
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group input {
  padding: 10px;
  border: 2px solid #ccc;
  border-radius: 5px;
  transition: border-color 0.3s ease;
}

.input-group input:focus {
  border-color: #007bff;
}

.input-group label {
  position: absolute;
  top: -8px;
  left: 10px;
  background-color: white;
  padding: 0 5px;
  font-size: 12px;
}

button {
  padding: 10px 20px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

button:hover {
  background-color: #0069d9;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值