How To Center A Fixed Element?
I'm a total novice in HTML/CSS, but I'm having trouble with centering a fixed h1 element. It refuses to center itself and sticks to the left side of the page. I've tried setting th
Solution 1:
if you want to use fixed position then add width: 100%;
css rule for h1
css style.
other just remove position
that will work.
Solution 2:
Solution 3:
the reason its sticking to the side of the page is because hence the name its fixed for example. you cannot tell it to freely float in the center if you have 'basically' demanded the element to be fixed, if that makes sense
you could do this
<style>.test{
position:fixed;
right:0;
left:0;
text-align:center;
background:#EEEEEE;
</style><h1class="test">test</h1>
Solution 4:
When using position
, specify it's position...left
, top
, or right
, bottom
.
Post a Comment for "How To Center A Fixed Element?"