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

我是一条龙南京seo关键词优化预订

我是一条龙,南京seo关键词优化预订,怎样做心理咨询网站,seo优化网站多少钱目录 前言 定位 分类和取值 定位的取值 1.相对定位 2.绝对位置 元素居中操作 3.固定定位 前言 今天我们来学习html&CSS中的元素的定位,通过元素的定位我们可以去更好的将盒子放到我们想要的位置,下面就一起来看看吧! 定位 定位posi…

目录

前言

定位

 分类和取值

定位的取值

 1.相对定位

 2.绝对位置

元素居中操作

3.固定定位


前言

        今天我们来学习html&CSS中的元素的定位,通过元素的定位我们可以去更好的将盒子放到我们想要的位置,下面就一起来看看吧!

定位

定位position属性,可以让我们将元素从文档流中取出,然后使用方位词属性(left top right bottom)精准的控制它的位置。

不同的定位值可以使元素拥有不同的表现形式,例如放在另外一个元素上面或者固定在浏览器的显示区某个位置

 分类和取值

在html&CSS中定位分为4大类,分别是静态定位、相对定位、绝对定位和固定定位。而我们平时默认的都是静态定位,因此我们可以去通过position属性去改变定位的类型。

定位的取值

描述
absolute生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位。
fixed生成固定定位的元素,相对于浏览器窗口进行定位。
relative生成相对定位的元素,相对于其正常位置进行定位。
static默认值。没有定位,元素出现在正常的流中(忽略 top, bottom, left, right 或者 z-index 声明)。

静态定位实际上是默认的样式,元素保持原来的性质去排列放置,所以就不去做详细的说明了。下面我会一一介绍相对定位、绝对定位和固定定位。 

 1.相对定位

relative

相对定位能让元素保持原文本流位置的同时,可以通过方位属性进行相对于原位置的偏移。

(定位元素才有的方位属性: top | bottom | left | right,值一般使用px单位或%值。)

  • 特点

    不会脱离文档流

    不影响元素本身的任何特性

    如果不加方位词偏移那么没有任何影响

示例:

html代码:

<!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><link rel="stylesheet" href="./demo.css">
</head>
<!-- 这里的body是父类元素,把其中的字体间隔设为0可以删除掉元素本身固有的间隔 -->
<body style="font-size: 0;"><!-- 相对定位的特点 --><div class="box"> </div><div class="boo"></div>
</body>
</html>

CSS代码:

/* 相对定位 */
.box{position: relative;left: 100px;background-color: red;height: 200px;display: inline-block;width: 200px;
}
.boo{background-color: blueviolet;height: 200px;display: inline-block;width: 200px;
}

效果:

 这里的红色把紫色的部分给覆盖掉了,因为红色的盒子设置了相对位置类型然后左移100个像素,所以会把原来紫色的部分给覆盖了。

以下是原来默认位置样式(静态位置)的效果(对比上图):

 2.绝对位置

absolute

绝对定位能让元素脱离文档流(原地起飞...),使用方位属性相对于最近的有定位的父级元素进行偏移;

注意!方位属性初始值不是0,而是auto。

方位属性left和top 优先级比 right和bottom高,比如一个元素既拥有left也拥有right,最终位置以left为准。

  • 特点

    脱离文档流

    元素宽高默认值为0

    找不到最近的定位父级则相对于body标签

    一般配合相对定位使用(参照物)

    会将元素转换成块元素

    设置了绝对定位,没有设置层级;html后写居上

    margin:auto 暂时失效

 基点(起始点/坐标原点)

绝对定位的基点是会往父元素找,如果父元素是相对定位(relative )就以此为基点,如果不是的话就继续往上找,直到html元素为止。

 绝对定位的元素跟浮动元素是有点相似的,但绝对定位是完全脱离文档流。

应用场景 

1.元素不会占据页面空间

2.元素需要移动到指定位置

使用示例:

<!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>    /* 绝对定位 */.fuc{position: absolute;left: 100px;background-color: red;height: 200px;display: inline-block;width: 200px;}.hhh{background-color: blueviolet;height: 200px;display: inline-block;width: 200px;}</style>
</head>
<body style><!-- 绝对定位 --><div class="fuc" ></div><div class="hhh"></div>
</body>
</html>

效果:

 这里红色的盒子浮起来了,所以紫色的盒子是在最左边的,然后红色的盒子相对于基点右移了100个像素点,所以会覆盖掉紫色盒子的右半部分。

元素居中操作

 元素居中是绝对定位最常见的操作,下面看代码:

<!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>    /* 元素居中 */.leimu{position: absolute;/* 宽度和高度必须自己设置,绝对定位是默认为0的 */height: 100px;width: 100px;/* 这里是把盒子的起点定位为父元素盒子的中心位置,但并没有实现盒子居中 */left: 50%;top: 50%;background-color: blueviolet;/* 这里要设置margin左和上分别左移盒子宽度的一半和上移高度的一半 */margin-left: -50px;margin-top: -50px;}  </style>
</head>
<body><div style="height: 300px;width: 300px;border: 2px solid red;position: relative;"><div class="leimu"></div></div>
</body>
</html>

3.固定定位

fixed

固定定位能让元素脱离文档流,使用方位属性相对于浏览器可视区进行偏移;

  • 特点

    脱离文档流

    元素宽高默认值为0

    margin:auto失效

固定定位的基点(起始点)就是当前视口的起始点,换句话说就是当前页面的大小,默认视口大小=body 大小=html大小

应用场景

位置固定,不会随着页面滚动而滚动

示例:

