溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

css實(shí)現(xiàn)固定定位的方法

發(fā)布時(shí)間:2020-09-14 14:09:05 來(lái)源:億速云 閱讀:133 作者:小新 欄目:web開(kāi)發(fā)

小編給大家分享一下css實(shí)現(xiàn)固定定位的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

把box2設(shè)為固定定位:

<!DOCTYPE html>
<html dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>定位</title>
    <style media="screen">
 
      .box1{
        width:100px; 
        height: 100px;
        background-color: rgb(184, 208, 162);
      }
      .box2{
            width:100px;
            height: 100px;
            background-color: rgb(231, 223, 143);
            position:fixed;
            left: 100px;
            top:  100px;
      }
      .box3{
        width:100px;
        height: 100px;
        background-color: rgb(188, 211, 213);
      }
      span{
        background-color: rgb(209, 198, 209);
      }
    </style>
  </head>
  <body>
   <div>
    <div>
    </div>
    <div>
      <div>
      </div>
    </div>
    <span>span元素</span>
   </div>
  </body>
</html>

輸出:

固定定位永遠(yuǎn)都會(huì)相對(duì)于瀏覽器窗口進(jìn)行定位;

固定定位會(huì)固定在瀏覽器窗口某個(gè)位置,不會(huì)隨滾動(dòng)條滾動(dòng);

css實(shí)現(xiàn)固定定位的方法

看完了這篇文章,相信你對(duì)css實(shí)現(xiàn)固定定位的方法有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

css
AI