I have been working on this code where I assigned a display:flex
to my body element. My understanding was that all child elements within the body would automatically become flex items, considering the body is both a flex container and a wrapper for its children. However, upon inspecting the developer tools in Firefox, I noticed that setting properties like align-items
and justify-content
had no effect, as the body was neither a flex container nor a grid container.
I'm now seeking clarification on when it's necessary to individually give divs, sections, or mains their own display:flex
property, as opposed to relying on automatic inheritance.
Below is an excerpt from my code:
#html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Butterfly Music App</title>
</head>
<body>
<main>
</main>
<footer>
</footer>
</body>
</html>
#css
html, body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
background-color: cyan;
font-family: gabriola;
color: purple;
}
footer {
justify-content: flex-end;
align-items: flex-start;
flex: 0 0 120px;
background-color: pink;
}