hover not working on div element which nests another div

Viewed 67

I have a div with the class button-wrapper and it contains another div with the class button. The button-wrapper div is supposed to increase its padding from 8px to 16px when hovered on so that the button div decreases in size. However, the button-wrapper div doesn't respond when I hover over it.

The code is hosted on the website mos.epizy.com.

Here is my code:

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.background,
.underlay,
.overlay,
.cover {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: scroll;
}

.overlay,
.cover {
  display: none;
}

.background {
  z-index: 0;
  background-image: url("images/shards.jpg");
  background-size: cover;
  min-width: 100%;
  min-height: 100%;
}

.underlay {
  z-index: 1;
  height: 100%;
}

.content {
  z-index: 2;
  padding-top: 20px;
}

.overlay {
  z-index: 3;
}

.cover {
  z-index: 4;
}

.menu {
  width: 100%;
}

.button-wrapper {
  padding: 8px;
  float: left;
  box-sizing: border-box;
  height: 150px;
}

.button {
  width: 100%;
  height: 100%;
  opacity: .9;
  transition: 1s;
}

.row-1 {
  width: 33.3%;
}

.row-2 {
  width: 66.6%;
}

.row-3 {
  width: 100%;
}

.button-wrapper:hover {
  padding: 16px;
}

.red {
  border: 1px solid red;
  background: red;
}

.blue {
  border: 1px solid blue;
  background: blue;
}
<div class="background"></div>
<div class="underlay"></div>
<div class="content">
  <div class="menu">
    <div class="button-wrapper row-1">
      <div class="red button">1/3</div>
    </div>
    <div class="button-wrapper row-2">
      <div class="red button">2/3</div>
    </div>
    <div class="button-wrapper row-3">
      <div class="red button">1</div>
    </div>
    <div class="button-wrapper row-1">
      <div class="blue button">1/3</div>
    </div>
    <div class="button-wrapper row-2">
      <div class="blue button">2/3</div>
    </div>
    <div class="button-wrapper row-3">
      <div class="blue button">1</div>
    </div>
  </div>
</div>
<div class="overlay"></div>
<div class="cover"></div>

1 Answers

I have adjusted your code and documented the changes in the code itself. Most important change is using a flexbox to display the columns next to each other (row has been renamed into col).

I also positioned the .content class to make z-index work.

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.background,
.underlay,
.overlay,
.cover {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: scroll;
}

.overlay,
.cover {
  display: none;
}

.background {
  z-index: 0;
  background-image: url("images/shards.jpg");
  background-size: cover;
  min-width: 100%;
  min-height: 100%;
}

.underlay {
  z-index: 1;
  height: 100%;
}

.content {
  position: relative; /* Added to make z-index work */
  z-index: 2;
  padding-top: 20px;
}

.overlay {
  z-index: 3;
}

.cover {
  z-index: 4;
}

.menu {
  width: 100%;
  display: flex; /* Added */
  flex-wrap: wrap; /* Added */
}

.button-wrapper {
  padding: 8px;
  /* float: left; REMOVED */
  box-sizing: border-box;
  height: 150px;
}

.button {
  width: 100%;
  height: 100%;
  opacity: .9;
  transition: 1s;
}

.col-1 {
  width: 33.3%;
}

.col-2 {
  width: 66.6%;
}

.col-3 {
  width: 100%;
}

.button-wrapper:hover {
  padding: 16px;
}

.red {
  border: 1px solid red;
  background: red;
}

.blue {
  border: 1px solid blue;
  background: blue;
}
<div class="background"></div>
<div class="underlay"></div>
<div class="content">
  <div class="menu">
    <div class="button-wrapper col-1">
      <div class="red button">1/3</div>
    </div>
    <div class="button-wrapper col-2">
      <div class="red button">2/3</div>
    </div>
    <div class="button-wrapper col-3">
      <div class="red button">1</div>
    </div>
    <div class="button-wrapper col-1">
      <div class="blue button">1/3</div>
    </div>
    <div class="button-wrapper col-2">
      <div class="blue button">2/3</div>
    </div>
    <div class="button-wrapper col-3">
      <div class="blue button">1</div>
    </div>
  </div>
</div>
<div class="overlay"></div>
<div class="cover"></div>

Related