I am trying to align either <h1>
or <div class="heading">
in the center of my webpage. The method I have attempted involves
body { text-align: center; }
However, I am puzzled as to why this approach is not yielding the desired result. I utilized Display: inline-block
to ensure that the border encompasses my content.
body {
margin: 0;
}
.navbar {
text-align: right;
background: black;
color: white;
padding: 10px;
}
ul {
list-style-type: none;
padding: 5px;
}
li {
display: inline-block;
}
.heading {
border: 2px solid black;
display: inline-block;
text-align: center;
}
<header>
<nav class="navbar">
<ul>
<li>home</li>
<li>about</li>
<li>contact</li>
</ul>
</nav>
<div class="heading">
<h1>heading</h1>
</div>
</header>