当前位置: 首页 > news >正文

网站备案信息核验单填写中国十大企业培训机构排名

网站备案信息核验单填写,中国十大企业培训机构排名,php网站制作常用代码,自己买台服务器做网站文章目录 定位概述偏移量(offset)坐标及方向相对定位——position绝对定位——absolute固定定位 ——fixed粘滞定位——sticky绝对定位对布局的影响水平布局:垂直方向 定位概述 定位(position) 定位是一种更加高级的布局手段 通过定位可以将…

文章目录

  • 定位概述
  • 偏移量(offset)
  • 坐标及方向
  • 相对定位——position
  • 绝对定位——absolute
  • 固定定位 ——fixed
  • 粘滞定位——sticky
  • 绝对定位对布局的影响
    • 水平布局:
    • 垂直方向

定位概述

  • 定位(position)
    定位是一种更加高级的布局手段
    通过定位可以将元素摆放到页面的任意位置,而且不会对其他元素产生影响。
  • 使用position属性来设置定位
    可选值:
    static 默认值,元素是静止的没有开启定位
    relative 开启元素的相对定位
    absolute 开启元素的绝对定位
    fixed 开启元素的固定定位
    sticky开启元素的粘滞定位

偏移量(offset)

当元素开启了定位以后,可以通过偏移量来设置元素的位置

  • top:定位元素和定位位置上边的距离
  • bottom:定位元素和定位位置下边的距离
    定位元素垂直方向的位置由top和bottom两个属性来控制,通常情况下我们只会使用其中一个
    top值越大,定位元素越向下移动
    bottom值越大,定位元素越向上移动
  • left:定位元素和定位位置的左侧距离
  • right:定位元素和定位位置的右侧距离
    定位元素水平方向的位置由left和right两个属性控制
    通常情况下只会使用一个
    left越大元素越靠右
    right越大元素越靠左

坐标及方向

在页面中坐标的样式:
在这里插入图片描述

相对定位——position

相对定位:
当元素的position属性值设置为relative时则开启了元素的相对定位

  • 相对定位的特点:
    1.元素开启相对定位以后,如果不设置偏移量元素不会发生任何的变化
    2.相对定位是参照于元素在文档流中的位置进行定位的
    3.相对定位会提升元素的层级
    4.相对定位不会使元素脱离文档流
    5.相对定位不会改变元素的性质块还是块,行内还是行内

eg:元素开启相对定位以后,如果不设置偏移量元素不会发生任何的变化

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><style>.box1,.box2,.box3{width: 100px;height: 100px;}.box1{background-color: teal;}.box2{background-color: tomato;position: relative;}.box3{background-color:rgb(236, 233, 61);}</style></head>
<body><div class="box1"></div><div class="box2"></div><div class="box3"></div></body>
</html>

在这里插入图片描述
eg:相对定位是参照于元素自己在文档流中的位置进行定位的

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><style>.box1,.box2,.box3{width: 100px;height: 100px;}.box1{background-color: teal;}.box2{background-color: tomato;position: relative;left: 100px;top: -100px}.box3{background-color:rgb(236, 233, 61);}</style></head>
<body><div class="box1"></div><div class="box2"></div><div class="box3"></div></body>
</html>

在这里插入图片描述

eg:提升元素的层级

   .box2{background-color: tomato;position: relative;left: 50px;top: -100px}

在这里插入图片描述

绝对定位——absolute

  • 当元素的position属性值设置为absolute时,则开启了元素的绝对定位
  • 绝对定位的特点:
    1.开启绝对定位后,如果不设置偏移量元素的位置不会发生变化
    2.开启绝对定位后,元素会从文档流中脱离
    3.行内元素:行内元素脱离文档流以后会变成块元素,特点和块元素一样。
    4.块元素:块元素不再独占页面的一行;如果没有设置宽度和高度,脱离文档流以后,块元素的宽度和高度默认都被内容撑开;如果设置了宽度和高度,就按设置的来。
    5.绝对定位会使元素提升一个层级
    6.绝对定位元素是相对于其包含块进行定位的
    包含块( containing block ):
  • 正常情况下:
    包含块就是离当前元素最近的祖先块元素
    <div> <div></div> </div>div的包含块就是div
    <div><span><em>hello</em></span></div>em的包含块也是div,因为span是行内元素
  • 绝对定位的包含块:
    包含块就是离它最近的开启了定位(即position不是static即可)的祖先元素,
    如果所有的祖先元素都没有开启定位,则根元素(html)就是它的包含块
  • 初始包含块:html(根元素)
    eg:
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><style>body{font-size: 50px;}.box0{width: 100px;height: 100px;background-color: rgb(52, 78, 102);}.box1 {width: 400px;height: 400px;background-color: teal;}.box2 {width: 100px;height: 100px;background-color: tomato;position:absolute;left: 0px;top: 0px;}.box3 {width: 200px;height: 200px;background-color: rgb(236, 233, 61);}</style></head><body><div class="box0">0</div><div class="box1">1<div class="box3">3<div class="box2">2</div></div></div></body>
</html>

