relative脱离文档流后依然占有原来的位置,而absolute脱离文档流后不占有后面的位置。
绝对定位常用于图片上的浮动标记。
static为默认的定位方式 <==>none
常用的搭配:子绝父相,自己改变位置,父级占有位置,防止后面的内容占有位置。
当父元素没有设置高度,因为子元素而导致父元素高度为0。
额外标签法
<div style="clear:both;"></div>
为父级添加overflow:hidden;
使用:after
伪元素选择器
selector:after {
content: "";
display: block;
clear: both;
height: 0;
visibility: hidden;
}
使用:before & :after
双伪类元素
selector:before,
selector:after {
content: "";
display: table;
}
selector {
clear: both;
}
使用可以脱离文档流的属性
display: table | fixed
position: absolute | fixed
完全脱离文档流,以可视浏览器窗口作为父级元素。固定定位=可视浏览器窗口+边偏移。
对已经(绝对/固定)定位的元素使用margin:auto让元素居中显示无效。需要使用top/left/right/bottom + margin-left/right/top/bottom。
/* 定位元素居中*/
selector {
/* 垂直居中*/
top: 50%;
margin-top: -1/2 * height;
}
使用了定位多个元素,回有堆叠作用,后面的叠在前面的上面。
解决办法:z-index:number;
。取值为整数,值越大,优先级越高。只能作用于使用了position的元素,对其他的标准流、浮动等无效。后面不跟单位。
以上方法都可以达到显示模式转换的效果,更改元素的display属性值。
border-top-left-radius:length;
border-top-right-radius:length;
border-bottom-right-radius:length;
border-bottom-left-radius:length;
先写上下再左右。
使用display:none,也可以使用visibility:hidden都可以达到隐藏的效果。但是,display隐藏后不会包留原来的位置。
outline:color||style||width;
一般情况下都是用outline:none取消轮廓线。
防止任意拖拽,resize:none。
实现内容垂直方向上定位,只作用于行内元素与行内块级元素。通常用来对行内块元素与文字的对齐,图片点对于文字的顶线、中线、基线、底线对齐。默认情况下是基线对齐。
可取值:top || middle || baseline || bottom
white-space 用来设置或检索对象内文字的显示方式。
white-space:normal; /* 默认方式*/
white-space:nowrap; /* 强制一行显示,直到文本结束或者遇到<br>才进行换行*/
text-overflow 用来设置或检索是否使用(...)表示对象内文字的溢出。
text-overflow:clip; /*不需要省略标记(...)表示,而是直接剪裁*/
text-overflow:ellipsis;/*对象内文字溢出时使用省略号(...)表示*/``
使用方式
/*第一步,先使用white-space使得文字强制一行显示*/
white-space:nowrap;
/*第二步,使用overflow使得溢出的文字隐藏*/
overflow:hidden;
/*第三步,用省略号代替溢出的部分*/
text-overflow:ellipsis;
将多个图标的背景图放置于一张大图上,通过改变背景图的位置实现获取相应的背景图,减少浏览器与服务器的交互次数。
top/left/right/bottom;margin-left/right/top/bottom
margin-left/right/top/bottom:-1px;
,border-collapse只作用于表格。该方法会导致后面的元素压住前面的元素。font-size:0;line-hight:0;
<link rel = "shortcut icon" href = "favicon.ico" type = "image/x-icon">
@font-face {
font-family:‘icomoon‘;
/*2,一定要注意跻径的间题*/
src:url( ‘fonts/icomoon.eot?7kkyc2‘ );
src:url(‘fonts/icomoon.eot?7kkyc2#iefix‘) format( ‘embedded-opentype‘)
url(‘fonts/icomoon.ttf?7kkyc2‘ ) format( ‘truetype‘),
url( ‘fonts/icomoon.woff?7kkyc2‘ ) format( ‘woff‘ ),
url(‘fonts/icomoon.svg?7kkyc2#icomoon‘ ) format(‘svg‘);
font-weight: normal;
font-style: normal;
}
文字的前进方式不同。
span {
position: absolute;
top: 0;
left: 100px;
height: 14px;
background-color: red;
line-height: 14px;
}
<span>8</span>
transition: 属性值 过渡时间 过渡形式 延迟时间;
top | right | left | bottom 只对已经定位的元素有效果。
有行高可不设置高度。
行内块元素与文字垂直居中:vertical-align & display:inline-block。
原文:https://www.cnblogs.com/JonnyJiang-zh/p/13546092.html