基于 css 的响应式登录表单

Responsive login form with based on css

我尝试了一些方法来使此页面在背景中显示背景图像并在页面中央显示注册框。无法使用 bootstrap 并且 css 无法 100% 工作。

最好的办法是使其具有响应性,以便它支持移动设备和桌面设备

码笔linkhttp://codepen.io/anon/pen/eBGzOY

<body onload="document.getElementById('user').focus();" style="background-color: ">
  <div id="main">
    <div id='user-agreement' style="display: none">
      <table width='100%'>
        <tbody>
          <tr>
            <td>
              <h3>User Agreement Policy</h3>
            </td>
          </tr>
          <tr>
            <td>
              Please do login with valid Guest credentails.
            </td>
          </tr>
          <tr>
            <td align='center'><br />
              <input type='button' value='Accept' onClick="" />
            </td>
          </tr>
        </tbody>
      </table>
    </div>

    <div id="logins">
      <div id="errorbox" style="display: none">
      </div>
      <div id="registered" style="">
        <h1 id="registeredhdr" class="swap"><span>REGISTERED USER</span></h1>
        <form action="login" id="regform" method="post" autocomplete="off" title="Form used by registered users to login">

          <div id="usernamebox">
            <label for="user" accesskey="u">USERNAME</label>
            <input type="text" name="user" id="user" size="25" class="text" accesskey="u" />
          </div>

          <div id="passwordbox">
            <label for="password" accesskey="p">PASSWORD</label>
            <input id="password" name="password" type="password" size="25" class="text" accesskey="p" />
          </div>

          <div id="fqdnbox" style="display: none"></div>

          <input type="hidden" name="cmd" value="authenticate" />
          <input type="submit" name="Login" value="Log In" class="button" />
          <p>Logging in as a registered user indicates you have read and accepted the <a href="javascript:void(0)" onclick="showPolicy();">Acceptable Use Policy</a>.</p>

        </form>
      </div>

      <div style="display: none">
        <form action="login" id="only_aup_form" method="post" title="">
          <input type="hidden" name="accept_aup" value="accept_aup" />
          <input type="hidden" name="requested_url" value="" />
        </form>
      </div>

      <div id="guest" style="display: none">
        <h1 id="guesthdr" class="swap"><span>GUEST USER</span></h1>
        <form action="login" id="guestform" emweb_name="captive_portal_guest" method="post" title="Form used by guest users to login">

          <div id="emailbox">
            <label for="email" accesskey="e">EMAIL</label>
            <input id="email" name="email" type="text" size="25" class="text" accesskey="e" />
          </div>

          <input type="hidden" name="cmd" value="authenticate" />
          <input type="submit" name="Login" value="Log In" class="button" />

        </form>
      </div>

      <div id="instructions" style="display: none;">
        <div id="instructionstext"></div>
        <div id="instructionsbg"></div>
      </div>
    </div>
  </div>


</body>

是希望this是你想要的!
这是代码,但请检查 link tho:

body {
   width: 100%;
   height: 100%;
   margin: 0;
   padding: 0;
   font-family: arial;
}

#main {
   position: relative;
   top: 50%;

   max-width: 500px;
   margin-left: auto;
   margin-right: auto;
   vertical-align: middle;
}

#passwordbox, #usernamebox {
   padding-bottom: 5px;
}

a, .swap {
   color: #9999ff;
}

ul {
   list-style: none;
   padding: 0px;
}

li {
   padding-bottom: 10px;
}

input[type=text], input[type=password] {
    color: #9999ff;
    height: 20px;
    padding: 5px;
    text-decoration: none;
    border: 1px solid #9999ff;
    background-color: transparent;
    border-radius: 1px;
}

textarea {
    color: #9999ff;
    padding: 5px;
    text-decoration: none;
    border: 1px solid #9999ff;
    background-color: transparent;
    height: 6em;
    width: 30em;
   font-family: arial;
   border-radius: 1px;
   -ms-overflow-style: none
}

input[type=submit] {
    width: 120px;
    height: 30px;
    cursor: pointer;
    color: #9999ff;
    text-decoration: none;
    border: 1px solid #9999ff;
    background-color: transparent;
    -webkit-appearance: none;
    border-radius: 1px;
   padding-right: 80px;
}

::-webkit-input-placeholder {
   font-family: arial;
   color: #9999ff;
}

:-moz-placeholder { /* Firefox 18- */
   font-family: arial;
   color: #9999ff;
}

::-moz-placeholder {  /* Firefox 19+ */
   font-family: arial;
   color: #9999ff;
}

