0

 html, body {
        height: 100%;
        font: 30px "2005_iannnnnCPU";
}

body {
    margin: 0;
    padding: 0;
    background: #000;  
}

.grid-container {
    display: grid;
    height: 100%;
    color: #fff;
    justify-items: center;
    align-items: center;
}
   
.square {
    height: 50px;
    width: 50px;
    background-color: #fff;
}

.contain {
    display: grid;
    padding: 15px;
    width: 60%;
    height: 23%;
    border: 3px solid #fff;
    color: #fff;  
}

.grid-items {
    margin: 1% 1%;
}

.ans {
    margin: 1% 1%;
    font: 20px "2005_iannnnnCPU";
    letter-spacing: 2px;
}

input[type=text] {
    background-color: none;
    background: transparent;
    border: 2px solid #555;
    color: #fff;
}

input[type=text]:focus {
    border: 2px solid #fff;
}

textarea:focus, input:focus{
    outline: none;
}

.button {
    border: none;
    color: white;
    padding: 2% 2%;
    margin: 6% 6%;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    outline: none;
}

.login {
    background-color: #000;
    font: 30px "2005_iannnnnCPU";
    color: #fff;
    border: 2px solid #fff;
    width: 50%;
    -ms-transform: translateX(40%);
    transform: translateX(40%);
}

.login:focus {     
    background-color:white; 
    color: black;   
    font-weight: bold;
}
<!DOCTYPE html>
<html lang="en">
  <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Neglected Moment</title>
      <link rel="stylesheet" href="css/style.css">
  </head>
  <body>
      <div class="grid-container">
          <div class="square"></div>
          <div class="contain">
              <label class="grid-items">Username</label>
              <input type="text" class="ans" id="ans-user" name="ans-user"></input>
              <label class="grid-items">Password</label>
              <input type="text" class="ans" id="ans-pass" name="ans-pass"></input>
              <button class="button login">login</button>
         </div>
      </div>
  </body>
</html>



   

Images:

i want to draw square just be the backgound, but my problem is contain.

when i draw square on top of my web. my old code(login form) will broke.

i think it about contain, but i don't know how to fix it.

Thank you for help.

enter image description here

can i delete this red part. i want my login form to center, but now it go down

kidsada
  • 11
  • 4

3 Answers3

1

Remove height from .contain class and add button using absolute position

html,
body {
  height: 100%;
  font: 30px "2005_iannnnnCPU";
}

body {
  margin: 0;
  padding: 0;
  background: #000;
}

.grid-container {
  display: grid;
  height: 100%;
  color: #fff;
  justify-items: center;
  align-items: center;
}

/*
.square {
    height: 50px;
    width: 50px;
    background-color: #fff;
}
*/

.contain {
  display: grid;
  padding: 15px 15px 50px;/*New css*/
  width: 60%;
  /*height: 23%;*/
  border: 3px solid #fff;
  color: #fff;
  position: relative;/*New css*/
  margin-bottom: 60px; /*New css*/ 
}

.grid-items {
  margin: 1% 1%;
}

.ans {
  margin: 1% 1%;
  font: 20px "2005_iannnnnCPU";
  letter-spacing: 2px;
}

input[type=text] {
  background-color: none;
  background: transparent;
  border: 2px solid #555;
  color: #fff;
}

input[type=text]:focus {
  border: 2px solid #fff;
}

textarea:focus,
input:focus {
  outline: none;
}

.button {
  border: none;
  color: white;
  padding: 2% 2%;
  margin: 6% 6%;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  outline: none;
}

.login {
  background-color: #000;
  font: 30px "2005_iannnnnCPU";
  color: #fff;
  border: 2px solid #fff;
  width: 50%;
  -ms-transform: translateX(40%);
  transform: translateX(40%);
  position: absolute;
  bottom: -50px;
}

