空格
<img src="图片路径" />
<link href="css文件相对路径" rel=“stylesheet” type=“text/css"/>
标签选择器
p{ } 作用于p
class选择器 .red{ } 引用 class="red"
id选择器 #hd{ } 引用id=“hd”
优先级 id>class>标签
层次选择器
E F E后的所有F
E>F E后的儿子(第一代)
E+F 元素E的相邻弟弟(就一个)
E~F 元素E的所有弟弟
引用 #second>p{ }
<div id="second">
<p> </p>
<p> </p>
</div>
伪类选择器
p:nth-child(5) {color:red;} 第5个标签红色
p:nth-child(2n-1) {color:red;} 奇数 2n 偶数 -n+5 前5行 n+5 第5行到最后
p:nth-last-child(-n+4) 从后往前 后4行
font_family:"微软雅黑" font-size:16px; 字体大小
font-style:italic;斜体 font-weight:boder 字体加粗 bolder更粗
text-align:center; text-decoration:line-through 划线
underline | 定义文本下的一条线。 |
overline | 定义文本上的一条线。 |
line-through | 定义穿过文本下的一条线。 |
text-indent:2em 缩进2字符 line-height:16px 行高最好是文字的1.5倍
letter-spacing:20px; 字符间距
盒子 宽width: 高 height:
边框 border:10px solid red; 宽度 样式 颜色;
内边距 padding:30px; 外边距:margin
清空所有外边距,内边距
*{ margin=0; padding=0; }
盒子总宽=内宽度(wdith)+左右padding+左右 border+左右margin
盒子居中 margin:0 auto; 上下 左右
back ground-img:url( 路径) 在css中引用路径从css开始进行计算
默认图片进行平铺 加 back-ground-repeat:no-repeat;
background-position :right bottom; x轴 y轴 居于盒子右下方
x轴 left right center y轴 top center bottom
div{ width :400px;
height:400px;
padding:60px
}
加padding改变了原长度 想和原来一样 需要 width-60px height-60px
padding-top :60px height单独减60px
浮动 float:left right
使用浮动的元素都变成一致的盒子,盒子模型有效,不独占一行,浮动元素会占用下面元素的空间
用clear消除 clear:both;
浮动元素对父元素的影响 浮动元素脱离文档流 父元素塌陷 解决在父元素加 overflow:hidden;
定位 css
position:static:默认
relative:相对定位
absolute:绝对定位 绝对定位的元素的位置相对于最近的已定位父元素,如果元素没有已定位的父元素,那么它的位置相对于<html>:
fixed:固定定位
元素的位置相对于浏览器窗口是固定位置。即使窗口是滚动的它也不会移动:
偏移 css
top 元素偏移相对于盒子的上边距离 bottom left right
position:absolute;
bottom0;right 0; 定在浏览器右下角
在他的父元素写 position:relative; 定在父元素的右下角