如何将我的登录div居中

时间:2016-11-07 16:20:17

标签: html css css3

我有一个登录页面但是在登录框位于页眉和页脚之间而没有滚动条存在时出现问题。下面是我的网页

登录框似乎是浮动的,示例在下面 web page floating login box

我想要做的是将登录框置于页眉和页脚之间,我不希望它可滚动。我的css代码和html在下面



@import url(https://fonts.googleapis.com/css?family=Roboto:300);

.login-page {
  width: 360px;
  padding: 8% 0 0;
}
.form {
  position: relative;
  z-index: 1;
  background: #FFFFFF;
  max-width: 360px;
  margin: 0 auto 100px;
  padding: 45px;
  text-align: center;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.form input {
  font-family: "Roboto", sans-serif;
  outline: 0;
  background: #f2f2f2;
  width: 100%;
  border: 0;
  margin: 0 0 15px;
  padding: 15px;
  box-sizing: border-box;
  font-size: 14px;
}
.form button {
  font-family: "Roboto", sans-serif;
  text-transform: uppercase;
  outline: 0;
  background: #4CAF50;
  width: 100%;
  border: 0;
  padding: 15px;
  color: #FFFFFF;
  font-size: 14px;
  -webkit-transition: all 0.3 ease;
  transition: all 0.3 ease;
  cursor: pointer;
}
.form button:hover,.form button:active,.form button:focus {
  background: #43A047;
}
.form .message {
  margin: 15px 0 0;
  color: #b3b3b3;
  font-size: 12px;
}
.form .message a {
  color: #4CAF50;
  text-decoration: none;
}
.form .register-form {
  display: none;
}
.container {
  position: relative;
  z-index: 1;
  max-width: 300px;
  margin: 0 auto;
}
.container:before, .container:after {
  content: "";
  display: block;
  clear: both;
}
.container .info {
  margin: 50px auto;
  text-align: center;
}
.container .info h1 {
  margin: 0 0 15px;
  padding: 0;
  font-size: 36px;
  font-weight: 300;
  color: #1a1a1a;
}
.container .info span {
  color: #4d4d4d;
  font-size: 12px;
}
.container .info span a {
  color: #000000;
  text-decoration: none;
}
.container .info span .fa {
  color: #EF3B3A;
}
body {
  background: white; /* fallback for old browsers 
  background: -webkit-linear-gradient(right, #76b852, #8DC26F);
  background: -moz-linear-gradient(right, #76b852, #8DC26F);
  background: -o-linear-gradient(right, #76b852, #8DC26F);
  background: linear-gradient(to left, #76b852, #8DC26F);
  */
  font-family: "Roboto", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale; 
 
}

footer {
background-color: #FFF;
position:fixed;
bottom: 0px;
width: 100%;
text-align: center;
}


header {
background-color: #FFF;
position:fixed;
top: 0px;
width: 100%;
text-align: center;
}

<body>
    <header class="bgm-green m-b-30">
        <ul class="h-inner">
            <li class="hi-logo m-10" >
                <img id="logo-image" class="logo-image" src="img/logo.png" alt="Logo">
            </li>

            <li class="pull-right">
				 <h2 class="c-white m-r-15 f-300"></h2>
			</li>
           
    </header>

    <section id="content" class="bgm-white">
        <div >
            <div class="login-page">
                <div class="form">
                    <form class="login-form">
                        <div class="input-group m-b-20">
                            <span class="input-group-addon"><i class="zmdi zmdi-account"></i></span>
                            <div class="fg-line">
                                <input type="text" class="form-control" placeholder="Username">
                            </div>
                        </div>

                        <div class="input-group m-b-20">
                            <span class="input-group-addon"><i class="zmdi zmdi-lock"></i></span>
                            <div class="fg-line">
                                <input type="password" class="form-control" placeholder="Password">
                            </div>
                        </div>

                        <label class="checkbox">
                            <input id="checker" type="checkbox" value="">
                            <i class="input-helper"></i>
                            <span>Remember me</span>
                        </label>
                        <button>login</button>
                        <p class="message">Unable to login? Contact our admin <a href="#">here</a></p>
                    </form>
                </div>
            </div>
        </div>
    </section>


    <footer class="bgm-green">
        <div class="c-white">
            Copyright &copy; 2016 First High Tower Infotech
        </div>
    </footer>

    <!-- Older IE warning message -->
    <!--[if lt IE 9]>
            <div class="ie-warning">
                <h1 class="c-white">Warning!!</h1>
                <p>You are using an outdated version of Internet Explorer, please upgrade <br/>to any of the following web browsers to access this website.</p>
                <div class="iew-container">
                    <ul class="iew-download">
                        <li>
                            <a href="http://www.google.com/chrome/">
                                <img src="img/browsers/chrome.png" alt="">
                                <div>Chrome</div>
                            </a>
                        </li>
                        <li>
                            <a href="https://www.mozilla.org/en-US/firefox/new/">
                                <img src="img/browsers/firefox.png" alt="">
                                <div>Firefox</div>
                            </a>
                        </li>
                        <li>
                            <a href="http://www.opera.com">
                                <img src="img/browsers/opera.png" alt="">
                                <div>Opera</div>
                            </a>
                        </li>
                        <li>
                            <a href="https://www.apple.com/safari/">
                                <img src="img/browsers/safari.png" alt="">
                                <div>Safari</div>
                            </a>
                        </li>
                        <li>
                            <a href="http://windows.microsoft.com/en-us/internet-explorer/download-ie">
                                <img src="img/browsers/ie.png" alt="">
                                <div>IE (New)</div>
                            </a>
                        </li>
                    </ul>
                </div>
                <p>Sorry for the inconvenience!</p>
            </div>
        <![endif]-->

    <!-- Javascript Libraries -->
    <!-- Placeholder for IE9 -->
    <!--[if IE 9 ]>
            <script src="vendors/bower_components/jquery-placeholder/jquery.placeholder.min.js"></script>
        <![endif]-->

    <script data-main="lib/js/config" src="lib/js/Requirejs.js"></script>

    <script>
		require(['config'], function(){
			require(['js/loaders/loginloader']);
		});
	</script>
</body>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:0)

margin: 0 auto;添加到.login-page,使其位于页面中央。

就像:

.login-page {
  margin: 0 auto;
}

或者查看下面的代码段:

@import url(https://fonts.googleapis.com/css?family=Roboto:300);

.login-page {
  width: 360px;
  padding: 8% 0 0;
}
.form {
  position: relative;
  z-index: 1;
  background: #FFFFFF;
  max-width: 360px;
  margin: 0 auto 100px;
  padding: 45px;
  text-align: center;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.form input {
  font-family: "Roboto", sans-serif;
  outline: 0;
  background: #f2f2f2;
  width: 100%;
  border: 0;
  margin: 0 0 15px;
  padding: 15px;
  box-sizing: border-box;
  font-size: 14px;
}
.form button {
  font-family: "Roboto", sans-serif;
  text-transform: uppercase;
  outline: 0;
  background: #4CAF50;
  width: 100%;
  border: 0;
  padding: 15px;
  color: #FFFFFF;
  font-size: 14px;
  -webkit-transition: all 0.3 ease;
  transition: all 0.3 ease;
  cursor: pointer;
}
.form button:hover,.form button:active,.form button:focus {
  background: #43A047;
}
.form .message {
  margin: 15px 0 0;
  color: #b3b3b3;
  font-size: 12px;
}
.form .message a {
  color: #4CAF50;
  text-decoration: none;
}
.form .register-form {
  display: none;
}
.container {
  position: relative;
  z-index: 1;
  max-width: 300px;
  margin: 0 auto;
}
.container:before, .container:after {
  content: "";
  display: block;
  clear: both;
}
.container .info {
  margin: 50px auto;
  text-align: center;
}
.container .info h1 {
  margin: 0 0 15px;
  padding: 0;
  font-size: 36px;
  font-weight: 300;
  color: #1a1a1a;
}
.container .info span {
  color: #4d4d4d;
  font-size: 12px;
}
.container .info span a {
  color: #000000;
  text-decoration: none;
}
.container .info span .fa {
  color: #EF3B3A;
}
body {
  background: white; /* fallback for old browsers 
  background: -webkit-linear-gradient(right, #76b852, #8DC26F);
  background: -moz-linear-gradient(right, #76b852, #8DC26F);
  background: -o-linear-gradient(right, #76b852, #8DC26F);
  background: linear-gradient(to left, #76b852, #8DC26F);
  */
  font-family: "Roboto", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale; 
 
}

footer {
background-color: #FFF;
position:fixed;
bottom: 0px;
width: 100%;
text-align: center;
}


header {
background-color: #FFF;
position:fixed;
top: 0px;
width: 100%;
text-align: center;
}

.login-page {
  margin: 0 auto;
}
<body>
<header class="bgm-green m-b-30">
    <ul class="h-inner">
        <li class="hi-logo m-10" >
            <img id="logo-image" class="logo-image" src="img/logo.png" alt="Logo">
        </li>

        <li class="pull-right">
             <h2 class="c-white m-r-15 f-300">Lagos State House of Assembly e-Parliament Management System</h2>
        </li>
    </ul>
</header>

<section id="content" class="bgm-white">
    <div >
        <div class="login-page">
            <div class="form">
                <form class="login-form">
                    <div class="input-group m-b-20">
                        <span class="input-group-addon"><i class="zmdi zmdi-account"></i></span>
                        <div class="fg-line">
                            <input type="text" class="form-control" placeholder="Username">
                        </div>
                    </div>

                    <div class="input-group m-b-20">
                        <span class="input-group-addon"><i class="zmdi zmdi-lock"></i></span>
                        <div class="fg-line">
                            <input type="password" class="form-control" placeholder="Password">
                        </div>
                    </div>

                    <label class="checkbox">
                        <input id="checker" type="checkbox" value="">
                        <i class="input-helper"></i>
                        <span>Remember me</span>
                    </label>
                    <button>login</button>
                    <p class="message">Unable to login? Contact our admin <a href="#">here</a></p>
                </form>
            </div>
        </div>
    </div>
</section>


<footer class="bgm-green">
    <div class="c-white">
        Copyright &copy; 2016 First High Tower Infotech
    </div>
</footer>

希望这有帮助!

答案 1 :(得分:0)

您的代码看起来很好。编辑了你的标记和片段以消除一些错误。

回答您的问题只是将margin: auto;添加到您的登录div CSS

.login-page {
  width: 360px;
  padding: 8% 0 0;
  margin: auto;
}

&#13;
&#13;
@import url(https://fonts.googleapis.com/css?family=Roboto:300);

.login-page {
  width: 360px;
  padding: 8% 0 0;
  margin: auto;
}
.form {
  position: relative;
  z-index: 1;
  background: #FFFFFF;
  max-width: 360px;
  margin: 0 auto 100px;
  padding: 45px;
  text-align: center;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.form input {
  font-family: "Roboto", sans-serif;
  outline: 0;
  background: #f2f2f2;
  width: 100%;
  border: 0;
  margin: 0 0 15px;
  padding: 15px;
  box-sizing: border-box;
  font-size: 14px;
}
.form button {
  font-family: "Roboto", sans-serif;
  text-transform: uppercase;
  outline: 0;
  background: #4CAF50;
  width: 100%;
  border: 0;
  padding: 15px;
  color: #FFFFFF;
  font-size: 14px;
  -webkit-transition: all 0.3 ease;
  transition: all 0.3 ease;
  cursor: pointer;
}
.form button:hover,.form button:active,.form button:focus {
  background: #43A047;
}
.form .message {
  margin: 15px 0 0;
  color: #b3b3b3;
  font-size: 12px;
}
.form .message a {
  color: #4CAF50;
  text-decoration: none;
}
.form .register-form {
  display: none;
}
.container {
  position: relative;
  z-index: 1;
  max-width: 300px;
  margin: 0 auto;
}
.container:before, .container:after {
  content: "";
  display: block;
  clear: both;
}
.container .info {
  margin: 50px auto;
  text-align: center;
}
.container .info h1 {
  margin: 0 0 15px;
  padding: 0;
  font-size: 36px;
  font-weight: 300;
  color: #1a1a1a;
}
.container .info span {
  color: #4d4d4d;
  font-size: 12px;
}
.container .info span a {
  color: #000000;
  text-decoration: none;
}
.container .info span .fa {
  color: #EF3B3A;
}
body {
  background: white; /* fallback for old browsers 
  background: -webkit-linear-gradient(right, #76b852, #8DC26F);
  background: -moz-linear-gradient(right, #76b852, #8DC26F);
  background: -o-linear-gradient(right, #76b852, #8DC26F);
  background: linear-gradient(to left, #76b852, #8DC26F);
  */
  font-family: "Roboto", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale; 
 
}

footer {
background-color: #FFF;
position:fixed;
bottom: 0px;
width: 100%;
text-align: center;
}


header {
background-color: #FFF;
position:fixed;
top: 0px;
width: 100%;
text-align: center;
}
&#13;
<body>
<header class="bgm-green m-b-30">
    <ul class="h-inner">
        <li class="hi-logo m-10" >
            <img id="logo-image" class="logo-image" src="img/logo.png" alt="Logo">
        </li>

        <li class="pull-right">
             <h2 class="c-white m-r-15 f-300">System</h2>
        </li>
    </ul>
</header>

<section id="content" class="bgm-white">
    <div >
        <div class="login-page">
            <div class="form">
                <form class="login-form">
                    <div class="input-group m-b-20">
                        <span class="input-group-addon"><i class="zmdi zmdi-account"></i></span>
                        <div class="fg-line">
                            <input type="text" class="form-control" placeholder="Username">
                        </div>
                    </div>

                    <div class="input-group m-b-20">
                        <span class="input-group-addon"><i class="zmdi zmdi-lock"></i></span>
                        <div class="fg-line">
                            <input type="password" class="form-control" placeholder="Password">
                        </div>
                    </div>

                    <label class="checkbox">
                        <input id="checker" type="checkbox" value="">
                        <i class="input-helper"></i>
                        <span>Remember me</span>
                    </label>
                    <button>login</button>
                    <p class="message">Unable to login? Contact our admin <a href="#">here</a></p>
                </form>
            </div>
        </div>
    </div>
</section>


<footer class="bgm-green">
    <div class="c-white">
        Copyright &copy; 2016 First High Tower Infotech
    </div>
</footer>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

你想要这样的东西: -

&#13;
&#13;
body{
	background-color:#9F3;
	margin:44px 0px 0px 0px;
	}
div#header{
	position:fixed;
	top:0px;
	left:0px;
	width:100%;
	height:20px;
	color: #F00;
	background-color:#603;
	padding:8px;
	
	}
	.aa{
	width:300px;
	height:240px;
	background-color:rgba(0,0,0,0.5);
	margin:0 auto;
	margin-top:40px;
	padding-top:10px;
	padding-left:50px;
	border-radius:15px;
	-webkit-border-radius:15px;
	-o-border-radius:15px;
	-moz-border-radius:15px;
	color:#FFF;
	font-weight:bold;
	box-shadow:inset -4px -4px rgba(0,0,0,0.5);
	}
.aa input[type="text"]{
	width:200px;
	height:35px;
	border:0;
	border-radius:5px;
	-webkit-border-radius:5px;
	-o-border-radius:5px;
	-moz-border-radius:5px;
	padding-left:5px;
	}
.aa input[type="password"]{
	width:200px;
	height:35px;
	border:0;
	border-radius:5px;
	-webkit-border-radius:5px;
	-o-border-radius:5px;
	-moz-border-radius:5px;
	padding-left:5px;
	}
.aa input[type="submit"]{
	width:100px;
	height:35px;
	border:0;
	border-radius:5px;
	-webkit-border-radius:5px;
	-o-border-radius:5px;
	-moz-border-radius:5px;
	background-color:#0FC;
	font-weight:bold;
	}
	
div#footer{
	position:fixed;
	bottom:0px;
	left:0px;
	width:100%;
	height:20px;
	color: #F00;
	background-color:#603;
	padding:8px;
	
	}
&#13;
<div id="header">
</div>

 <div class="aa">
<h1>Login</h1>
<form>
 <input type="text" placeholder="Please Enter Username"><br><br>
 <input type="password" placeholder="Please Enter Password"><br><br>
 <input type="submit" value="Login">
 
</form>
</div>
 <div id="footer">

</div>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

&#13;
&#13;
@import url(https://fonts.googleapis.com/css?family=Roboto:300);

.login-page {
  width: 360px;
  padding: 8% 0 0;
  margin:0 auto;
}
.form {
  position: relative;
  z-index: 1;
  background: #FFFFFF;
  max-width: 360px;
  margin: 0 auto 100px;
  padding: 45px;
  text-align: center;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.form input {
  font-family: "Roboto", sans-serif;
  outline: 0;
  background: #f2f2f2;
  width: 100%;
  border: 0;
  margin: 0 0 15px;
  padding: 15px;
  box-sizing: border-box;
  font-size: 14px;
}
.form button {
  font-family: "Roboto", sans-serif;
  text-transform: uppercase;
  outline: 0;
  background: #4CAF50;
  width: 100%;
  border: 0;
  padding: 15px;
  color: #FFFFFF;
  font-size: 14px;
  -webkit-transition: all 0.3 ease;
  transition: all 0.3 ease;
  cursor: pointer;
}
.form button:hover,.form button:active,.form button:focus {
  background: #43A047;
}
.form .message {
  margin: 15px 0 0;
  color: #b3b3b3;
  font-size: 12px;
}
.form .message a {
  color: #4CAF50;
  text-decoration: none;
}
.form .register-form {
  display: none;
}
.container {
  position: relative;
  z-index: 1;
  max-width: 300px;
  margin: 0 auto;
}
.container:before, .container:after {
  content: "";
  display: block;
  clear: both;
}
.container .info {
  margin: 50px auto;
  text-align: center;
}
.container .info h1 {
  margin: 0 0 15px;
  padding: 0;
  font-size: 36px;
  font-weight: 300;
  color: #1a1a1a;
}
.container .info span {
  color: #4d4d4d;
  font-size: 12px;
}
.container .info span a {
  color: #000000;
  text-decoration: none;
}
.container .info span .fa {
  color: #EF3B3A;
}
body {
  background: white; /* fallback for old browsers 
  background: -webkit-linear-gradient(right, #76b852, #8DC26F);
  background: -moz-linear-gradient(right, #76b852, #8DC26F);
  background: -o-linear-gradient(right, #76b852, #8DC26F);
  background: linear-gradient(to left, #76b852, #8DC26F);
  */
  font-family: "Roboto", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale; 
 
}

footer {
background-color: #FFF;
position:fixed;
bottom: 0px;
width: 100%;
text-align: center;
}


header {
background-color: #FFF;
position:fixed;
top: 0px;
width: 100%;
text-align: center;
}
&#13;
<body>
    <header class="bgm-green m-b-30">
        <ul class="h-inner">
            <li class="hi-logo m-10" >
                <img id="logo-image" class="logo-image" src="img/logo.png" alt="Logo">
            </li>

            <li class="pull-right">
				 <h2 class="c-white m-r-15 f-300"></h2>
			</li>
           
    </header>

    <section id="content" class="bgm-white">
        <div >
            <div class="login-page">
                <div class="form">
                    <form class="login-form">
                        <div class="input-group m-b-20">
                            <span class="input-group-addon"><i class="zmdi zmdi-account"></i></span>
                            <div class="fg-line">
                                <input type="text" class="form-control" placeholder="Username">
                            </div>
                        </div>

                        <div class="input-group m-b-20">
                            <span class="input-group-addon"><i class="zmdi zmdi-lock"></i></span>
                            <div class="fg-line">
                                <input type="password" class="form-control" placeholder="Password">
                            </div>
                        </div>

                        <label class="checkbox">
                            <input id="checker" type="checkbox" value="">
                            <i class="input-helper"></i>
                            <span>Remember me</span>
                        </label>
                        <button>login</button>
                        <p class="message">Unable to login? Contact our admin <a href="#">here</a></p>
                    </form>
                </div>
            </div>
        </div>
    </section>


    <footer class="bgm-green">
        <div class="c-white">
            Copyright &copy; 2016 First High Tower Infotech
        </div>
    </footer>

    <!-- Older IE warning message -->
    <!--[if lt IE 9]>
            <div class="ie-warning">
                <h1 class="c-white">Warning!!</h1>
                <p>You are using an outdated version of Internet Explorer, please upgrade <br/>to any of the following web browsers to access this website.</p>
                <div class="iew-container">
                    <ul class="iew-download">
                        <li>
                            <a href="http://www.google.com/chrome/">
                                <img src="img/browsers/chrome.png" alt="">
                                <div>Chrome</div>
                            </a>
                        </li>
                        <li>
                            <a href="https://www.mozilla.org/en-US/firefox/new/">
                                <img src="img/browsers/firefox.png" alt="">
                                <div>Firefox</div>
                            </a>
                        </li>
                        <li>
                            <a href="http://www.opera.com">
                                <img src="img/browsers/opera.png" alt="">
                                <div>Opera</div>
                            </a>
                        </li>
                        <li>
                            <a href="https://www.apple.com/safari/">
                                <img src="img/browsers/safari.png" alt="">
                                <div>Safari</div>
                            </a>
                        </li>
                        <li>
                            <a href="http://windows.microsoft.com/en-us/internet-explorer/download-ie">
                                <img src="img/browsers/ie.png" alt="">
                                <div>IE (New)</div>
                            </a>
                        </li>
                    </ul>
                </div>
                <p>Sorry for the inconvenience!</p>
            </div>
        <![endif]-->

    <!-- Javascript Libraries -->
    <!-- Placeholder for IE9 -->
    <!--[if IE 9 ]>
            <script src="vendors/bower_components/jquery-placeholder/jquery.placeholder.min.js"></script>
        <![endif]-->

    <script data-main="lib/js/config" src="lib/js/Requirejs.js"></script>

    <script>
		require(['config'], function(){
			require(['js/loaders/loginloader']);
		});
	</script>
</body>
&#13;
&#13;
&#13;