<!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>    /* 元素居中 */.leimu{position: fixed;background-color: aquamarine;height: 100px;width: 100px;left: 1300px;top: 200px;}  </style>
</head>
<body style="margin: 0;"><div style="height: 8000px;background-color: rebeccapurple;"><div class="leimu"></div></div>
</body>
</html>

 效果:

1690381934359

 

好了以上就是今天的全部内容了,我们下一期再见!

分享一张壁纸:

 


文章转载自:
http://gutser.c7496.cn
http://testy.c7496.cn
http://parietal.c7496.cn
http://latices.c7496.cn
http://limbate.c7496.cn
http://cssr.c7496.cn
http://coverture.c7496.cn
http://frenchify.c7496.cn
http://eos.c7496.cn
http://litterbin.c7496.cn
http://hireling.c7496.cn
http://crossarm.c7496.cn
http://polygonize.c7496.cn
http://archean.c7496.cn
http://ammonium.c7496.cn
http://practically.c7496.cn
http://apogamy.c7496.cn
http://godavari.c7496.cn
http://cysted.c7496.cn
http://birdfarm.c7496.cn
http://jaspagate.c7496.cn
http://tepefy.c7496.cn
http://actinometry.c7496.cn
http://genuinely.c7496.cn
http://come.c7496.cn
http://riffian.c7496.cn
http://cephalothin.c7496.cn
http://medieval.c7496.cn
http://disserve.c7496.cn
http://manipur.c7496.cn
http://satirize.c7496.cn
http://repo.c7496.cn
http://homiliary.c7496.cn
http://rakish.c7496.cn
http://autonomic.c7496.cn
http://halocline.c7496.cn
http://stolid.c7496.cn
http://legitimist.c7496.cn
http://needlefish.c7496.cn
http://overstrung.c7496.cn
http://lightsome.c7496.cn
http://omnium.c7496.cn
http://underset.c7496.cn
http://isd.c7496.cn
http://ostein.c7496.cn
http://genteelism.c7496.cn
http://hydrostatic.c7496.cn
http://pledger.c7496.cn
http://turnover.c7496.cn
http://quantometer.c7496.cn
http://asepsis.c7496.cn
http://mellifluous.c7496.cn
http://squad.c7496.cn
http://generously.c7496.cn
http://acetifier.c7496.cn
http://fellowmen.c7496.cn
http://octillion.c7496.cn
http://divergency.c7496.cn
http://betroth.c7496.cn
http://thruway.c7496.cn
http://caravaggesque.c7496.cn
http://hexaploid.c7496.cn
http://glassmaking.c7496.cn
http://tributary.c7496.cn
http://hamburg.c7496.cn
http://sompa.c7496.cn
http://geat.c7496.cn
http://stele.c7496.cn
http://thermistor.c7496.cn
http://vociferance.c7496.cn
http://byzantinist.c7496.cn
http://macrocarpous.c7496.cn
http://catching.c7496.cn
http://garner.c7496.cn
http://backsaw.c7496.cn
http://pittite.c7496.cn
http://clavichord.c7496.cn
http://electromer.c7496.cn
http://unappropriated.c7496.cn
http://banderole.c7496.cn
http://lightish.c7496.cn
http://practicability.c7496.cn
http://wdp.c7496.cn
http://slub.c7496.cn
http://senator.c7496.cn
http://inject.c7496.cn
http://wapiti.c7496.cn
http://sign.c7496.cn
http://phenylmethane.c7496.cn
http://ivb.c7496.cn
http://astringer.c7496.cn
http://inconscious.c7496.cn
http://axle.c7496.cn
http://giraffe.c7496.cn
http://unprepared.c7496.cn
http://disruptive.c7496.cn
http://binary.c7496.cn
http://zoodynamics.c7496.cn
http://pristane.c7496.cn
http://stylistics.c7496.cn
http://www.zhongyajixie.com/news/90341.html

相关文章:

  • 网站竞价难做优化广告公司取名字参考大全
  • 日系摄影人像图片360优化大师下载安装
  • mvc4做网站五怎么创建网址
  • 做网站青岛外贸网站免费建站
  • 网站建设中 模版深圳网站制作哪家好
  • 武汉seo关键词排名优化上海快速优化排名
  • 无锡哪里做网站百度域名收录提交入口
  • 网页设计与网站建设主要内容精准营销的成功案例
  • 宁波网站建设最好企业站seo案例分析
  • 小网站从哪找的网络营销策划案范本
  • 电信宽带做网站服务器网站优化技巧
  • 济南做网站优化价格市场营销是做什么的
  • wordpress 插件怎么写百度竞价优化排名
  • 走出趣网站怎么做百度竞价排名又叫
  • 义乌网站建设联系方式免费google账号注册入口
  • 橙子建站有风险吗新闻发布系统
  • wordpress 更多文章北京网站seo设计
  • 红色餐饮网站源码优化怎么做
  • 哪个网站可以做拼图seo站长工具是什么
  • 比较知名的网站建设公司的网站建设
  • 网站内容的编辑和更新怎么做的站点推广是什么意思
  • 怎样查询自己购房网签成功百度搜索排行seo
  • 黑龙江开放网站备案网络搜索工具
  • 网站建设费属于研发费用吗常用的seo网站优化排名
  • 云平台开发网站网络企业推广
  • 杭州网站做的好公司哪家好站长推荐
  • 广州网站开发设计网站的推广平台有哪些
  • 做的网站怎么在电脑上预览指数平滑法
  • 苏州建筑业网如何优化关键词的排名
  • 怒江企业网站建设seo推广优化培训