输出:
在这里插入图片描述
如果开启2的定位:

      .box1 {position: relative;width: 400px;height: 400px;background-color: teal;}

输出:
在这里插入图片描述

如果开启3的定位:

.box3 {position: relative;width: 200px;height: 200px;background-color: rgb(236, 233, 61);}

在这里插入图片描述

固定定位 ——fixed

固定定位:

  • 将元素的position属性设置为fixed则开启了元素的固定定位
  • 固定定位也是一种绝对定位(absoult),所以固定定位的大部分特点都和绝对定位一样:
    1.开启固定定位后,如果不设置偏移量元素的位置不会发生变化
    2.开启固定定位后,元素会从文档流中脱离
    3.固定定位会改变元素的性质,行内变成块,块的宽高被内容撑开
    (也就是脱离文档流的特点)
    4.固定定位会使元素提升一个层级
    5.唯一不同的是固定定位永远参照于浏览器的视口(即窗口)进行定位。

即当滚动条滚动时,固定定位的元素的位置不会改变
eg:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><style>body{font-size: 50px;height: 1500px;}.box0{width: 100px;height: 100px;background-color: rgb(52, 78, 102);}.box1 {position: relative;width: 400px;height: 400px;background-color: teal;}.box2 {width: 100px;height: 100px;background-color: tomato;position:fixed;left: 0px;top: 0px;}.box3 {width: 200px;height: 200px;background-color: rgb(236, 233, 61);}</style></head><body><div class="box0">0</div><div class="box1">1<div class="box3">3<div class="box2">2</div></div></div></body>
</html>

在这里插入图片描述

粘滞定位——sticky

该属性,浏览器的支持度不高
粘滞定位

  • 当元素的position属性设置为sticky时则开启了元素的粘滞定位
  • 粘滞定位和相对定位的特点基本一致
    1.元素开启相对定位以后,如果不设置偏移量元素不会发生任何的变化
    2.相对定位会提升元素的层级
    3.相对定位不会使元素脱离文档流
    4.相对定位不会改变元素的性质块还是块,行内还是行内

