CSS position: absolute screen resolution problem

前端 未结 4 1355
暖寄归人
暖寄归人 2020-12-30 07:40

CSS code:

top:45;
left:98;
float:right;
position:absolute;z-index:2;

I have done the above coding for a floating div when I wa

相关标签:
4条回答
  • 2020-12-30 08:07

    Absolutely positioned elements are positioned according to either a relatively positioned ancestor or the window. It sounds like in your case, it's being positioned in the window.

    The way to fix this is to put your absolutely positioned <div> inside a relative container. That way, as the window changes size, it will stay in the correct spot:

    <div style="position: relative">
        <div style="position: absolute; left: 98px; top: 45px;">
             This div will always be 98px from the left and 45px from the top of its parent .
        </div>
    </div>
    
    0 讨论(0)
  • 2020-12-30 08:11

    Assuming the element is not contained within another element with a position of relative, the element you are positioning should be in the same position regardless of resolution.

    Make sure you use:

    top: 45px
    left: 98px
    

    You left the pixel declaration off in your code above.

    Also, float:right is not required on the positioned element, as position:absolute will take it out of the normal flow of the document anyway.

    0 讨论(0)
  • 2020-12-30 08:15

    None of the above solutions work for me... keep it on absolute position and give margin-top, margin-left...in %age like;

    margin-top:10%;
    margin-left:5%;
    

    that will automatically adjust w.r.t. screen resolution...

    this worked perfect for me. tested on different resolutions.

    have a fun!

    0 讨论(0)
  • 2020-12-30 08:20

    Instead of pixel, use the %. It may help you to produce the output.

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