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

后端 未结 13 1253
春和景丽
春和景丽 2020-12-04 08:43

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

\"W

相关标签:
13条回答
  • 2020-12-04 09:17

    In my case the offset was added to a custom element with grid layout within an li while the ul was a vertical flexbox.

    The pretty simple solution was to set the define the li as block element with

    li {
     display: block;
    }
    

    And the offset was gone

    0 讨论(0)
  • 2020-12-04 09:20

    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?

    0 讨论(0)
  • 2020-12-04 09:23

    Setting the top and left properties to negative values might not be a good workaround if your problem is simply that you're in quirks mode. This can happen if the page is missing a <!DOCTYPE> declaration, causing it to be rendered in quirks mode in IE8. In IE8 Developer Tools, make sure that "Quirks Mode" is not selected under "Document Mode". If it is selected, you may need to add the appropriate <!DOCTYPE> declaration.

    0 讨论(0)
  • 2020-12-04 09:29

    moving element top: -12px or positioning it absolutely doesn't solve the problem but only masks it

    I had the same problem - check if you have in one wrapping element mixed: floating elements with non-floating ones - my non-floating element caused this strange offset to the floating one

    0 讨论(0)
  • 2020-12-04 09:29

    This seems weird, but you can try setting vertical-align: top in the CSS for the inputs. That fixes it in IE8, at least.

    0 讨论(0)
  • 2020-12-04 09:29

    You can apply a reset css to get rid of those 'defaults'. Here is an example of a reset css http://meyerweb.com/eric/tools/css/reset/ . Just apply the reset styles BEFORE your own styles.

    0 讨论(0)
提交回复
热议问题