1

I have below html code and the problem is the height of .div2 is as same as body. How can I make the div2 height to fit to its content which is the font size of hello? I know I can make it by changing body display to block but I do need flex display. Is there a way to make it under flex layout?

body {
  width: 923px;
  height: 700px;
  display: flex;
}

.div2 {
  height: auto;
  background-color: red;
}
<body>
  <div class="div2">hello</div>
</body>
Temani Afif
  • 211,628
  • 17
  • 234
  • 311
Joey Yi Zhao
  • 30,508
  • 51
  • 183
  • 377

0 Answers0