三角形的画法,一般经常使用三角形作为提示框、下拉菜单等功能。
一、CSS 画三角形实现方式
1、HTML 结构
1 |
|
2、将类名为 item 的块级元素的 width、height 设置为 0
1 |
|
3、将类名为 item 的元素的 3 个 border 的颜色设置为 transparent,箭头指向的对面 border 设置颜色;
1 |
|
上面的为方向向上的三角形
4、依次类推可以画出方向向左、右、下的三角形
1 |
|
二、网页变成灰色的方法:
1 |
|
三、position 定位
static: 默认值
relative: 相对定位 相对于自身原有位置进行偏移,仍处于标准文档流中
absolute: 绝对定位 相对于最近的已定位的祖先元素
fixed: 固定定位 相对于视窗来定位
四、浮动、清楚浮动
1 |
|
一、HTML
新增选择器 document.querySelector、document.querySelectorAll
拖拽释放(Drag and drop) API
媒体播放的 video 和 audio
本地存储 localStorage 和 sessionStorage
离线应用 manifest
桌面通知 Notifications
语意化标签 article、footer、header、nav、section
增强表单控件 calendar、date、time、email、url、search
地理位置 Geolocation
多任务 webworker
全双工通信协议 websocket
客户端和服务端双向通信
历史管理 history
跨域资源共享(CORS) Access-Control-Allow-Origin
页面可见性改变事件 visibilitychange
跨窗口通信 PostMessage
Form Data 对象
绘画 canvas
HTML 的语义化:
1 |
|
语义化的优点:
- 易于用户阅读,样式丢失的时候能让页面呈现清晰的结构。
- 有利于 SEO,搜索引擎根据标签来确定上下文和各个关键字的权重。
- 方便屏幕阅读器解析,如盲人阅读器根据语义渲染网页
- 有利于开发和维护,语义化更具可读性,代码更好维护,与 CSS3 关系更和谐。
二、CSS
css 的继承:
无继承性的属性:
1、display:规定元素应该生成的框的类型
2、文本属性:
vertical-align:垂直文本对齐
text-decoration:规定添加到文本的修饰
text-shadow:文本阴影效果
white-space:空白符处理
unicode-bidi:设置文本方向
3、盒子模型属性:
width、height、margin 、margin-top、margin-right、margin-bottom、margin-left、border、 border-style、border-top-style、border-right-style、border-bottom-style、border-left-style、border-width、border-top-width、border-right-right、border-bottom-width、border-left-width、border-color、border-top-color、border-right-color、border-bottom-color、border-left-color、border-top、border-right、border-bottom、border-left、padding、padding-top、padding-right、padding-bottom、padding-left
4、背景属性:
backgroun、background-color、background-image、background-repeat、background-position、background-attachment
5、定位属性:
float、clear、position、top、right、bottom、left、min-width、min-height、max-width、max-height、overflow、clip、z-index
其他。。。
有继承性属性
1、字体系列:
font:组合字体
font-family:规定元素的字体系列
font-weight:设置字体的粗细
font-size:设置字体的尺寸
font-style:定义字体的风格
2、文本系列属性:
text-indent:文本缩进
text-align:文本水平对齐
line-height:行高
word-spacing:增加或减少单词间的空白(即字间隔)
letter-spacing:增加或减少字符间的空白(字符间距)
text-transform:控制文本大小写
direction:规定文本的书写方向
color:文本颜色 a 元素除外
3、元素可见性
visibility
其他。。。
块级元素哪些属性可以继承?
text-indent、text-align、visibility、cursor
盒模型:
标准盒模型:盒子总宽度/高度 =width/height + padding + border + margin。( 即 width/height 只是 内容高度,不包含 padding 和 border 值 )
IE 盒子模型:盒子总宽度/高度 =width/height + margin = (内容区宽度/高度 + padding + border) + margin。( 即 width/height 包含了 padding 和 border 值 )
BFC 是什么?(边距重叠解决方案)
BFC 是 CSS 布局的一个概念,是一块独立的渲染区域,是一个环境,里面的元素不会影响到外部的元素 。
父子元素和兄弟元素边距重叠,重叠原则取最大值。空元素的边距重叠是取 margin 与 padding 的最大值。
BFC 原理?
(1)内部的 Box 会在垂直方向,从顶部开始一个接着一个地放置;
(2)Box 垂直方向的距离由 margin(外边距)决定,属于同一个 BFC 的两个相邻 Box 的 margin 会发生重叠;
(3)每个元素的 margin Box 的左边, 与包含块 border Box 的左边相接触,(对于从左到右的格式化,否则相反)。即使存在浮动也是如此;
(4)BFC 在页面上是一个隔离的独立容器,外面的元素不会影响里面的元素,反之亦然。文字环绕效果,设置 float;
(5)BFC 的区域不会与 float Box 重叠(清浮动);
(6)计算 BFC 的高度时,浮动元素也参与计算。
CSS 在什么情况下会创建出 BFC?
0、根元素,即 HTML 元素(最大的一个 BFC)
1、浮动(float 的值不为 none)
2、绝对定位元素(position 的值为 absolute 或 fixed)
3、行内块(display 为 inline-block)
4、表格单元(display 为 table、table-cell、table-caption、inline-block 等 HTML 表格相关的属性)
5、弹性盒(display 为 flex 或 inline-flex)
6、默认值。内容不会被修剪,会呈现在元素框之外(overflow 不为 visible)
样式优先级:
!important
内联
1000id 选择器 #content
100类选择器(伪类和属性选择器) .content
10类型选择器和伪元素选择器 div p
1通配符(*)、子选择器(>)、相邻选择器(+) 0
继承的样式没有权值
盒子塌陷
本应该在父盒子内部的元素跑到了外部。
当父元素没设置足够大小的时候,而子元素设置了浮动的属性,子元素就会跳出父元素的边界(脱离文档流),尤其是当父元素的高度为 auto 时,而父元素中又没有其它非浮动的可见元素时,父盒子的高度就会直接塌陷为零, 我们称这是CSS 高度塌陷。
解决盒子塌陷的方法:
1、设置盒子的宽高
2、给外部的父盒子也添加浮动,让其脱离标准文档流
3、父盒子添加 overflow 属性
4、父盒子最下方引入清除浮动块 clear:both
5、after 伪元素清除浮动
6、父盒子添加 border
7、父盒子设置 padding-top
伪类和伪元素的区别
伪类:
- 其核⼼就是⽤来选择 DOM 树之外的信息,不能够被普通选择器选择的⽂档之外的元素,⽤来添加⼀些选择器的特殊效果。
- ⽐如:hover :active :visited :link :visited :first-child :focus :lang 等
- 由于状态的变化是⾮静态的,所以元素达到⼀个特定状态时,它可能得到⼀个伪类的样式;当状态改变时,它⼜会失去这个样式。
- 由此可以看出,它的功能和 class 有些类似,但它是基于⽂档之外的抽象,所以叫 伪类。
伪元素:
- DOM 树没有定义的虚拟元素
- 核⼼就是需要创建通常不存在于⽂档中的元素,
- ⽐如::before ::after 它选择的是元素指定内容,表示选择元素内容的之前内容或之后内容。
- 伪元素控制的内容和元素是没有差别的,但是它本身只是基于元素的抽象,并不存在于⽂档中,所以称为伪元素。⽤于将特殊的效果添加到某些选择器
总结:
- 伪类和伪元素都是⽤来表示⽂档树以外的”元素”。
- 伪类和伪元素分别⽤单冒号:和双冒号::来表示。
- 伪类和伪元素的区别,关键点在于如果没有伪元素(或伪类),
- 是否需要添加元素才能达到效果,如果是则是伪元素,反之则是伪类
- 伪类和伪元素都不出现在源⽂件和 DOM 树中。也就是说在 html 源⽂件中是看不到伪类和伪元素的。
- 伪类其实就是基于普通 DOM 元素⽽产⽣的不同状态,他是 DOM 元素的某⼀特征。
- 伪元素能够创建在 DOM 树中不存在的抽象对象,⽽且这些抽象对象是能够访问到的。
行内元素的 margin padding
- 水平方向:水平方向上,都有效;
- 垂直方向:垂直方向上,都无效;(padding-top 和 padding-bottom 会显示出效果,但是高度不会撑开,不会对周围元素有影响)
min-height 和 max-height min-width 和 max-width
- max-width 会覆盖 width,即使 width 是行内样式或者设置了 !important。
- min-width 会覆盖 max-width,此规则发生在 min-width 和 max-width 冲突的时候;
布局:
未知高度元素垂直居中、垂直居中的实现方式有哪些?
1、绝对定位+css3 transform:translate(-50%,50%)
1 |
|
2、css 的 flex 布局
1 |
|
3、table 布局
1 |
|
图片垂直居中的方法
1 |
|
rem 适配
1 |
|
清除浮动的方法:
1、clear:both 添加了无意义的标 签,结构化比较差
2、overflow:hidden 内容增多的时候不会自动换行导致内容被隐藏掉,无法显示出要溢出的元素。
3、伪元素:after 伪元素清除浮动
1 |
|
4、after 伪元素空余字符法
1 |
|
5、使用 before 和 after 双伪元素清除浮动
1 |
|
px:绝对长度单位
em:相对长度单位 值不固定,继承父元素的字体大小 相对父元素的大小
rem:相对长度单位 相对于根元素换算