1. 增量规范
这是一个增量规范,意味着目前仅包含与 CSS 锚点定位第1级 [CSS-ANCHOR-POSITION-1] 的不同之处。
2. 锚点定位的容器查询
本节扩展了 容器查询(来自 [css-conditional-5]), 允许通过 锚点定位 查询元素的某些特性。
2.1. 通过 container-type 扩展 anchored
本规范为 container-type 属性(定义见 CSS Conditional 5 § 5.1 创建查询容器:container-type 属性) 增加了一个新的 anchored 关键字。anchored 可以与现有的容器类型一起使用,比如 scroll-state 和 size:
normal | [ [ size | inline-size ] || scroll-state || anchored ]
- anchored
- 建立一个 查询容器 用于 容器查询, 允许锚点定位元素的后代根据锚点的某些特性进行样式化。 (目前仅限于哪些 position-try-fallbacks 被应用。)
#anchored{ container-type : anchored; } #anchored-size{ container-type : anchored inline-size; }
2.2. 扩展 @container 语法以支持 anchored 查询
为了查询 anchored 容器,anchored() 函数被添加到 @container 语法中。它通过在 '<query-in-parens>' 语法中添加如下产生式扩展了容器查询语法:
<query-in-parens> = ...
| anchored( <anchored-query> )
<anchored-query> = not <anchored-in-parens>
| <anchored-in-parens> [ [ and <anchored-in-parens> ]* | [ or <anchored-in-parens> ]* ]
| <anchored-feature>
<anchored-in-parens> = ( <anchored-query> )
| ( <anchored-feature> )
| <general-enclosed>
2.3. 锚定容器特性
2.3.1. 应用的 position-try-fallbacks:fallback 特性
| 名称: | fallback |
|---|---|
| 用于: | @container |
| 值: | none | [ [<dashed-ident> || <try-tactic>] | <position-area-query> ] |
| 类型: | 离散 |
fallback 容器特性查询某个锚点 定位元素是否应用了其计算后的position-try-fallbacks 选项中的任何一个 。
- none
- anchored 容器没有应用任何position-try-fallbacks。
- <dashed-ident> || <try-tactic>
-
anchored 容器匹配由<dashed-ident> 和 <try-tactic> 组成的组合,该组合由position-try-fallbacks 应用。
如果<dashed-ident> 或 <try-tactic> 中任意一个没有包含
在
查询值中,则在position-try-fallbacks
的应用值中也需要省略它,反之亦然,以便
匹配。
该 <dashed-ident> 尝试规则名称不 被视为一个 树作用域名称,用于匹配 fallback。
<try-tactic> 的顺序很重要。例如,
flip-start flip-block与flip-block flip-start不同。 因此,对于 fallback 查询,顺序必须匹配。 - <position-area-query>
-
该 anchored 容器具有一个 <position-area>,应用自 position-try-fallbacks。如果该
从回退项应用的 <position-area> 与该
查询值表示
相同的物理区域,则查询匹配。也就是说,block-start 将匹配 top,当 writing-mode 为 horizontal-tb 时。
查询值 any 对给定轴始终匹配。
#container{ container-type : anchored; position : absolute; position-anchor : --a; position-area : left; position-try-fallbacks : right; &::before{ content : ">" ; } @container anchored ( fallback: right) { &::before{ content : "<" ; }; } }
.anchored{ container-type : anchored; position-try-fallbacks : --foo, --bar flip-inline; @container anchored ( fallback: --bar flip-inline) { /* 当 '--bar' 回退适用时应用 */ .inner{ background-color : green; } } @container anchored ( fallback: --bar) { /* 不适用,因为 try-tactic 也必须匹配 */ .inner{ background-color : red; } } }
.anchored{ container-type : anchored; position-anchor : --a; position-try-fallbacks : right; writing-mode : vertical-rl; @container anchored ( fallback: self-block-start) { /* 如果 'right' 回退适用则应用,因为 block-start 是 'right' 在 'vertical-rl' 中。 */ .inner{ background-color : green; } } }
.anchored{ container-type : anchored; position-anchor : --a; position-try-fallbacks : bottom right; writing-mode : vertical-rl; @container anchored ( fallback: bottom any) { /* 应用,因为 'any' 匹配 'right'。 */ .inner{ color : lime; } } @container anchored ( fallback: right) { /* 应用,因为垂直轴中隐式的 'any' 匹配 'bottom'。 */ .inner{ background-color : green; } } }
2.3.2. <position-area-query>值的语法
用于查询 position-area fallback 的值,语法与 <position-area> 相同, 但每个产生式都额外添加了 any 关键字:
<position-area-query> = [
[ left | center | right | span-left | span-right
| x-start | x-end | span-x-start | span-x-end
| self-x-start | self-x-end | span-self-x-start | span-self-x-end
| span-all | any ]
||
[ top | center | bottom | span-top | span-bottom
| y-start | y-end | span-y-start | span-y-end
| self-y-start | self-y-end | span-self-y-start | span-self-y-end
| span-all | any ]
|
[ block-start | center | block-end | span-block-start | span-block-end | span-all | any ]
||
[ inline-start | center | inline-end | span-inline-start | span-inline-end
| span-all | any ]
|
[ self-block-start | center | self-block-end | span-self-block-start
| span-self-block-end | span-all | any ]
||
[ self-inline-start | center | self-inline-end | span-self-inline-start
| span-self-inline-end | span-all | any ]
|
[ start | center | end | span-start | span-end | span-all | any ]{1,2}
|
[ self-start | center | self-end | span-self-start | span-self-end | span-all | any ]{1,2}
]
- any
-
any 可以用于一个或两个轴。它指代的轴是不明确的,处理方式与 '<position-area>' 里的其他不明确关键字(如 start 或 center)一致,适用于分配轴和复制单关键字值的场景。
- start, end, self-start, self-end
- top, bottom, left, right
- y-start, y-end, self-y-start, self-y-end
- x-start, x-end, self-x-start, self-x-end
- block-start, block-end, self-block-start, self-block-end
- inline-start, inline-end, self-inline-start, self-inline-end
- center
- span-start, span-end, span-self-start, span-self-end
- span-top, span-bottom, span-left, span-right
- span-y-start, span-y-end, span-self-y-start, span-self-y-end
- span-x-start, span-x-end, span-self-x-start, span-self-x-end
- span-block-start, span-block-end, span-self-block-start, span-self-block-end
- span-inline-start, span-inline-end, span-self-inline-start, span-self-inline-end
- span-all
- top, bottom, left, right
-
具体定义见 '<position-area>'。
如果只给出一个关键字,且该关键字没有轴歧义,则 '<position-area-query>' 的行为,就如同第二个关键字为 any。这与 '<position-area>' 处理单关键字不同,后者的第二个关键字为 span-all。 其他情况下,'<position-area-query>' 在分配轴时行为与 '<position-area>' 一致。
3. 安全性注意事项
目前未发现任何安全性问题。
4. 隐私注意事项
目前未发现任何隐私问题。