-3

我试图让管理员登录名居中,这样看起来更好,这是代码。

<?php
session_start();
$username="user";
$password="123";

if(isset($_POST['username']) && $_POST['password'] == $password)
{
    header("Location: mainpage.php");
}
else
{
?>

<html>
    <head>
    </head>
    <body>

        <div style='text-align:center'>
        <h3>Welcome To Kontak</h3>
        </div>
        <hr /><br />
        <form id='login' action="" method='post' accept-charset='UTF-8'>
            <fieldset style="width:550px">
            <legend>Admin Login</legend>
            <input type='hidden' name='submitted' id='submitted' value='1'/>

            <label for='username' >UserName:</label>
            <input type='text' name='username' id='username'  maxlength="50" />


            <label for='password' >Password:</label>
            <input type='password' name='password' id='password' maxlength="50" />

            <input type='submit' name='submit' value='Submit' />
            </fieldset>
        </form>
    </body>
</html>
<?php
}
?>

管理员登录和框没有居中,我相信解决方案很简单,但我不是最擅长 php。

4

3 回答 3

1

用于style="margin: 0px auto; width: 550px;"如下形式

或者

你也可以用<fieldset style="margin: 0px auto;width:550px">这个

<html>
    <head>
    </head>
    <body>

        <div style='text-align:center'>
        <h3>Welcome To Kontak</h3>
        </div>
        <hr /><br />
        <form id='login' action="" method='post' accept-charset='UTF-8' style="margin: 0px auto; width: 550px;">
            <fieldset style="width:550px">
            <legend>Admin Login</legend>
            <input type='hidden' name='submitted' id='submitted' value='1'/>

            <label for='username' >UserName:</label>
            <input type='text' name='username' id='username'  maxlength="50" />


            <label for='password' >Password:</label>
            <input type='password' name='password' id='password' maxlength="50" />

            <input type='submit' name='submit' value='Submit' />
            </fieldset>
        </form>
    </body>
</html>
于 2013-11-05T05:55:08.267 回答
1

这不是 php 问题,您可以使用 HTML 和 CSS 来完成。

我已经创建了登录表单...


在此处输入图像描述


HTML

<form id="login" class="login">
  <h2>Please log in</h2>
  <label for="user" class="icon-user">User:</label>
  <input class="user" id="user" />
  <label for="password" class="icon-lock">Password:</label>
  <input type="password" class="password" id="password" />

  <input type="submit" value="Go" />
  <ul class="extra">
    <li><a href="#" class="forgetPassword">Forgot Password</a></li>
  </ul>
</form>

<div class="blur"></div>

CSS

* {
  user-select: none;
  @include box-sizing(border-box);
}

html {
  overflow: -moz-scrollbars-vertical; 
  overflow-y: scroll;
}

body {
  font-family:"Roboto", Arial, sans-serif;
  font-weight: 400;
  color: white;
}

.blur {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: url('http://www.wallgc.com/images/2013/05/abstract-wallpaper-abstract-wallpapers.jpg') no-repeat;
  background-position: center bottom;
  z-index: -1;
}

