position用法
fixed的用法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.pg-header{
background-color: red;
height: 48px;
/*添加position后可以使该div与其他div处于屏幕的不同层,fixed为将该div固定到浏览器窗口的指定位置,
top、bottom、right、left四个方位代表了离屏幕有多少距离*/
position: fixed;
top: 0px;
right: 0px;
left: 0px;
}
.pg-body{
background-color: darkgray;
height: 5000px;
margin-top: 50px;
}
.pg-back_to_top {
background-color: black;
color: white;
height: 50px;
width: 50px;
position: fixed;
right: 10px;
bottom: 10px;
}
</style>
</head>
<body>
<div class="pg-header">标题</div>
<div class="pg-body">内容</div>
<div onclick="GoTop();" class="pg-back_to_top">返回顶部</div>
<script>
function GoTop(){
console.log("123")
document.documentElement.scrollTop = 0;
}
</script>
</body>
</html>
absolute和relative用法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--position的relative如果单独使用,没有任何效果,因为它是自己定义自己,对div自己没有任何实际意义。
但如果这个div的内部还有div,而且这个内部的div想要定义自己相对于父div的位置,就需要在自己的position
属性添加absolute-->
<div style="position:relative;width: 500px;height: 200px;border: 1px solid red;margin: 0 auto">
<div style="position: absolute;bottom: 0px;width: 50px;height: 50px;background-color: black"></div>
</div>
<div style="position:relative;width: 500px;height: 200px;border: 1px solid red;margin: 0 auto">
<div style="position: absolute;top: 0px;right: 0px;width: 50px;height: 50px;background-color: black"></div>
</div>
<div style="position:relative;width: 500px;height: 200px;border: 1px solid red;margin: 0 auto">
<div style="position: absolute;top: 0px;width: 50px;height: 50px;background-color: black"></div>
</div>
</body>
</html>e
z-index属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--z-index可以设置层级页面的优先级,值越大,优先级越高,优先级高的放在最上面-->
<div style="z-index: 10;background-color: white;position: fixed;height: 200px;width: 400px;
top: 50%;left: 50%;margin-top: -200px;margin-left: -200px">
<input type="text"/>
<input type="text"/>
<input type="text"/>
</div>
<div style="z-index:9;position: fixed;background-color: darkgray;
top: 0;
bottom: 0;
left: 0;
right: 0;
/*opacity属性为设置div的透明度,值越大,背景色越深*/
opacity: 0.5"></div>
<div style="height: 5000px;background-color: green">第一层页面</div>
</body>
</html>
position用法的更多相关文章
- css 之position用法详解
css 之position用法详解: http://www.jb51.net/web/77495.html
- HTML之Position用法
在此,先做声明,本篇仅是摘录自互联网,个人认为这篇文章讲的很不错,附于此地与大家共同欣赏. position的四个属性值: 1.relative2.absolute3.fixed4.static下面分 ...
- html 之 position用法
引用: position的四个属性值: 1.relative2.absolute3.fixed4.static下面分别讲述这四个属性. <div id="parent"> ...
- 浅谈 css 之 position用法
在 css中, position 属性有四个值可用: static(默认值).absolute.relative.fixed. relative:相对定位(相对于自身进行在常规流中的位置进行定位,保留 ...
- CSS中常见的位置(position)属性
常用的位置属性列表: position(top.bottom.left.right) .overflow.z-index position用法: 值 描述 relative 相对定位,原位置仍占用空间 ...
- CSS语法与用法小字典
前言:这是上学时期对CSS学习的整理,一直没见过光,由于不是专门做前端开发的,难免写不到重点,但对于看懂CSS,和掌握一些基本的用法,熟悉里面的门路还是大有裨益的.由于是从word中贴过来的,排版和格 ...
- [js - 算法可视化] 汉诺塔(Hanoi)演示程序
前段时间偶然看到有个日本人很早之前写了js的多种排序程序,使用js+html实现的排序动画,效果非常好. 受此启发,我决定写几个js的算法动画,第一个就用汉诺塔. 演示地址:http://tut.ap ...
- 顶点/片元 shader 总结
Cg顶点程序必须在结构中传递顶点数据.几种常用的顶点结构定义在文件UnityCG.cginc中,有如下三种结构体: 1.appdata_base: 包含顶点位置,法线和一个纹理坐标.2.appdata ...
- WEB入门.六 盒子模型
学习内容 CSS盒子模型 盒子之间的关系 页面元素定位 能力目标 理解盒子模型 理解内容与表现分离的优点 理解并掌握盒子之间的关系 理解并掌握绝对定位与相对定位的用法 本章简介 上一章节中已经讲解了页 ...
随机推荐
- 设置eclipse中jsp/html文件好看的自动排版
注:本文转载于ieayoio,原文链接:https://blog.csdn.net/ieayoio/article/details/49930587#8912689 eclipse中jsp文件代码的排 ...
- 嵌入式系统LINUX环境搭建
Linux kernel Complier: http://supportopensource.iteye.com/blog/680483 sudo make mrproper 净化解 ...
- javascript——事件处理模型(DOM 和 IE)
javascript的事件处理模型分为 DOM事件处理模型和 IE事件处理模型. 一.DOM事件流模型 DOM事件流分为三个阶段:捕获阶段.目标阶段.冒泡阶段. 捕获阶段:自上而下,由document ...
- JS中,split()用法(将字符串按指定符号分割成数组)
<!DOCTYPE html> <html> <head> <meta charset="{CHARSET}"> <title ...
- @Value在Controller中取值
一.使用 @Value("${name}")注解可以获取自定义的properties文件中的name值 二.配置 如果只是在applicationcontext.xml中配置,那么 ...
- python的面向对象编程
面向对象编程是一种程序的范式,它把程序看成是对不同对象的相互调用,对现实世界建立的一种模型. 面向对象编程的基本思想,类和实例.类用于定义抽象对象,实例根据类的定义被创建出来. 在python当中我们 ...
- c++primer-p100.用迭代器进行二分法搜索
#include <vector> #include <iostream> using namespace std; int main() { vector<int> ...
- [Python Study Notes]csv文件操作
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- Generalized Low Rank Approximation of Matrices
Generalized Low Rank Approximations of Matrices JIEPING YE*jieping@cs.umn.edu Department of Computer ...
- js中的各种宽高
在设计页面时可能经常会用到固定层的位置,这就需要获取一些html对象的坐标以更灵活的设置目标层的坐标,这里可能就会用到document .body.scrollTop等属性,但是此属性在xhtml标准 ...