I'm attempting to center an HTML Cointainer through CSS. I've seen ways to center, such as the following:
#container{
...
margin: 0 auto;
...
}
or
#container{
...
position: relative;
...
}
but the HTML element still remains at the top left corner. I guess there's something wrong with the HTML code, but can't figure out what.
body {
text-align: center;
position: absolute;
font-family: Roboto;
background-repeat: no-repeat;
background-image: url(backgroung-image1.png);
background-size: cover;
}
h1 {
text-align: center;
width: max-content;
}
#container {
margin: 100px auto;
width: auto;
height: auto;
position: absolute;
}
button {
color: white;
font-size: 15px;
background-color: rgb(165, 42, 42);
}
<div id="container">
<h1> Tip Calculator</h1>
<div id="calculator">
<!--text box-->
<form>
<p>How much was your bill?</p>
<input type="text" id="billSum" placeholder="Bill in $">
<p>How was the service?</p>
<select id="serviceReview">
<option disabled selected value="0">Choose a review</option>
<option value="0.3">Exellent</option>
<option value="0.2">Good</option>
<option value="0.15">Ok</option>
<option value="0.10">Bad</option>
<option value="0.5">Terrible</option>
</select>
</form>
<p>How many people share the bill?</p>
<p>
<input type="text" placeholder="Number of people" id="numberOfPeople"> people
</p>
<button type="button" id="calculateBtn">Calculate</button>
</div>
<!--tip-->
<div id="tipSection">
<p id="tip"> each</p>
</div>
</div>
Comment regarding possible duplicate
After posting the question, another question was suggested to be answering my question. After trying the solution in the aforementioned question, the element was centered horizontally, but not vertically. I had to add dimensions of 100px so that the element would be centered vertically as well.