How do I get rid of an element's offset using CSS?
That offset is basically the x,y position that the browser has calculated for the element based on it's position css attribute. So if you put a <br>
before it or any other element, it would change the offset. For example, you could set it to 0 by:
#inputBox{position:absolute;top:0px;left:0px;}
or
#inputBox{position:relative;top:-12px;left:-2px;}
Therefore, whatever positioning issue you have, is not necessarily an issue with offset, though you could always fix it by playing with the top,left,right and bottom attributes.
Is your problem browser incompatibility?
For me, it was vertical-align: baseline
vs vertical-align: top
that was causing the top offset.
Try to set vertical-align: top
Quick fix:
position: relative;
top: -12px;
left: -2px;
this should balance out those offsets, but maybe you should take a look at your whole layout and see how that box interacts with other boxes.
As for terminology, left
, right
, top
and bottom
are CSS offset properties. They are used for positioning elements at a specific location (when used with absolute
or fixed
positioning), or to move them relative to their default location (when used with relative
positioning). Margins on the other hand specify gaps between boxes and they sometimes collapse, so they can't be reliably used as offsets.
But note that in your case that offset may not be computed (solely) from CSS offsets.