.login {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -150px 0 0 -150px;
  width: 300px;
  height: 300px;
  color: rgba(#fff, .85);
  display: inline-block;
  font-size: 16px;
  padding: 8px 12px;
  text-decoration: none;
  border-radius: 10px;
  @include background-clip(padding-box);
  @include box-shadow(inset -1px 1px 0px rgba(255, 255, 255, 0.3),
  inset 1px 1px 0px rgba(255, 255, 255, 0.3)
  );
  border: 1px solid #000;
  background-color: rgba(#000, .1);
  @include background-image(linear-gradient(top, rgba(#000, .1), rgba(#000, .3)));
  h2 {
    margin: .5em;
    text-align: center;
    //@include background-image(linear-gradient(#fff, #eee));
    //@include background-clip(text);
    //-webkit-text-fill-color: transparent;
    text-shadow: 0 1px 2px rgba(#000,.5);
    font-weight: 900;
  }
  input,
  label,
  .extra {
    outline: none;
    position: absolute;
  }
}

.user,
.password {
  font-size: 150%;
  color: #fff;
  @include box-sizing(border-box);
  height: 45px;
  padding: .3em 20px .3em 40px;
  width: 270px;
  background: rgba(#000, .3);
  border: 0;
  border-radius: 25px;
  box-shadow: 0 -1px 1px rgba(#fff, .8) inset;
}
.password {
  padding: .3em 70px .3em 40px;
}
[for="user"],
.user {
  top: 70px;
}
[for="password"],
.password,
input[type="submit"] {
  top: 150px;
}

[for="password"],
[for="user"] {
  text-indent: -9999px;
  &:before {
      text-indent: 0;
      position: absolute;
      top: 12px;
      left: 15px;
      font-size: 120%;
      z-index: 1;
  }
}

input[type="submit"] {
  right: 17px;
  height: 43px;
  width: 60px;
  background-color: #6bac14;
  @include background-image(linear-gradient(to bottom, #8ff704, #1c8700));
  border: 0;
  border-radius: 0 25px 25px 0;
  box-shadow: 0 5px 2px #a6ee40 inset, 1px 1px 0 rgba(#000, .5);
  color: #fff;
  text-transform: uppercase;
  font-size: 110%;
  text-shadow: 1px 1px 0 rgba(#000, .5);
  text-align: center;
}

label[for="remember"] {
  top: 210px;
  left: 40%;
  cursor: pointer;
  white-space: nowrap;
}
#remember { visibility: hidden;}
.remember {
  &:before,
  &:after {
      visibility: visible;
      content: '';
      position: absolute;
      left:-35px;
      top: 4px;
  }
  &:before {
      right: -2px;
      width: 30px;
      height: 15px;
      border-radius: 10px;
      box-shadow: inset 0 1px 2px rgba(#000, .8);
      @include background-image(linear-gradient(top, rgba(#000, .1) 0%, rgba(#000,.2) 100%));
  }
  &:after {
      top: 2px;
      width: 16px;
      height: 16px;
      background-color: #fff;
      @include background-image(linear-gradient(top, #E5E5E5 0%, #878787 100%));
      border: 1px solid rgba(#000,.5);
      border-radius: 50%;
      box-shadow: inset 0px 1px 1px white, 0 1px 1px rgba(0,0,0,.8);
      right:11px;
  }
}
#remember:checked + .remember {
  &:before {
    @include background-image(linear-gradient(top, #C25830 0%, #F69C3C 100%));
  }
  &:after {
      left: -21px;
      font-family: FontAwesome;
      content: '\f00c';
      color: rgba(#000, .4);
  }
}

.extra {
  margin: 0;
  padding: 0;
  list-style: none;
  bottom: 0;
  width: 100%;
  height: 50px;
  background: rgba(#000,.3);
  left: 0;
  border-radius: 0 0 10px 10px;
  @include box-shadow(inset -1px 1px 0px rgba(255, 255, 255, 0.3),
  inset 1px 0 0px rgba(255, 255, 255, 0.3)
  );
  border-top: 1px solid #000;
  word-spacing: -1;
  a {
    display: inline-block;
    text-decoration: none;
    height: 100%;
    &.facebook,
    &.googlePlus {
      top: 0;
      background-position: left top;
      background-repeat: no-repeat;
      width: 49px;
      text-indent: 9999px;
      position: absolute;
      top: 0;
      right: 0;
      &:before {
        position: absolute;
        top: 7px;
        left: 12px;
        text-indent: 0;
        color: rgba(#fff, .8);
        font-size: 180%;
        text-shadow: 0 -1px 0 rgba(0,0,0,0.3);
      }
    }

    &.forgetPassword {
      width: 200px;
      color: #fff;
      line-height: 45px;
      text-align: center;
      text-shadow: 0 1px 1px rgba(black, 0.5);
      &:before {
        font-family: FontAwesome;
        content: '\f0e2';
        padding-right: 5px;
      }


    }
  }
}
于 2013-11-05T06:02:21.890 回答
0
<form id='login' action="" method='post' accept-charset='UTF-8'>

<form id='login' action="" method='post' accept-charset='UTF-8' style='text-align: center'>

我在这里所做的是添加CSS Text-Align

PHP是后端的东西,它与浏览器解释什么无关

于 2013-11-05T05:57:19.967 回答