首页 > 其他分享 >边框、display、盒子模型、浮动、溢出、定位、z-index

边框、display、盒子模型、浮动、溢出、定位、z-index

时间:2022-12-02 23:11:09浏览次数:32  
标签:index 定位 标签 100px 边框 width border display

目录

边框

border-left-width: 5px;  宽度
border-left-style: dotted;  样式
border-left-color: #0000ff;   颜色

image
image

border-top-width: 10px;
border-top-style: solid;
border-top-color: green;

image

border-right-width: 10px;
border-right-style: dashed;
border-right-color: red;

border-bottom-width: 5px;
border-bottom-style: solid;
border-bottom-color: darkorange;

image

前缀一样可以缩写
border-left: 3px solid black;
border-top: 5px dotted orange;
打乱顺序也可以
border-right: coral 10px solid;
border-bottom: dashed 15px red;

image

这个就是上下左右都用一样的格式
border: 10px solid orange;

image

画圆
边框默认是矩形,通过 border-radius: 50%; 变成圆形,但要设置长宽,长宽不一样就是矩形

image

display

"""
行内标签是无法设置长宽 只有块儿级可以设置
"""
display:none  彻彻底底的隐藏标签(页面上不会显示 也不会保留标签的位置)

没隐藏之前
image
隐藏之后
image

visibility: hidden  隐藏的不彻底,不会显示,但是位置还会保留,不好用

盒子模型

我们可以将标签看成是一个盒子(快递盒)
所有标签都有,主要是说div标签

1.快递包里面的实际物体			 content(内容)
2.物体与内部盒子墙的距离	       padding(内边距、内填充)
3.快递盒的厚度				   border(边框)
4.快递盒之间的距离				  margin(外边距)

image

padding-left: 50px;  让文字离边框左边50px
padding-top: 60px;让文字离边框上边60px
padding-right: 10px;让文字离边框右边50px,要文字长度够长,不然看不出效果
padding-bottom: 80px;让文字离边框下边50px

image

padding: 20px; 一个位置,上下左右

image

padding: 20px 40px;两个位置  上下   左右

image

padding: 10px 20px 30px;三个位置 上  左右  下

image

padding: 10px 20px 30px 40px;四个位置 上 右 下 左

image

按照上、右、下、左的顺序
margin
调节边框与边框的距离
 margin-top: 20px;

image

margin与padding相似

浮动

浮动就是用来做页面布局的

浮动的现象
	float:left\right,多个浮动依次排列
   
浮动带来的影响
	浮动的元素是脱离正常文档流的 会造成父标签塌陷

未浮动前
image
浮动后
image

如何解决浮动的影响
	clear  (地面 天空)不允许出现浮动的元素

image

解决浮动带来的影响终极方法
	先提前写好样式类
    	.clearfix:after {  给某个标签尾部添加东西
            content: '';  添加空字符串,是文本的格式
            display: block;  变成块级标签,独占一行
            clear: both; 左右两边不允许有浮动元素(地面、天空)
        }
	谁塌陷了 就给谁添加clearfix样式类就可以了

image

ps:浏览器会优先展示文本内容(如果被挡住)

image

溢出

边框里面放不下

image

overflow: hidden; 直接多的就隐藏

image

overflow: auto; 生成一个可以滚动的区域查看

image

图片操作
图片溢出了
div {
height: 150px;
width: 150px;
border: 5px solid greenyellow;
border-radius: 50%;
}

image

overflow: hidden;  被隐藏

image

overflow: auto; 滚动条,效果也不好

image

div img {
max-width: 100%; 等比缩放,要配合overflow使用,先把图片放进去
        }

image

定位

标签在默认情况下都是无法通过定位的参数来移动
针对定位有四种状态
	1.static静态(标签默认的状态 无法定位移动)
 	2.relative相对定位(基于标签原来的位置)
 	3.absolute绝对定位(基于某个定位过的父标签做定位)
	4.fixed固定定位(基于浏览器窗口固定不动)

image

relative相对定位(基于标签原来的位置)
.c1 {
background-color: red;
height: 100px;
width: 100px;
position: relative;
}

image

absolute绝对定位(基于某个定位过的父标签做定位,就是一个已经定位过了的标签)
.c1 {
background-color: red;
height: 100px;
width: 100px;
position: relative;
}
.c2 {
background-color: greenyellow;
height: 100px;
width: 200px;
position: absolute;
top: 100px;
left: 100px;
}

image

fixed固定定位(基于浏览器窗口固定不动)
.c1 {
border: 5px solid black;
height: 100px;
width: 100px;
position: fixed;
right: 100px;
bottom: 200px;
}

image

z-index

做出分层的页面

body {
margin: 0; 把浏览器自带的间隙去除
}
.cover {
background-color: rgba(127,127,127,0.5);
position: fixed;  把位置固定
left: 0;  把浏览器所有位置顶满
bottom: 0; 
right: 0;
top: 0;
z-index: 100; 浏览器默认高度是零,可以改
}
.modal {
height: 200px;
width: 400px;
background-color: white;
z-index: 101;
position: fixed;
left: 50%; 调整位置
top: 50%;
margin-left: -200px;
margin-top: -100px;
        }

image
image
image

标签:index,定位,标签,100px,边框,width,border,display
From: https://www.cnblogs.com/8564129qwe/p/16945965.html

相关文章