1

Although I have set the z-indexes correct, so the .container class can be on the back level, on the upper side, it has an empty space that I suspect is caused by the .add-book div. I have linked the button through javascript so it will increase the opacity to 1 when pressed, (by toggling an 'active' class) but now I have set the .add-box opacity to 1 for easier editing.

body {
  margin: 0;
  font-family: Montserrat;
}

nav {
  ...
}

.add {
  font-family: Montserrat;
  margin-right: 2rem;
  height: 3rem;
  border-radius: 20px;
  padding-left: 20px;
  padding-right: 20px;
  font-size: 1rem;
  border: 0;
  cursor: pointer;
  background-color: rgb(248, 248, 248);
  transition: 0.1s;
}

.add:hover {
  background-color: rgb(245, 245, 245);
}

.add:active {
  background-color: rgb(237, 237, 237);
}

.add-book {
  width: 15rem;
  height: 23rem;
  background-color: rgb(237, 237, 237);
  z-index: +20;
  position: relative;
  top: 4.7rem;
  left: calc(100vw - 15rem - 10px);
  border-radius: 17px;
  display: flex;
  opacity: 1;
  flex-direction: column;
  align-items: center;
}

.add-book h2 {
  margin: 0;
  margin-top: 15px;
}

.add-book h3 {
  margin: 0;
}

.input-container {
  margin-top: 20px;
}

.input-container input {
  width: 12rem;
  margin-top: 5px;
}

.checkbox-container {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 12rem;
}

.checkbox-container input {
  transform: scale(1.2);
}

.add-book button {
  margin-top: auto;
  margin-bottom: 25px;
  height: 2.3rem;
  width: 12rem;
  border-radius: 10px;
  border: solid 2px rgb(225, 225, 225);
  background-color: rgb(248, 248, 248);
  cursor: pointer;
  transition: 0.1s;
}

.add-book button:hover {
  background-color: rgb(245, 245, 245);
}

.add-book button:active {
  background-color: rgb(237, 237, 237);
}

.add-book.active {
  opacity: 1;
}

.main-container {
  width: 100%;
  background-color: antiquewhite;
  height: calc(100vh - 4rem);
  z-index: -1;
}
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap" rel="stylesheet" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<nav>
  <div class="title">
    <h1>MyLibrary .</h1>
  </div>
  <button class="add" id="add">Add Book</button>
</nav>
<div class="add-book" id="add-book">
  <h2>Add Book</h2>
  <div class="input-container">
    <h3>Title</h3>
    <input type="text" id="title" />
  </div>
  <div class="input-container">
    <h3>Author</h3>
    <input type="text" id="author" />
  </div>
  <div class="input-container">
    <h3>Pages</h3>
    <input type="number" id="pages" />
  </div>
  <div class="checkbox-container">
    <h3>Read</h3>
    <input type="checkbox" id="checkbox" />
  </div>
  <button>Add!</button>
</div>
<div class="main-container">
  <h1>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaassdasd</h1>
</div>
Adam
  • 5,495
  • 2
  • 7
  • 24
randomman
  • 11
  • 1
  • 1
    That's due to the default `margin-top` the `h1` element gets from the user agent stylesheet. https://stackoverflow.com/a/19719427/1427878, https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing – CBroe Jan 16 '23 at 13:25
  • @CBroe unfortunately it is not. Even after removing it, it still has a lot of empty space – randomman Jan 16 '23 at 14:09
  • Not sure what you are talking about. As soon as I give the h1 containing "MyLibrary" a `margin-top: 0`, that text sits more or less "flush" with the upper viewport corner. If that's not what you meant, then please give a more precise description of what the actual issue is. – CBroe Jan 16 '23 at 14:13
  • @CBroe suggestion works perfectly, if that doesn't solve your issue then please provide an image and clear description of the issue you are facing – Usama Saeed Jan 16 '23 at 14:28

0 Answers0