再写好看一点
时间: 2024-02-02 14:03:28 浏览: 91
好的,以下是一个使用Vue和Bootstrap写的响应式登录页面,样式更加美观的示例代码:
```html
<template>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card shadow-lg">
<div class="card-header text-white bg-primary">{{title}}</div>
<div class="card-body">
<form>
<div class="form-group">
<label for="username">用户名</label>
<input type="text" class="form-control" id="username" v-model="username" placeholder="请输入用户名">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" class="form-control" id="password" v-model="password" placeholder="请输入密码">
</div>
<button type="button" class="btn btn-primary btn-block" @click="login">登录</button>
</form>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
title: '登录',
username: '',
password: ''
}
},
methods: {
login() {
// 处理登录逻辑,可以向后端发送请求进行验证
console.log('用户名:', this.username)
console.log('密码:', this.password)
}
}
}
</script>
<style>
@media (min-width: 576px) {
.card {
margin-top: 5rem;
}
}
.card-header {
font-size: 1.5rem;
font-weight: bold;
}
.card-body {
padding: 2rem;
}
.btn-primary {
background-color: #007bff;
border-color: #007bff;
}
.btn-primary:hover {
background-color: #0069d9;
border-color: #0062cc;
}
.btn-primary:focus,
.btn-primary.focus {
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.5);
}
.btn-primary.disabled,
.btn-primary:disabled {
background-color: #007bff;
border-color: #007bff;
}
.btn-primary:not(:disabled):not(.disabled):active,
.btn-primary:not(:disabled):not(.disabled).active,
.show > .btn-primary.dropdown-toggle {
background-color: #0062cc;
border-color: #005cbf;
}
.btn-primary:not(:disabled):not(.disabled):active:focus,
.btn-primary:not(:disabled):not(.disabled).active:focus,
.show > .btn-primary.dropdown-toggle:focus {
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.5);
}
</style>
```
在这个示例中,我们在基础代码的基础上,增加了一些CSS样式,使得登录页面更加美观。我们使用了Bootstrap提供的阴影组件shadow-lg,增加了登录框的立体感。同时,我们调整了按钮的样式,使得按钮在鼠标悬停、聚焦和激活时的效果更加醒目。为了提高可读性,我们增加了一些注释和缩进,使得代码更加易于阅读。
阅读全文