.login:focus {
  background-color: white;
  color: black;
  font-weight: bold;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Neglected Moment</title>
  <link rel="stylesheet" href="css/style.css">
</head>

<body>
  <div class="grid-container">
    <div class="contain">
      <label class="grid-items">Username</label>
      <input type="text" class="ans" id="ans-user" name="ans-user"/>
      <label class="grid-items">Password</label>
      <input type="text" class="ans" id="ans-pass" name="ans-pass"/>
      <button class="button login">login</button>
    </div>
  </div>
</body>
</html>
Minal Chauhan
  • 6,025
  • 8
  • 21
  • 41
  • Nice answer. I would add position:relative; to the .grid-container, so the position absolute in .container would be the same, no matter the height of the body. – Sam Sep 02 '20 at 13:19
0

The problem is in your

.contain { height: 23%;};

I changed it to 65% and it worked in the snippet, but you should try it for your desired display height.

html,
body {
  height: 100%;
  font: 30px "2005_iannnnnCPU";
}

body {
  margin: 0;
  padding: 0;
  background: #000;
}

.grid-container {
  display: grid;
  height: 100%;
  color: #fff;
  justify-items: center;
  align-items: center;
}


/*
    .square {
        height: 50px;
        width: 50px;
        background-color: #fff;
    }
    */

.contain {
  display: grid;
  padding: 15px;
  width: 60%;
  height: 65%;
  border: 3px solid #fff;
  color: #fff;
}

.grid-items {
  margin: 1% 1%;
}

.ans {
  margin: 1% 1%;
  font: 20px "2005_iannnnnCPU";
  letter-spacing: 2px;
}

input[type=text] {
  background-color: none;
  background: transparent;
  border: 2px solid #555;
  color: #fff;
}

input[type=text]:focus {
  border: 2px solid #fff;
}

textarea:focus,
input:focus {
  outline: none;
}

.button {
  border: none;
  color: white;
  padding: 2% 2%;
  margin: 6% 6%;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  outline: none;
}

.login {
  background-color: #000;
  font: 30px "2005_iannnnnCPU";
  color: #fff;
  border: 2px solid #fff;
  width: 50%;
  -ms-transform: translateX(40%);
  transform: translateX(40%);
}

.login:focus {
  background-color: white;
  color: black;
  font-weight: bold;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Neglected Moment</title>
  <link rel="stylesheet" href="css/style.css">
</head>

<body>
  <div class="grid-container">
    <div class="contain">
      <label class="grid-items">Username</label>
      <input type="text" class="ans" id="ans-user" name="ans-user"></input>
      <label class="grid-items">Password</label>
      <input type="text" class="ans" id="ans-pass" name="ans-pass"></input>
      <button class="button login">login</button>
    </div>
  </div>
</body>

</html>
Sam
  • 723
  • 5
  • 18
0

Why not a fieldset:

https://jsfiddle.net/mplungjan/utpnxfca/

html,
body {
  height: 100%;
  font: 30px "2005_iannnnnCPU";
}

body {
  margin: 0;
  padding: 0;
  background: #000;
}

.grid-container {
  display: grid;
  height: 100%;
  color: #fff;
  justify-items: center;
  align-items: center;
}

.square {
  height: 50px;
  width: 50px;
  background-color: #fff;
}

.contain {
  display: grid;
  padding: 15px;
  border: 3px solid #fff;
  color: #fff;
}

.grid-items {
  margin: 1% 1%;
}

.ans {
  margin: 1% 1%;
  font: 20px "2005_iannnnnCPU";
  letter-spacing: 2px;
}

input[type=text] {
  background-color: none;
  background: transparent;
  border: 2px solid #555;
  color: #fff;
}

input[type=text]:focus {
  border: 2px solid #fff;
}

textarea:focus,
input:focus {
  outline: none;
}

.button {
  border: none;
  color: white;
  padding: 2% 2%;
  margin: 6% 6%;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  outline: none;
}

.login {
  background-color: #000;
  font: 30px "2005_iannnnnCPU";
  color: #fff;
  border: 2px solid #fff;
  width: 50%;
  -ms-transform: translateX(40%);
  transform: translateX(40%);
}

.login:focus {
  background-color: white;
  color: black;
  font-weight: bold;
}
<div class="grid-container">
  <div class="square"></div>
  <fieldset class="contain">
    <legend>Login</legend>
    <label class="grid-items">Username</label>
    <input type="text" class="ans" id="ans-user" name="ans-user" />
    <label class="grid-items">Password</label>
    <input type="text" class="ans" id="ans-pass" name="ans-pass" />
    <button class="button login">login</button>
  </fieldset>
</div>
mplungjan
  • 169,008
  • 28
  • 173
  • 236