CKTIS / CSS
anchor-size() — velikost sidrnega polja
`anchor-size()` za odvisni absolutno pozicionirani element izračuna dolžino iz dejanske mere sidrnega polja.
Različica: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaksa
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )anchor-size() za odvisni absolutno pozicionirani element izračuna dolžino iz dejanske mere sidrnega polja.
Primer panelu določi širino anchor-size(--card width) in polovico anchor-size(--card height); meritev potrdi panel velikosti 120 krat 20 slikovnih pik, poravnan pod sidrom 120 krat 40.
Slovnica: anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? ).
width in height bereta fizične mere; block in inline preslikata osi po načinu pisanja vsebujočega bloka, self-block in self-inline pa po lastnem načinu pisanja elementa, ki poizveduje. Izpuščena mera uporabi os lastnosti. Brez razrešljivega sidra se uporabi nadomestna dolžina; brez nje je deklaracija ob izračunu neveljavna.
Primeri
const stage=document.createElement('div'),card=document.createElement('div'),panel=document.createElement('div');document.body.append(stage);stage.append(card,panel);stage.style.cssText='position:relative;width:320px;height:180px';card.style.cssText='position:absolute;left:30px;top:20px;width:120px;height:40px;anchor-name:--card';panel.style.cssText='position:absolute;position-anchor:--card;left:anchor(--card left);top:anchor(--card bottom);width:anchor-size(--card width);height:calc(anchor-size(--card height)/2)';const a=card.getBoundingClientRect(),b=panel.getBoundingClientRect(),s=getComputedStyle(panel);const aligned=Math.round(b.left-a.left)===0&&Math.round(b.top-a.bottom)===0;if(!aligned||Math.round(b.width)!==120||Math.round(b.height)!==20)throw new Error('anchor-size relationship did not resolve');console.log('size='+Math.round(b.width)+'x'+Math.round(b.height)+'; aligned='+aligned+'; computed='+s.width+','+s.height);Rezultat
size=120x20; aligned=true; computed=120px,20px
`anchor-size()` za odvisni absolutno pozicionirani element izračuna dolžino iz dejanske mere sidrnega polja.