美文网首页
CSS进阶08-绝对定位 Absolute Positionin

CSS进阶08-绝对定位 Absolute Positionin

作者: love丁酥酥 | 来源:发表于2018-03-02 18:17 被阅读41次

(注1:如果有问题欢迎留言探讨,一起学习!转载请注明出处,喜欢可以点个赞哦!)
(注2:更多内容请查看我的目录。)

1. 简介

在绝对定位模型中,盒根据其包含块显式偏移。盒从标准流中完全脱离(对后来的同胞元素没有影响)。绝对定位盒为其标准流的子元素和绝对定位(非固定定位)后代创建新的包含块。然而,绝对定位元素的内容不在任何其他盒的流中,它们可能遮挡其他盒的内容(或被遮挡),这取决于重叠盒子的堆叠层级stack levels

2. 固定定位 Fixed positioning

固定定位是绝对定位的子类。唯一的区别在于,固定定位盒的包含块是由视口创建的。在连续媒体中,当文档滚动时,固定盒不会移动。就这点来讲,它们同固定背景图片fixed background images相像。在分页媒体paged media中,固定定位盒在每一页重复。这对布局很有用,比如,在每个页面的底部放置签名。比页面区域要大的固定定位盒将会被裁剪。固定定位盒在初始化包含块中不可见的部分将不会打印。

开发者可以使用固定定位去创建框架式frame-like布局。考虑如下框架布局:



这可以通过如下HTML文档和样式规则实现:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>A frame document with CSS 2.1</title>
<style type="text/css" media="screen">
   body { height: 8.5in }/* 计算百分百高度需要 */
   #header {
      position: fixed;
      width: 100%;
      height: 15%;
      top: 0;
      right: 0;
      bottom: auto;
      left: 0;
   }
   #sidebar {
      position: fixed;
      width: 10em;
      height: auto;
      top: 15%;
      right: auto;
      bottom: 100px;
      left: 0;
   }
   #main {
      position: fixed;
      width: auto;
      height: auto;
      top: 15%;
      right: 0;
      bottom: 100px;
      left: 10em;
   }
   #footer {
      position: fixed;
      width: 100%;
      height: 100px;
      top: auto;
      right: 0;
      bottom: 0;
      left: 0;
   }
</style>
</head>
<body>
   <div id="header"> ...  </div>
   <div id="sidebar"> ...  </div>
   <div id="main"> ...  </div>
   <div id="footer"> ...  </div>
</body>
</html>

参考

https://www.w3.org/TR/CSS22/visuren.html#visual-model-intro
https://www.w3.org/TR/CSS2/visuren.html
CSS规范 > 9 视觉格式化模型 Visual Formatting Model

相关文章

  • CSS进阶08-绝对定位 Absolute Positionin

    (注1:如果有问题欢迎留言探讨,一起学习!转载请注明出处,喜欢可以点个赞哦!)(注2:更多内容请查看我的目录。) ...

  • 定位

    绝对定位 position: absolute 绝对定位元素脱离正常文档流,相对其定位上下文(Positionin...

  • 二十,CSS定位概述与相对定位

    CSS定位:position:relative(相对)/absolute(绝对)/ static(无定位)/ fi...

  • 关于CSS定位

    在CSS中关于定位的内容是:position:relative(相对定位)absolute(绝对定位) ...

  • css入坑之二

    css的元素定位->position属性 1.position:absolute 绝对定位。绝对定位是子元素相对于...

  • CSS相对定位(position)

    CSS定位方式有:相对定位(relative)、绝对定位(absolute)和固定定位(fixed) positi...

  • CSS定位

    CSS定位 定位有三种,分别是相对定位(relative)、绝对定位(absolute)、固定定位(fixed)。...

  • CSS 定位(postion、z-index)

    CSS 定位 CSS有三种基本的定位机制:普通流,浮动,绝对定位(absolute, fixed):普通流是默认定...

  • css绝对定位、相对定位和文档流的那些事

    css绝对定位、相对定位和文档流的那些事 margin塌陷 position:absolute; display:...

  • css课程学习

    1.css伪类### 2.css3新增伪类### 3.伪元素### 4.定位### 绝对定位(absolute):...

网友评论

      本文标题:CSS进阶08-绝对定位 Absolute Positionin

      本文链接:https://www.haomeiwen.com/subject/qbenxftx.html