最近在翻《CSS权威指南》,一些零散的知识点平时不太注意,这里记录一下。css
display指定了元素的显示类型,它包含两类基础特征,用于指定元素怎样生成盒模型——外部显示类型定义了元素怎样参与流式布局的处理,内部显示类型定义了元素内子元素的布局方式。html
<display-outside>(指定了元素的外部显示类型,实际上就是其在流式布局中的角色) = block | inline | run-in
<display-inside> (指定了元素的内部显示类型,它们定义了元素内部内容的格式化上下文的类型)= flow | flow-root | table | flex | grid | ruby
<display-listitem> (元素的外部显示类型变为 block 盒,并将内部显示类型变为多个 list-item inline 盒)= <display-outside>? && [ flow | flow-root ]? && list-item
<display-internal> (用来定义这些“内部”显示类型,只有在特定的布局模型中才有意义)= table-row-group | table-header-group | table-footer-group | table-row | table-cell | table-column-group | table-column | table-caption | ruby-base | ruby-text | ruby-base-container | ruby-text-container
<display-box> (是否彻底生成显示盒)= contents | none
<display-legacy> (CSS 2 对于 display 属性使用单关键字语法)= inline-block | inline-list-item | inline-table | inline-flex | inline-grid
复制代码
<link rel="stylesheet" href="day.css" title="Default Day">
<link rel="alternate stylesheet" href="night.css" title="Night">
复制代码
rel(关系)中能够指定候选样式表,默认使用第一个样式表。恰好看到这篇文章link rel=alternate网站换肤功能最佳实现,本身实现了一下: web
这里的应用在于,若是咱们在开发一个CSS框架或者模式库,定义一个类'btn btn-small btn-arrow btn-active'
显得冗余,咱们能够直接使用'btn-small-arrow-active'
api
<button class="btn-small-arrow-active"></button>
*[class|="btn"][class*="-arrow"]:after {content: '▼'}
复制代码
一个元素可能被两个或多个规则匹配,其中只有一个规则能胜出,特指度可以解决冲突。一个特指度由四部分构成,好比0, 0, 0, 0
浏览器
0, 1, 0, 0
0, 0, 1, 0
0, 0, 0, 1
h1 {} /* 0, 0, 0, 1 */
p em {} /* 0, 0, 0, 2 */
.grape {} /* 0, 0, 1, 0 */
p.bright em.dark {} /* 0, 0, 2, 2 */
li#answer {} /* 0, 1, 0, 1 */
复制代码
!important
重要规则始终胜出el::first-letter {} /*装饰首字母*/
el::first-line {} /*装饰首行*/
el::before {} /*前置内容元素*/
el::after {} /*后置内容元素*/
复制代码
a:link {}
a:visited {}
a:focus {}
a:hover {}
a:active {}
复制代码
可使用样式获取的元素上的HTML属性值(实际兼容浏览器不多),例如:ruby
<!--css-->
p::before {content: "[" attr(id) "]"}
<!--html-->
<p id="leadoff">This is the first paragraph</p>
<!--显示结果-->
[leadoff]This is the first paragraph
复制代码
:root {/* 或者html */
--base-color: #639;
}
h1 {
color: var(--base-color);
}
复制代码
<length>
| <percentage>
<number>
| <length>
| <percentage>
| normal
<length>
| <percentage>
<div class="bg-img">HELLO</div>
<!--css-->
.bg-img {
width: 1500px;
height: 400px;
color: transparent;
font-size: 300px;
background-image: url('bg.jpg');
background-size: contain;
-webkit-background-clip: text;
background-clip: text;
}
复制代码
100% auto
(若是元素高度比宽度大,反之为auto 100%
)未完待续bash