:-ms-input-placeholder {  
   font-family: arial;
   color: #9999ff;
}

我同样使用了以下内容

<!DOCTYPE html>
<html>

<head>
    <title>Login</title>
        <meta charset="utf-8">
        <link href="css/style.css" rel='stylesheet' type='text/css' />
        <meta name="viewport" content="width=device-width, initial-scale=1">
<style>

/* reset */
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,dl,dt,dd,ol,nav ul,nav li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;}
article, aside, details, figcaption, figure,footer, header, hgroup, menu, nav, section {display: block;}
ol,ul{list-style:none;margin:0px;padding:0px;}
blockquote,q{quotes:none;}
blockquote:before,blockquote:after,q:before,q:after{content:'';content:none;}
table{border-collapse:collapse;border-spacing:0;}
/* start editing from here */
a{text-decoration:none;}
.txt-rt{text-align:right;}/* text align right */
.txt-lt{text-align:left;}/* text align left */
.txt-center{text-align:center;}/* text align center */
.float-rt{float:right;}/* float right */
.float-lt{float:left;}/* float left */
.clear{clear:both;}/* clear float */
.pos-relative{position:relative;}/* Position Relative */
.pos-absolute{position:absolute;}/* Position Absolute */
.vertical-base{ vertical-align:baseline;}/* vertical align baseline */
.vertical-top{  vertical-align:top;}/* vertical align top */
nav.vertical ul li{ display:block;}/* vertical menu */
nav.horizontal ul li{   display: inline-block;}/* horizontal menu */
img{max-width:100%;}
/*end reset*/
/****-----start-body----****/
body{
    background:url(bg1.jpg)  no-repeat center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    position:relative;
    font-family: 'Open Sans', sans-serif;

}
.login-form {
    background:#fff;
    width:32%;
    max-width:400px;
    margin:9% auto 4% auto;
    position: relative;
}
p{margin-top:20px;}
.head {
    position: absolute;
    top:-15%;
    left: 35%;
}
.head img {
    border-radius:50%;
    -webkit-border-radius:50%;
    -o-border-radius:50%;
    -moz-border-radius:50%;
    border:6px solid rgba(221, 218, 215, 0.23);
}
form {
    padding:24% 2.5em;
    padding-bottom:20px;
}
form li{
    border:1px solid #B4B2B2;
    list-style:none;
    margin-bottom:25px;
    width:100%;
    background:none;
    border-radius: 0.3em;
    -webkit-border-radius: 0.3em;
    -o- border-radius: 0.3em;
    -moz-border-radius: 0.3em;

}

.icon{
    background:url(icons.png)  no-repeat 0px 0px;
    height:30px;
    width:30px;
    display: block;
    float:left;
    margin:7px -11px 0px 0px
}

.user{
    background: url(icons.png) no-repeat 12px 11px;

}
.lock{
    background: url(icons.png) no-repeat -17px 11px;
}
input[type="text"], input[type="password"] {
    font-family: 'Open Sans', sans-serif;
    width:60%;
    padding:0.7em 2em 0.7em 1.7em;
    color:#858282;
    font-size:18px;
    outline: none;
    background: none;
    border:none;
    font-weight:600;
    }
