I have a div that I've centered using margin left and right auto
. However, I want this bar to be visible throughout my page, so I positioned it absolutely. But now the bar is not centered anymore, it's appearing on the left. How can I position the bar at the center top of the page?
<div class="bar">bar</div>
.bar{
width: 400px;
height: 40px;
margin-left:auto;
margin-right:auto;
background-color:orange;
}
Here is the fiddle.