导航首页 » 技术教程 » Boostrap实现的登录界面实例代码
Boostrap实现的登录界面实例代码 117 2024-02-16   

Bootstrap它是一个开源的web开发前端框架。

这几天我看了下Bootstrap的官方文档。看到其中的Basic-form,突然想实现下登录界面。然后想了下实现的思路,于是就打开了桌面的H5 builder码起来。代码实现起来其实不难,但是碰到个问题,就是Bootstrap的布局控制好像用.col类难以实现居中显示,虽然可以用modal(模态框)实现弹出居中,但是我暂时不想用modal框。发现问题后,第一想法是自己再定义个css进行一个控制。但是又不知道行业内的大牛是不是只用Bootstrap就能实现,而我只是没发现实现的方法。然后倔强地想要试试只用Bootstrap实现,后来各种google,百度,半小时过去了。没找到方法,所以我也只能自己写css进行布局一个div居中。其实,也不是我不懂css,只是单纯地想实现下。好了,废话少说,上个图坐镇。界面写得不好看,如有错误请大方指正。(背景图不会PS,是用别人的,若有侵权请给我发邮件或者留言,我立马换图!)。

查看图片

好了,感觉登录框不够居中。如有更好的方法,请告知我谢谢!

本界面使用的Bootstrap是v3.3.5版本。

基本代码:

style.css(我的css用于控制登录框那个外部的div居中):

body {
background:url(../img/login_bg_0.jpg) #f8f6e9;
}
.mycenter{
margin-top: 100px;
margin-left: auto;
margin-right: auto;
height: 350px;
width:500px;
padding: 5%;
padding-left: 5%;
padding-right: 5%;
}
.mycenter mysign{
width: 440px;
}
.mycenter input,checkbox,button{
margin-top:2%;
margin-left: 10%;
margin-right: 10%;
}
.mycheckbox{
margin-top:10px;
margin-left: 40px;
margin-bottom: 10px;
height: 10px;
}

login.html(登录的界面html代码):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>用户登录</title>
<link rel="stylesheet" href="http://www.gimoo.net/t/1812/css/bootstrap.min.css" />
<link rel="stylesheet" href="http://www.gimoo.net/t/1812/css/style.css" />
<script src="http://www.gimoo.net/t/1812/js/bootstrap.min.js"></script>
</head>
<body>
<form action="login.php" method="post">
<div class="mycenter">
<div class="mysign">
<div class="col-lg-11 text-center text-info">
<h2>请登录</h2>
</div>
<div class="col-lg-10">
<input type="text" class="form-control" name="username" placeholder="请输入账户名" required autofocus/>
</div>
<div class="col-lg-10"></div>
<div class="col-lg-10">
<input type="password" class="form-control" name="password" placeholder="请输入密码" required autofocus/>
</div>
<div class="col-lg-10"></div>
<div class="col-lg-10 mycheckbox checkbox">
<input type="checkbox" class="col-lg-1">记住密码</input>
</div>
<div class="col-lg-10"></div>
<div class="col-lg-10">
<button type="button" class="btn btn-success col-lg-12">登录</button>
</div>
</div>
</div>
</form>
</body>
</html>

【注意】本代码在chrome浏览器上显示正常,但是在IE8上有问题,代码也没做对IE浏览器的支持,的确做法不对,我会后期更新的。

以上所述是小编给大家介绍的Boostrap实现的登录界面实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对绿夏网网站的支持!



!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103