form li:hover{
    border:1px solid #40A9DF;
     box-shadow: 0 0 1em #40A9DF;
     -webkit-box-shadow: 0 0 1em #40A9DF;
     -o-box-shadow: 0 0 1em #40A9DF;
     -moz-box-shadow: 0 0 1em #40A9DF;
}
input[type="submit"]{
    float:right;
    font-size:18px;
    display: inline-block;
    font-weight:600;
    color: #fff;
    transition: 0.1s all;
    -webkit-transition: 0.1s all;
    -moz-transition: 0.1s all;
    -o-transition: 0.1s all;
    cursor: pointer;
    outline: none;
    padding:15px 10px;
    margin-top:3px;
    font-family: 'Open Sans', sans-serif;
    width:40%;
    border:none;
    border-radius: 0.3em;
    -webkit-border-radius: 0.3em;
    -o- border-radius: 0.3em;
    -moz-border-radius: 0.3em;
    background: #bbb; 

}
input[type="submit"]:hover{
    background: #ccc; /* Old browsers */

}
/***************************/
.p-container{
    margin-top:2em;
}
.p-container  .checkbox input {
    position: absolute;
    left: -9999px;
}
.p-container.checkbox i {
    border-color: #fff;
    transition: border-color 0.3s;
    -o-transition: border-color 0.3s;
    -ms-transition: border-color 0.3s;
    -moz-transition: border-color 0.3s;
    -webkit-transition: border-color 0.3s;

}
.p-container.checkbox i:hover {
    border-color:red;

}
.p-container  i:before {
    background-color: #2da5da;  
}
.p-container  .rating label {
    color: #ccc;
    transition: color 0.3s;
    -o-transition: color 0.3s;
    -ms-transition: color 0.3s;
    -moz-transition: color 0.3s;
    -webkit-transition: color 0.3s;
}
.p-container  .checkbox input + i:after {
    position: absolute;
    opacity: 0;
    transition: opacity 0.1s;
    -o-transition: opacity 0.1s;
    -ms-transition: opacity 0.1s;
    -moz-transition: opacity 0.1s;
    -webkit-transition: opacity 0.1s;
}
.p-container .checkbox input + i:after {
    content:url(../images/tick.png) no-repeat 7px 1px;
    top:-15px;
    left:1px;
    width: 15px;
    height: 15px;
}
.p-container  .checkbox {
    float: left;
    margin-right: 30px;
}
.p-container .checkbox {
    padding-left: 40px;
    font-size: 16px;
    line-height:60px;
    color:#858282;
    cursor: pointer;
    font-family: 'Open Sans', sans-serif;   
    font-weight: 600;
}
.p-container  .checkbox {
    position: relative;
    display: block;
}
.p-container  .checkbox i {
    position: absolute;
    top:18px;
    left:5px;
    display: block;
    width:22px;
    height:22px;
    outline: none;
    border:1px solid #999;
    background:#fff;
    border-radius:4px;
    -webkit-border-radius:4px;
    -moz-border-radius:4px;
    -o-border-radius:4px;

}
.p-container  .checkbox input + i:after {
    position: absolute;
    opacity: 0;
    transition: opacity 0.1s;
    -o-transition: opacity 0.1s;
    -ms-transition: opacity 0.1s;
    -moz-transition: opacity 0.1s;
    -webkit-transition: opacity 0.1s;
}
.p-container .checkbox input + i:after {
    color: #2da5da;
}
.p-container .checkbox input:checked + i,
.p-container . input:checked + i {
    border-color: #2da5da;  
}
.p-container .rating input:checked ~ label {
    color: #2da5da; 
}

.p-container .checkbox input:checked + i:after {
    opacity: 1;
}

/****************/
.copy-right {
    position: absolute;
    bottom:-16%;
    left: 43.7%;
}
.copy-right p {
    color: #fff;
    font-size: 1em;
    font-family: 'Open Sans', sans-serif;   
    font-weight: 600;
}
.copy-right p a {
    font-family: 'Open Sans', sans-serif;   
    font-size: 1em;
    color:#FF8E03;
    -webkit-transition: all 0.3s ease-out;
    -moz-transition: all 0.3s ease-out;
    -ms-transition: all 0.3s ease-out;
    -o-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
}
.copy-right p a:hover {
    color:#fff;
}
/*-----start-responsive-design------*/
@media (min-width:1500px){
.login-form  {
        margin:15% auto 0;
        width:45%;
    }
    .copy-right {
    left: 41%;
    bottom:-18%;
    }
}
@media (max-width:1024px){
.login-form  {
        margin:8% auto 0;
        width:45%;
    }
    .copy-right {
    left: 41%;
    bottom:-18%;
    }
}
@media (max-width:768px){
    .login-form  {
        margin:12% auto 0;
        width:57%;
    }
    .copy-right {
    left:38%;
    bottom:-14%;
    }
}
@media (max-width:640px){                                  
    .login-form  {
        margin:13% auto 0;
        width:70%;
    }
    .copy-right {
    left:36%;
    bottom:-18%;
    }
}
@media (max-width:480px){                                  
    .login-form  {
        margin:20% auto 0;
        width:90%;
    }
    .copy-right {
    left:30%;
    bottom:-17%;
    }
.login-form {
  margin: 30% auto 0;

}

}
@media (max-width:320px){                                  
    .login-form  {
        margin:20% auto 0;
        width:95%;
    }
    form{
        padding:19% 1.5em; 
        padding-bottom:20px;
    }
    form li{
        margin-top:10px;
    }

    input[type="text"], input[type="password"]{
        font-size:15px;
        padding: 0.5em 1em 0.5em 1em;
    }
    input[type="submit"]{
        float:none;
        font-size: 15px;
        padding: 10px 10px;
        width: 40%;
        margin-left: 28%;
    }
    .head{
        top:-12%;
        left:35.5%;
    }
    .head img {
    width:69%;
    }
    .user {
        background: url(../images/icons.png) no-repeat 12px 4px;
    }
    .lock {
        background: url(../images/icons.png) no-repeat -20px 3px;
    }
    .p-container .checkbox {
    float: none;
    text-align: center;
    }
    .p-container{
        margin-top: 0;
    }
    .icon{
        margin:6px -11px 0px 0px;
    }
    .p-container .checkbox i {
    position: absolute;
    top: 18px;
    left: 43px;
    }
    .copy-right {
    left:20%;
    bottom:-10%;
    }
}

