1

I am having following code

.flex {
  display: flex;
  width: 100%;
  height: 48px;
  background: black;
  flex-direction: row
}
.flex-item {
  height: 100%;
  background: grey
}
<button class="flex">
  <div class="flex-item">
    Click Me
  </div>
</button>

The problem is, parent node is <button> with flex-direction: row, child element does not accept height in percentage. height in percentage only works if parent node is <div>

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
NIRAV PAREKH
  • 137
  • 1
  • 2
  • 11

1 Answers1

0

* {
  margin: 0;
  padding: 0;
}

.flex {
  display: flex;
  width: 100%;
  height: 48px;
  background: black;
  flex-direction: row;
  border: none;
}

.flex-item {
  height: 100%;
  background: grey;
}
<button class="flex">
  <div class="flex-item">
    Click Me
  </div>
</button>

but if you work with flex, it is better to use its functionality to add to the parent align-items: stretch;

* {
  margin: 0;
  padding: 0;
}

.flex {
  display: flex;
  width: 100%;
  height: 48px;
  background: black;
  flex-direction: row;
  align-items: stretch;
  border: none;
}

.flex-item {
  background: grey;
}
<button class="flex">
  <div class="flex-item">
    Click Me
  </div>
</button>
Air
  • 181
  • 3
  • 15