代码之家  ›  专栏  ›  技术社区  ›  Edwin Yip

如何使div始终位于浏览器窗口的最左侧?

  •  2
  • Edwin Yip  · 技术社区  · 14 年前

    我想做一个 div

    2 回复  |  直到 7 年前
        1
  •  5
  •   Matt Mitchell    14 年前

    试试这个:

    div#mydiv {
        position: fixed;
        left: 0;
    }
    

    top bottom

    比如:

    div#mydiv {
        position: fixed;
        left: 0;
        top: 200px; /* 200px from top */
    }
    

    或:

    div#mydiv {
        position: fixed;
        left: 0;
        bottom: 200px; /* 200px from bottom */
    }
    

    div#mydiv {
        position: fixed;
        left: 0;
        top: 50%; /* Half way down the side */
    }
    
        2
  •  2
  •   Gabriele Petrioli    14 年前

    设置其 position fixed 以及它的 left 0px

    #fixedLeft{
        position:fixed; /* now it will stay fixed on the screen, even while you scroll*/
        left:0px; /* it will be stuck to the left*/
        top:50%; /* it will be in the middle (vertically)*/
    }