不同的是:

  1. 粘滞定位可以在元素到达某个位置时将其固定
    2.粘滞定位是参照于body进行定位的
    eg:
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><link rel="stylesheet" href="../reset.css" /><style>.nav{/* width: 1246px; */width: 1250px;height: 50px;background-color: rgb(231,231,226);margin: 50px auto;position: sticky;top:100px;}.nav li{height:50px;float: left;/* 设置height=line-height可以使元素垂直居中 */line-height: 48px;}.nav a{display: block;color: slategray;text-decoration: none;font-size: 18px;padding: 0 42px;}.nav li:last-child a{/* 这样写或者将nav的宽度修改为 width: 1246px; */padding: 0 44px 0 44px;}.nav a:hover{background-color: #3f3f3f;color: white;}.box1{width: 200px;height: 1000px;background-color: darksalmon;}body{height: 2000px;}</style></head><body><ul class="nav"><li><a href="#">HTML/CSS</a></li><li><a href="#">Browser Side</a></li><li><a href="#">Server Side</a></li><li><a href="#">Programming</a></li><li><a href="#">XML</a></li><li><a href="#">Web Building</a></li><li><a href="#">Reference</a></li></ul><div class="box1"></div></body>
</html>

在这里插入图片描述

绝对定位对布局的影响

也是相对于自己的包含快进行分居中等位置操作

水平布局:

当我们开启了绝对定位后,水平方向的布局等式就需要添加left和right两个值,此时规则和之前一样只是多添加了两个值:
left + margin-left + border-left + padding-left + width + padding-rigth + border-right + margin-right + right = 包含块的内容宽度

当发生过度约束:

  • 如果9个值中没有auto 则自动调整right值以使等式满足
    如果有auto,则自动调整auto的值以使等式满足
  • 可设置auto的值
    margin width left right
  • 因为left和right的值默认是auto,所以如果不指定left和right,则等式不满足时,会自动调整这两个值(着重调整right)
    eg:
<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8"><style>.box1{width: 500px;height: 500px;background-color: darksalmon;position: relative;}.box2{position: absolute;width: 100px;height: 100px;background-color: darkseagreen;/* 写不写都一样,因为默认值就是auto */left: auto;right: auto;}</style>
</head>
<body><div class="box1"><div class="box2"></div></div> 
</body>
</html>

在这里插入图片描述
如果:width,right,left都为auto时就不会显示了

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8"><style>body{background-color: darksalmon;}.box1{width: 500px;height: 500px;background-color:rgba(253, 253, 253, 0.288);position: relative;}.box2{position: absolute;/* 写不写都一样,因为默认值就是auto */width: auto;height: 100px;background-color: darkseagreen;/* 写不写都一样,因为默认值就是auto */left: auto;right: auto;}</style>
</head>
<body><div class="box1"><div class="box2"></div></div> 
</body>
</html>

输出:
在这里插入图片描述

水平居中方式:
要先指定 width,并且设置right = left = 0,水平居中才有效果

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8"><style>body{background-color: darksalmon;}.box1{width: 500px;height: 500px;background-color:rgba(253, 253, 253, 0.288);position: relative;}.box2{position: absolute; width: 100px;height: 100px;background-color: darkseagreen;left: 0;right: 0;margin-left: auto;margin-right: auto;}</style>
</head>
<body><div class="box1"><div class="box2"></div></div> 
</body>
</html>

输出:
在这里插入图片描述

垂直方向

垂直方向布局的等式的也必须要满足
top + margin-top/bottom + padding-top/bottom + border-top/border-bottom + height + bottom = 包含块的内容高度
所以可以利用这一特性,使元素垂直居中:

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8"><style>body{background-color: darksalmon;}.box1{width: 500px;height: 500px;background-color:rgba(253, 253, 253, 0.288);position: relative;}.box2{position: absolute; width: 100px;height: 100px;background-color: darkseagreen;top: 0;bottom: 0;margin-top: auto;margin-bottom: auto;}</style>
</head>
<body><div class="box1"><div class="box2"></div></div> 
</body>
</html>

在这里插入图片描述
所以利用绝对定位可以使元素垂直水平居中

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8"><style>body{background-color: darksalmon;}.box1{width: 500px;height: 500px;background-color:rgba(253, 253, 253, 0.288);position: relative;}.box2{position: absolute; width: 100px;height: 100px;background-color: darkseagreen;top: 0;bottom: 0;left: 0;right: 0;margin: auto;}</style>
</head>
<body><div class="box1"><div class="box2"></div></div> 
</body>
</html>

在这里插入图片描述

http://www.khdw.cn/news/37566.html

相关文章:

  • 龙岩市天宫山风景区沈阳seo按天计费
  • 外包加工网上可靠吗网站优化培训
  • 0基础12天精通网站建设关键词歌词简谱
  • 亚马逊品牌备案网站怎么做网络黄页推广软件哪个好用
  • 女女做网站南宁百度推广代理商
  • 自己买空间让网络公司做网站好吗临沂网站建设方案服务
  • php怎么做网站后台外链群发平台
  • 寿光专业做网站的公司有哪些营销推广公司案例
  • 做网站淄博人民网 疫情
  • 百度上找不到网站重庆seo技术教程博客
  • 免费个人网站2018什么平台可以免费打广告
  • 建个公司网站多少钱网站搭建平台
  • 做彩平图的素材那个网站有培训学校管理系统
  • 泉州网站建设公司推荐阿里巴巴国际站运营
  • 原阳县建站塔山双喜专业网络推广公司排名
  • 京东网站建设目标是什么下载优化大师app
  • 临沂做网站找哪家好seo外包网站
  • 做时时彩网站都要什么百度信息流广告怎么投放
  • 那些提卡网站是怎么做的如何进行电子商务网站推广
  • 长春火车站是南站还是北站站长之家网站介绍
  • 酒店 深圳 网站制作深圳百度seo哪家好
  • 滨州正规网站建设价格谷歌搜索引擎seo
  • 自己用模板做网站最新最好的磁力搜索
  • 泉州做网站优化价格关键词优化排名第一
  • 拉萨网站建设熊掌号如何建立网站
  • 香港ccd设计公司官网seo蜘蛛池
  • 织梦 xml 网站地图品牌营销策划包括哪些内容
  • 可以帮忙做网站做公司爱站网关键词排名
  • 毕业设计做网站怎么样网络推广的平台有哪些
  • 常用的开发工具有哪些seo技术顾问阿亮