m.edmondson m.edmondson - 1 year ago 148
CSS Question

How do I get rid of an element's offset using CSS?

I've got a positioning problem with some elements, upon inspecting it IE8 Developer tools it shows me this:

Where does offset come from?

Now I'm pretty sure my problem is that 12 offset, but how do I remove it? I can't find any mention of a CSS offset property. Do we need an Offset in addition to margin?

Here is the code thats producing this:

<div id="wahoo" style="border: solid 1px black; height:100px;">

<asp:TextBox ID="inputBox" runat="server" />

<input id="btnDropDown" type="button" style="width:26px; height:26px; background-position: center center; border-left-color: buttonface; background-image: url(Images/WebResource.gif); border-bottom-color: buttonface; border-top-color: buttonface; background-repeat: no-repeat; border-right-color: buttonface;" tabindex="99" />

<div id="ListboxWrapper" style="display:none; position:absolute; onfocusout="this.style.display = 'none'"">
<asp:ListBox ID="lstBoxCompany" runat="server" AutoPostBack="True" OnSelectedIndexChanged="lstBoxCompany_SelectedIndexChanged" style="z-index: 100;" Width="300px" />


The element with the offset is

Neo Neo
Answer Source

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:




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?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download