</style>
<script language="javascript" type="text/javascript">
function cp_ua() {
    this.div_ids = new Array('user-agreement', 'logins');
    this.cp_a_type = null;
    this.init = function(cp_a_type) {
        if(this.cp_a_type == null)
            this.cp_a_type = cp_a_type;
    }
    this.show_forms = function(isUa, isDisabled) {
        var __user_agreement = (!isUa) ? true : false;
        var __cmp_str = (__user_agreement) ? this.div_ids[0] : this.div_ids[1];
        var vm=null, vmid=null;
        for(var i=0; i<this.div_ids.length; i++) {
            var div_id = this.div_ids[i];
            var div_ref = document.getElementById(div_id);
            var disp_str = (div_id.match(__cmp_str)) ? 'block' : 'none';
            if(div_ref) {
                div_ref.style.display = disp_str;
            }
        }
        if(isUa && (vm = document.getElementsByName(this.cp_a_type)[0]) != null) {
            this.ed_fields(isDisabled);
            vm.focus();
        } 
    }
    this.ed_fields = function(flag) {   /* Enable/Disable fields */
        var inputs = document.getElementsByTagName('input');
        for(var j=0; j<inputs.length; j++) {
            var vm = inputs[j];
            if(vm) {
                vm.disabled = flag;
            }
        }
        return;
    }
    this.only_aup = function(requested_url) {
        var xform = document.getElementById("only_aup_form");
        var url = document.getElementsByName("requested_url")[0];
        url.value = requested_url;
        xform.submit();
        return;
    }
}
var CpUa = new cp_ua();

function showPolicy() {
    win = window.open("/upload/custom/Guest-Captive-cp_prof/acceptableusepolicy.html", "policy", "height=550,width=550,scrollbars=1");
}
</script>
</head>

<body onload="document.getElementById('user').focus();" style="background-color: ">

                 <!-----start-main---->
                <div class="login-form">
                    <div class="head">
                        <img src="logo.jpg" alt=""/>

                    </div>
                <form action="login" id="regform" method="post" autocomplete="off" title="Form used by registered users to login">
                    <li>
                        <input id="user" type="text" class="text" placeholder="USERNAME" value="USERNAME" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'USERNAME';}" accesskey="u" ><a href="#" class=" icon user"></a>

                    </li>
                    <li>
                        <input id="password" name="password" placeholder="PASSWORD" accesskey="p" type="password" value="" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = '';}"><a href="#" class=" icon lock"></a>
                    </li>
                    <div class="p-container">
                                <div id="fqdnbox" style="display: none"></div>
                                <input type="hidden" name="cmd" value="authenticate" />
                                <input type="submit" name="Login" value="Log In" >
                            <div class="clear"> </div>
                    </div>
                                <p>Logging in as a registered user indicates you have   read and accepted the <a href="javascript:void(0)"  onclick="showPolicy();">Acceptable Use Policy</a>.</p>
                </form>
            </div>
            <!--//End-login-form-->
        <div  style="display: none">
            <form action="login" id="only_aup_form" method="post" title="">
            <input type="hidden" name="accept_aup" value="accept_aup" />
            <input type="hidden" name="requested_url" value="" />
            </form>
        </div>
                <div id="guest" style="display: none">
            <h1 id="guesthdr" class="swap"><span>GUEST USER</span></h1>
            <form action="login" id="guestform" emweb_name="captive_portal_guest" method="post" title="Form used by guest users to login">

            <div id="emailbox">
            <label for="email" accesskey="e">EMAIL</label>
            <input id="email" name="email" type="text" size="25" class="text" accesskey="e" />
            </div>

            <input type="hidden" name="cmd" value="authenticate" />
            <input type="submit" name="Login" value="Log In" class="button" />

            </form>
        </div>

        <div id="instructions" style="display: none;">
            <div id="instructionstext"></div>
            <div id="instructionsbg"></div>
        </div>

          <!-----start-copyright---->
                    <div class="copy-right">
                    </div>
                <!-----//end-copyright---->

</body>
</html>