I have one small question about css. I want the content .add-task-container and .task-container to show up in the middle of the screen but for some reason it is not working. I’m sure I have something wrong with my css but I just can’t pinpoint which part. Would love it if someone can help me out and explain what needs fixing. Thank you!
body{
background: url(/todolist/img/DSC05921-6.jpg) no-repeat center center/cover;
margin:0;
}
.content-container{
background: #FFFFFF;
width:50%;
margin:auto;
text-align:center;
justify-content: center;
}
<body>
<div class="content-container">
<div class="add-task-container">
<input type="text" placeholder="Enter Task" id="input-task">
<button id="add-task">ADD</button>
</div>
<div class="task-container">
</div>
</div>
<script src=script.js></script>
</body>
3
Answers
If you want it centered horizontally and vertically, you could do this:
In css
Here,
display: flex;
will align the child divs in same row, thenflex-direction: column;
will make the child divs in a column, thenjustify-content: center;
will make child divs in vertically center andalign-items: center
will make the inner divs in horizontally centre.if you remove the `flex-direction: column;` then `align-items: center` will make inner divs vertically center and `justify-content: center;` will make child divs horizontally center.
.content-container {
}
.add-task-container {
}
.task-container {
}