Nicolo Lüscher
Nicolo Lüscher

Reputation: 603

Set height to 100% of parrent height which has height 30%?

html, body, ul {
  width: 100%;
  height: 100%;
}

#loginwindow {
  position: fixed;
  display: block;
  top: 50%;
  left: 50%;
  visibility: visible;
  width: 30%;
  height: 30%;
  margin: -15% 0 0 -15%;
  text-align: center;
  float: center;
  border: 1px solid black;
  background-color: white;
}

#closeloginwindow {
  position: absolute;
  top: 20px;
  right: 20px;
  transition: .25s;
  color: #000;
  border: none;
  outline: none;
  background-color: transparent;
  font-size: 12pt;
}

#closeloginwindow:hover {
  color: #555;
}

#loginwindow-content {
  display: table;
  table-layout: fixed;
  width: 100%;
  height: 100%;
  border: 1px solid #c2c2c2;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.loginwindow-row {
  text-align: center;
  display: table-row;
  background: pink;
}

.loginbutton {
    display: table-cell;
    vertical-align: middle;
    border-top: 1px solid green;
}

.logininput {
    display: table-cell;
    vertical-align: middle;
    border-top: 1px solid green;
}
  <div id="loginwindow" class="nowrap">
    <button type="button" id="closeloginwindow" onclick="closeloginwindow(); enableScroll();"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
    <form method="post" onsubmit="closeloginwindow();">
      <ul id="loginwindow-content">
        <li class="loginwindow-row">
          <input class="logininput" type="text" placeholder="Name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Name'" required>
        </li>
        <li class="loginwindow-row">
          <input class="logininput" type="password" placeholder="Password" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Password'" required>
        </li>
        <li class="loginwindow-row">
          <input type="submit" id="loginbuttonsubmit" class="loginbutton" value="Login">
          <input type="button" id="loginbuttoncancel" class="loginbutton" value="Cancel" onclick="closeloginwindow(); enableScroll();">
        </li>
      </ul>
    </form>
  </div>

I am trying to make a simple portfolio Website. The website should have a loginmask which apears in front of everithing else. Inside of this loginmask, i want to make 3 rows of content(Username, Password, Buttons). To spread them evenly, i want to make a list like mentioned here: How to spread dynamic divs vertically, evenly?

However, i can't set the hight of the list to 100% sice I have set the height of the login window to 30%. Set a percentage of a percentage is no posible like mentioned here: CSS can't seem to set height to 100% of parent container

The div's don't spread evenly since the height couldn't be set. My question is: How can I set the height of the list, so that it takes the whole window?

EDIT: Or is there any other way to spread them eavenly. I did some research and the only possible thing i found was the one mentioned above.

I hope, I asked the question correctly. I'm pretty new here.

Upvotes: 0

Views: 83

Answers (1)

D. Hodge
D. Hodge

Reputation: 88

It seems that you need to apply styling to the form as that is the parent of the ul which you are trying to size. Here are the css changes that I made to get it to work the way I assume you want.

I removed float:center; because as far as I know it does not exist.

Depending on your target audience you could also look into css flex-boxes for element distribution.

#loginwindow {
  position: fixed;
  display: block;
  z-index: 3;
  top: 50%;
  left: 50%;
  /*visibility: hidden;*/
  width: 30%;
  height: 30%;
  margin: -15% 0 0 -15%;
  text-align: center;
  /*opacity: 0;*/
  border: 1px solid black;
  background-color: white;
}

#loginform{ /* Set height of form to 100% */
  height:100%;
}

#loginwindow-content {
 display: table;
 table-layout: fixed;
 width: 100%;
 height: 100%; /* Height set to 100% so we don't overflow */
 border: 1px solid #c2c2c2;
 -moz-box-sizing: border-box;
 box-sizing: border-box;
  margin:0;
  padding:0;
}

.loginwindow-row {
  text-align: center;
  display: table-row;
  background: pink;
}

.loginbutton {
  display: table-cell;
  vertical-align: middle;
  border-top: 1px solid green;
}

.logininput {
  display: table-cell;
  vertical-align: middle;
  border-top: 1px solid green;
}

#closeloginwindow{ /*Added to move the close button out of the way*/
  position:absolute;
  left:0;
  top:0;
  z-index:1;
}
  <div id="loginwindow" class="nowrap">
    <button type="button" id="closeloginwindow" onclick="closeloginwindow(); enableScroll();"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
    <form id="loginform" method="post" onsubmit="closeloginwindow();">
      <ul id="loginwindow-content">
        <li class="loginwindow-row">
          <input class="logininput" type="text" placeholder="Name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Name'" required>
        </li>
        <li class="loginwindow-row">
          <input class="logininput" type="password" placeholder="Password" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Password'" required>
        </li>
        <li class="loginwindow-row">
          <input type="submit" id="loginbuttonsubmit" class="loginbutton" value="Login">
          <input type="button" id="loginbuttoncancel" class="loginbutton" value="Cancel" onclick="closeloginwindow(); enableScroll();">
        </li>
      </ul>
    </form>
  </div>

Upvotes: 2

Related Questions