[HTML5] CSS样式——position属性

目录

position的属性值:

一、static 默认值

二、relative 相对定位

三、absolute 绝对定位

四、fixed 固定定位


position的属性值:

  1. static(默认值)
  2. relative(相对定位)
  3. absolute(绝对定位)
  4. fixed(固定定位)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 100px;
            height: 100px;
        }
        .div1{
            background-color: burlywood;
        }
        .div2{
            background-color: thistle;
        }
        .div3{
            background-color: cadetblue;
        }
    </style>
</head>
<body>
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div3"></div>
</body>
</html>

  

一、static 默认值

没有定位,元素没有脱离文档流。

<style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 100px;
            height: 100px;
        }
        .div1{
            background-color: burlywood;
        }
        .div2{
            background-color: thistle;
            position: static;
            top: 20px;
            left: 20px;
        }
        .div3{
            background-color: cadetblue;
        }
    </style>

  

二、relative 相对定位

相对于自身原来位置移动。

 1.没有脱离文档流。

 2.不影响周围元素(如果一个元素设置了相对定位并且不写偏移属性,意味这个元素对页面没有任何影响)。

​<style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 100px;
            height: 100px;
        }
        .div1{
            background-color: burlywood;
        }
        .div2{
            background-color: thistle;
            position: relative;
            top: 20px;
            left: 20px;
        }
        .div3{
            background-color: cadetblue;
        }
    </style>

​

 

三、absolute 绝对定位

相对于自身第一个position为非static的父元素进行定位。如果该标签所在的父标签均没有设置position为非static,则相对于浏览器窗口进行定位(相对于body标签进行定位),但是此时元素会随着滚动调的滑动而滑动。脱离文档流。

1.相对于浏览器窗口定位

<style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 100px;
            height: 100px;
        }
        .div1{
            background-color: burlywood;
        }
        .div2{
            background-color: thistle;
            position: absolute;
            top: 20px;
            left: 20px;
        }
        .div3{
            background-color: cadetblue;
        }
    </style>

 当div2有父标签,且父子标签均未设置position属性时:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .div1,.div2,.div3{
            width: 100px;
            height: 100px;
        }
        .fu{
            width: 150px;
            height: 150px;
            background-color: yellowgreen;
            position: relative;
        }
        .div1{
            background-color: burlywood;
        }
        .div2{
            background-color: thistle;
        }
        .div3{
            background-color: cadetblue;
        }
    </style>
</head>
<body>
    <div class="div1"></div>
    <div class="fu">
        <div class="div2"></div>
    </div>
    <div class="div3"></div>
</body>
</html>

 

2.当父元素有position属性且属性值不为static时,子元素div2的定位相对于自身第一个position为非static的父元素进行定位

<style>
        *{
            margin: 0;
            padding: 0;
        }
        .div1,.div2,.div3{
            width: 100px;
            height: 100px;
        }
        .fu{
            width: 150px;
            height: 150px;
            background-color: yellowgreen;
            position: relative;
        }
        .div1{
            background-color: burlywood;
        }
        .div2{
            background-color: thistle;
            position: absolute;
            top: 20px;
            left: 20px;
        }
        .div3{
            background-color: cadetblue;
        }
    </style>

 

四、fixed 固定定位

相对于浏览器窗口进行定位(相对于body标签进行定位),此时元素不会随着滚动调的滑动而滑动。脱离文档流。

<style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 100px;
            height: 100px;
        }
        .div1{
            background-color: burlywood;
        }
        .div2{
            background-color: thistle;
            position: fixed;
            top: 20px;
            left: 20px;
        }
        .div3{
            background-color: cadetblue;
        }
    </style>

 

要在CentOS 7中的单用户模式修改密码,您可以按照以下步骤操作: 1. 首先,重启系统并进入GRUB引导菜单。您可以按下计算机的电源按钮并立即按下并持续按住Shift键,直到出现GRUB菜单为止。 2. 使用方向键选择第一个启动项,并按下e键进行编辑。 3. 找到以"linux16"开头的那一行,然后去掉其中的"rhgb"和"quiet"参数。在"UTF-8"之后添加"init=/bin/sh"参数。这将让系统在单用户模式下启动并进入一个shell提示符。 4. 按下Ctrl + x键启动修改。 5. 您现在将进入一个单用户模式的shell提示符。输入以下命令以重新挂载根文件系统为可写模式: ``` mount -o remount,rw / ``` 6. 输入以下命令以更改root用户的密码: ``` passwd ``` 7. 按照提示输入新密码并确认。 8. 输入以下命令以重新挂载根文件系统为只读模式: ``` mount -o remount,ro / ``` 9. 输入以下命令以重启系统: ``` reboot ``` 10. 系统将重新启动并返回到正常的登录界面。 请注意,这些步骤将使您能够在CentOS 7中的单用户模式修改root用户的密码。确保您按照指示操作,并确保保护好您的密码以确保系统的安全性。 [参考文献] 提供了在GRUB引导菜单中编辑启动项的具体步骤。 提供了在单用户模式下重新挂载根文件系统为可写模式和只读模式的命令。 提供了在系统中使用命令"reboot"来重启系统的方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值