html学习3-CSS补充
position
fixed:把标签固定在页面的某处
例子:使用fixed制作“回到顶部”按钮
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div onclick="GoTop();" style="width:50px;height:50px;background-color:black;color:white;
position:fixed;bottom:20px;right:20px">
返回顶部
</div>
<div style="height:5000px;background-color:#dddddd">
ddfdfdadfdf
</div>
<script>
function GoTop(){
document.documentElement.scrollTop = 0;
console.log(document.documentElement.scrollTop)
}
</script>
</body>
</html>
例子2:固定页面头部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.pg-header{
height:48px;
background-color:black;
color:#dddddd;
position:fixed;
top:0;
right:0;
left:0;
}
.pg-body{
background-color:#dddddd;
height:5000px;
margin-top:50px;
}
</style>
</head>
<body>
<div class="pg-header">头部</div>
<div class="pg-body">内容</div>
</body>
</html>
absolute:把标签固定在页面的某处,位置是绝对固定的
relative:通常和absolute一起用
<div style='position:relative;'>
<div style='position:absolut;top:0,right:0;'></div>
<div/>
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div style="width:50px;height:50px;
background-color:black;
position:absolute;
right:0;
bottom:0;"> </div>
<div style="margin:0 auto;position:relative;width:500px;height:200px;border:1px solid red;">
<div style="position:absolute;left:0;bottom:0;width:50px;height:50px;background-color:black;"></div>
</div>
<div style="margin:0 auto;position:relative;width:500px;height:200px;border:1px solid red;">
<div style="position:absolute;right:0;bottom:0;width:50px;height:50px;background-color:blue;"></div>
</div>
<div style="margin:0 auto;position:relative;width:500px;height:200px;border:1px solid red;">
<div style="position:absolute;right:0;top:0;width:50px;height:50px;background-color:blue;"></div>
</div> <div style="height:5000px;background-color:#dddddd;">
ddfdfdadfdf
</div>
</body>
</html>
页面分层显示:
z-index
opacity 透明 值:0-1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div style="display:none;z-index:10;
position:fixed;background-color:white;
height:100px;
width:500px;
top:50%;
left:50%;
margin-left:-250px;margin-top:-200px; ">
<input type="text">
<input type="text">
<input type="text">
</div> <div style="display:none;z-index:9;position:fixed;background-color:#dddddd;
top:0;
bottom:0;
left:0;
right:0;
opacity:0.5;
"></div> <div style="height:5000px;background-color:green;">
ddfdfdadfdf
</div>
</body>
</html>
overflow
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div style="height:200px;width:300px;overflow:hidden;">
<img src="IMG_1980.JPG">
</div>
<p></p>
<div style="height:200px;width:300px;overflow:auto;">
<img src="IMG_1980.JPG">
</div>
</body>
</html>
hover
鼠标移动到标签时,属性才生效
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.pg-header{
position:fixed;
right:0;
left:0;
top:0;
height:48px;
background-color:#2459a2;
line-height:48px;
} .pg-body{
margin-top:50px;
} .w{
width:980px;
margin:0 auto;
} .pg-header .menu{
display:inline-block;
padding:0 10px 0 10px;
color:white;
} .pg-header .menu:hover{
background-color:blue;
}
</style>
</head>
<body>
<div class="pg-header">
<div class="w">
<a class="logo">LOGO</a>
<a class="menu">全部</a>
<a class="menu">42区</a>
<a class="menu">段子</a>
<a class="menu">1024</a>
</div>
</div>
<div class="pg-body">
<div class="w">g</div>
</div>
</body>
</html>
background-color 背景颜色
background-image:url('xxx.gif')#默认。div大,图片重复放
background-repeat:no-repeat/repeat-x/repeat-y 图片重复加载
background-position:10px 10px/position-x/position-y 移动背景图片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<span style="background-image:url('微笑.gif');height:20px;width:20px;display:inline-block;"></span>
<div style="height:35px;width:400px;position:relative;">
<input type="text" style="height:35px;width:370px;padding-right:30px" />
<span style="position:absolute;right:0;top:10px;background-image:url('微笑.gif');height:25px;width:25px;display:inline-block;"></span> </div> <div style="width:200px;height:200px;border:1px solid red;
background-image:url('土拨鼠.gif');
background-repeat:no-repeat;
background-position-x:10px;
background-position-y:10px"></div>
</body>
</html>
结束
html学习3-CSS补充的更多相关文章
- jQuery 顺便学习下CSS选择器 奇偶匹配nth-child(even)
今天学习jQuery,看到nth-child(even)用法,特意找了下这个选择器的用法,在CSS3标准中,用法很强大. 对此,我把CSS3标准中nth-child()用法大致介绍下: CSS3伪类选 ...
- CSS补充与JavaScript基础
一.CSS补充 position 1.fiexd 固定在页面的某个位置; 示例将顶部菜单始终固定在页面顶部 position: fixed; 将标签固定在某个位置 right: 0; 距离右边0像素 ...
- CSS补充之--页面布局、js补充,dom补充
CSS补充之--页面布局 主站一:(下面是一个大致的模板) <div class="pg-header"> <div style="width: 120 ...
- css补充、JavaScript、Dom
css补充: position: fixed:可以将标签固定在页面的某个位置 absolute+relative:通过两者的结合可以让标签在一个相对的位置 代码例子:(通过fixed标签将某些内容固定 ...
- 如何从零开始学习DIV+CSS
CSS是样式,DIV是层.DIV+CSS是网站标准(web标准),通常为了说明与HTML网页设计语言中的表格(table)定位方式的区别.因为XHTML网站设计标准中,不再使用表格定位技术,而是采用D ...
- 学习完毕-css
最近零零散散学习了css 最后附带链接,里面有css的全部demo.有空的可以练习练习,下一步 --->js -----http://www.w3cschool.cc/css/css-examp ...
- ReactNative学习之css样式使用
前言: 前面学习了html,今天学习一下css的基本使用,看下html与css之间是如何结合来编写前端网页的. CSS 是什么? CSS 是 Cascading Style Sheets(级联样式表) ...
- Learning ROS for Robotics Programming Second Edition学习笔记(三) 补充 hector_slam
中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...
- HTML+CSS补充
1. HTML+CSS补充 - 布局: <style> .w{ width:980px;margin:0 auto; } </style> <body> <d ...
- 2016.01.22 前端学习 HTML/CSS
学习HTML/CSS http://edu.51cto.com/course/course_id-3116.html 明日实践
随机推荐
- SSIS 查找 组件
通过SSIS的“查找”组件进行不同数据源之间数据的合并操作 为了协助开发还原生产环境中的某些bug,需要将将生产环境的某些特定表数据导入到测试环境做测试,之前一直都是暴力地truncate测试环境的表 ...
- apache配置跨域请求代理
1.配置允许跨域请求 Header always set Access-Control-Allow-Origin "*"Header always set Access-Contr ...
- [LOJ113] 最大异或和 - 线性基
虽然是SB模板但还真是第一次手工(然而居然又被运算符优先级调戏了) #include <bits/stdc++.h> using namespace std; #define int lo ...
- JS定义类的六种方式详解
转载自: http://www.jb51.net/article/84089.htm 在前端开发中,经常需要定义JS类.那么在JavaScript中,定义类的方式有几种,分别是什么呢?本文就JS定义类 ...
- 手机大厂必备测试技能-GMS 认证
GMS认证背景 在之前的一篇文章有给各位小伙伴们科普过关于GMS的作用,http://www.lemfix.com/topics/266 "墙"内的小伙伴可能很少会用到这样的服务, ...
- ASP.NET + MVC5 入门完整教程八 -—-- 一个完整的应用程序(下)
https://blog.csdn.net/qq_21419015/article/details/80802931 SportsStore 1.导航 添加导航控件 如果客户能够通过产品列表进行分类导 ...
- AcWing 913. 排队打水
#include <iostream> #include <algorithm> using namespace std; typedef long long LL; ; in ...
- bzoj 3669: [Noi2014]魔法森林 (LCT & kruskal)
这道题呢, 首先按照关键字a排序,然后不断地加边,用lct维护这个过程 具体实现: 先按照关键字a排序,枚举每一条边,判断两点是否已经联通(kruskal 部分)如果联通,就在两点路径间寻找最大的b, ...
- 安装java jdk环境jdk1.8
1) yum 安装java jdk 1.8 * -y 验证java [root@localhost local]# java -version openjdk version "1.8.0_ ...
- intellij idea设置打开多个文件显示在多行tab上