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>