day12 css样式
目录
1.标签分类
2.浮动布局
3.margin塌陷
4.定位postion
5.背景图
一. 标签分类
默认在标准文档流
行内标签
span,a,em,i,strong,b,input,img
特点:
1.在一行内显示
2.不能设置宽高,如果不设置宽 默认是字体的大小
ps: 块级元转行内 很少使用
ps:行内标签又包括了行内块标签。属性数display:inline-block
经典标签:input, img
块级标签
div p ul ol li dl dt form table h1~h6
特点:
1.独占一行
2.可以设置宽高,如果不设置宽,默认是父元素100%的宽度
标签分类的属性display,表示要显示 什么状态,可以改变标签属性取值范围inline | block | inline-block | none
ps:一个行内转行内块用的最多
二. 浮动布局
设计初衷是文字环绕
(
marge:0 auto 让一个普通标准文档流下盒子水平居中
垂直居中:父盒子的高度减子盒子的高度除2
)
浮动现象:1. 脱离标准文档流 (不在 页面占位置)
2. 贴边显示
3.文字怀绕
4.收缩现象(一旦给元素设置了浮动,就可以任意设置宽度)
问题:
一旦给子元素设置浮动,父元素不设置高度,因为浮动元素脱标了,不在页面上占位置,撑不起父元素 的高度
清除浮动的方式:
1.给父盒子设置固定高度(不易维护)
2.内墙法
clear:both; 清除左右两边浮动带来的影响
在最后一个浮动元素的后面加一个空的块级元素(标准文档流),并且设置该元素为
缺点: 代码冗余
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
padding: 0;
margin: 0;
}
#header{
width: 100%;
/*height: 100px;*/
}
.container{
width: 1226px;
/*height: 100%;*/
background-color: black;
margin: 0 auto;
} .logo{
width: 55px;
height: 55px;
background-color: darkorange;
float: left;
margin-top: 22px;
}
.list_header{
width: 500px;
height: 100px;
background-color:deepskyblue ;
float: left;
} .form{
width: 250px;
height: 48px;
background-color: darkcyan;
float: right;
margin-top: 28px;
}
.clearfix{
clear: both;
}
</style> </head>
<body> <div id="header">
<div class="container">
<div class="logo"></div>
<div class="list_header"></div>
<div class="form"></div>
<div class="clearfix"></div>
</div> </div>
</body>
</html> 3.伪元素选择器
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
padding: 0;
margin: 0;
}
#header{
width: 100%;
/*height: 100px;*/
}
.container{
width: 1226px;
/*height: 100%;*/
background-color: black;
margin: 0 auto;
} .logo{
width: 55px;
height: 55px;
background-color: darkorange;
float: left;
margin-top: 22px;
}
.list_header{
width: 500px;
height: 100px;
background-color:deepskyblue ;
float: left;
} .form{
width: 250px;
height: 48px;
background-color: darkcyan;
float: right;
margin-top: 28px;
}
.clearfix::after{
content: '';
display: block;
clear: both;
} </style> </head>
<body> <div id="header">
<div class="container clearfix">
<div class="logo"></div>
<div class="list_header"></div>
<div class="form"></div>
<div class="clearfix"></div>
</div> </div>
</body>
</html> 4. overflow:hidden
给父元素添加了overflow hidden也能清除浮动
牵扯了css定制的规则
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
padding: 0;
margin: 0;
}
#header{
width: 100%;
/*height: 100px;*/
}
.container{
width: 1226px;
/*height: 100%;*/
background-color: black;
margin: 0 auto;
overflow: hidden;
} .logo{
width: 55px;
height: 55px;
background-color: darkorange;
float: left;
margin-top: 22px;
}
.list_header{
width: 500px;
height: 100px;
background-color:deepskyblue ;
float: left;
} .form{
width: 250px;
height: 48px;
background-color: darkcyan;
float: right;
margin-top: 28px;
} </style> </head>
<body> <div id="header">
<div class="container">
<div class="logo"></div>
<div class="list_header"></div>
<div class="form"></div>
<div class="clearfix"></div>
</div> </div>
</body>
</html>
ps:布局规则 给一个盒子一旦设置了overflow:hidden|scroll
设置了overflow:hidden 这个盒子就会形成BFC 上下文管理
凡是在BFC中的盒子,有一个布局规则:
父元素的规则也会得到计算
ps:浮动给标签打来的影响:脱离标准流
三. margin塌陷
水平方向 两个margin加起来的距离
垂直:会出现塌陷问题,一个100px的口和一个50px的口会重叠
标准文档流下margin垂直也会出现塌陷,浮动margin不会出现问题
解决方案:给一个盒子设置就好了
四. 定位
position:static;静态 默认的
position: relative;相对定位
参考点:以原来的位置为参考点
现象:
1.压盖现象(一般不用)
2.微调元素
布局方案:
子绝父相
position: absolute; 绝对定位
参考点:
单独设置绝对定位,以页面左上角为参考点
有子绝父相,以最近的父辈元素的左上角为参考点
现象:
1.脱标
2.压盖现象(常用)
position: fixed; 固定定位
参考点:浏览器的左上角
现象:
0.固定在网页上不变
1.脱标
2.压盖(一般不用)
作用:
固定导航栏,小广告,回到顶部
relative相对定位
设置相对定位对盒子没影响,但是对多四个属性 top left (往右) right (往左) bottom
以原来的位置为参考点
现象: 1. 压盖现象 2. 可以微调元素
(vertical-align:middle 设置基线 多用于input,在这里看到的 所以就补充在这儿了。啦啦啦)
absolute 绝对对位 (相对对位一般和绝对定位联合使用,子绝父相)
参考点:单独设置绝对对位以页面左上角为参考点 子绝父相里以父为参考点
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>mi购物车案例</title>
<style>
.shop{
width: 100px;
height: 40px;
background-color: #000;
float: right;
line-height: 40px;
position: relative;
text-align: center;
border-radius: 4px;
} .shop a{
text-decoration: none;
width: 100px;
height: 40px;
display: block;
color: #fff;
font-size: 14px; }
.shop .content{
width: 300px;
height: 100px;
background-color: red;
position: absolute;
top: 40px;
left: -200px;
display: none;
}
.shop:hover{
display: block;
}
</style>
</head>
<body>
<div class="shop">
<a href="#">购物车</a>
<div class="content"></div>
</div> </body>
</html> fixed 固定定位
参考点是浏览器的左上角
z-index 设置优先级
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style> *{
padding: 0;
margin: 0;
} body{
padding-top: 80px;
}
.fix_header{
width: 100%;
height: 80px;
/**/
background-color: black;
position: fixed;
top: 0;
left: 0;
bottom: 10px;
z-index: 10;
} p.active{
position: relative;
color: red;
} </style>
</head>
<body>
<div class="fix_header"></div>
<p>aaaaaaaaaaaivy</p>
<p>ivy</p>
<p>ivy</p>
<p>ivy</p>
<p>ivy</p>
<p>ivy</p>
<p>ivy</p>
<p>ivy</p>
<p class="active">what's the weather like?</p>
<p>ivy</p>
<p>ivy</p>
<p>ivy</p>
</body>
</html>
z-index
z-index只应用在定位的元素,默认z-index:auto;
z-index取值为整数,数值越大,它的层级越高
如果元素设置了定位,没有设置z-index,那么谁写在最后面的,表示谁的层级越高。
从父现象。通常布局方案我们采用子绝父相,比较的是父元素的z-index值,哪个父元素的z-index值 越大,表示子元素的层级越高。
五 背景图
background-color:颜色
background-img: url 写地址
background-position 切图
day12 css样式的更多相关文章
- css样式让input垂直居中
css样式让input垂直居中 css代码: .div1{ border: 1px solid #CCC; width:1120px; height:40px; margin:auto; displa ...
- 深度理解CSS样式表,内有彩蛋....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- js设置css样式.
在js设置css样式做法 var obj = document.getElementById('div'); obj.style.width = '100px'; obj.style.height = ...
- CSS样式表
CSS样式及属性 样式标的基本概念 样式表的分类 1.内联样式表 和html联合显示,控制精确,但可重用性差,冗余多. 例:<p style="font-size:14px;" ...
- 脚本工具(获取某个文件夹下的所有图片属性批量生成css样式)
问题描述: 由于有一次工作原因,就是将某个文件夹下的所有图片,通过CSS描述他们的属性,用的时候就可以直接引用.但是我觉得那个文件夹下的图片太多,而且CSS文件的格式又有一定的规律,所有想通过脚本来生 ...
- jQuery所支持的css样式
jQuery所支持的css样式 backgroundPosition borderWidth borderBottomWidth borderLeftWidth borderRightWidth bo ...
- Yii2 assets注册的css样式文件没有加载
准备引入layui.css文件的,在LayuiAssets类中已经配置了资源属性 <?php namespace frontend\assets; use yii\web\AssetBundle ...
- 获取元素计算后的css样式封装
获取元素计算后的css样式封装: function getCss(obj,attribute) { if(obj.currentStyle) { return obj.currentStyle[att ...
- JS实战 · 仿css样式选择器
代码如下: <html> <head> <meta http-equiv="Content-Type" content="text/ ...
随机推荐
- mybatis工作流程
1)通过Reader对象读取src目录下的mybatis.xml配置文件(该文本的位置和名字可任意) 2)通过SqlSessionFactoryBuilder对象创建SqlSessionFactory ...
- Python - 排序( 插入, 冒泡, 快速, 二分 )
插入排序 算法分析 两次循环, 大循环对队列中的每一个元素拿出来作为小循环的裁定对象 小循环对堆当前循环对象在有序队列中寻找插入的位置 性能参数 空间复杂度 O(1) 时间复杂度 O(n^2) 详细代 ...
- Jmeter联机负载时报错: connection refused to host localhost,nested exception is:java.net ConnectException:Connection refused:connect
Jmeter联机负载时报错: connection refused to host localhost,nested exception is:java.net ConnectException:C ...
- mac被锁有pin码的解锁方法
停用规律: 错误5次密码停用1分钟 再错误3次停用5分钟 在错误1次就停用15分钟 再错误1次就是60分钟了,而且还没输入框了,这时候我们要通过按 option,commond这2个按钮来唤起输入框 ...
- es6 实现单链表
第一种/** * 链表节点类 */ class Node { constructor(ele) { this.ele = ele; this.next = null; } } /** * 链表类 */ ...
- bashdb调试shell脚本
http://note.youdao.com/noteshare?id=ef705313b714cf3a17cfe17dc80956a3
- coreseek(sphinx) 全文检索
转自: http://blog.csdn.net/aidandai/article/details/50464793 编译错误解决--sphinx-0.9.9 I tried to install t ...
- 转:获取windows凭证管理器明文密码
1.运行cmdkey /list查看windows保存凭证 方法1.mimikaz mimikatz vault::cred 2.利用powershell尝试获取 windows 普通凭据类型中的明文 ...
- Linux 下使用 rar 进行压缩和解压缩
1. 下载安装文件 https://www.rarlab.com/download.htm 注意下载 64位的 2. 2019.8 时的下载命令为: wget https://www.rarlab. ...
- [转帖]Zookeeper vs etcd vs Consul比较
Zookeeper vs etcd vs Consul比较 https://it.baiked.com/consul/2341.html 需要转型 加强学习. 如果使用预定义的端口,服务越多,发生冲突 ...