Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" />                    </div>  </div> 

The element with the offset is inputBox

like image 760
m.edmondson Avatar asked Jan 27 '11 14:01

m.edmondson


People also ask

How do I completely remove an element in CSS?

display: none; 'Unlike the visibility property, which leaves an element in normal document flow,display: none removes the element completely from the document. It does not take up any space, even though the HTML for it is still in the source code. This is because it is, indeed, removed from the document flow.

What does offset mean in CSS?

Definition and Usage The outline-offset property adds space between the outline and the edge or border of an element. The space between an element and its outline is transparent.

How do you get the offset of an element?

jQuery . offset() will get the current coordinates of the first element, or set the coordinates of every element, in the set of matched elements, relative to the document.


1 Answers

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?

like image 127
Neo Avatar answered Oct 05 '22 19:10

Neo