@@ -2456,6 +2456,80 @@ Generating a Random Numeric Value: the ''random()'' function</h3>
24562456 <pre class=prod>
24572457 <random()> = random( <<random-key>> ? , <<calc-sum>> , <<calc-sum>> , <<calc-sum>> ? )
24582458 </pre>
2459+
2460+ <div class=example>
2461+ Imagine you have several ''.box'' elements,
2462+ all styled with the following CSS:
2463+
2464+ <pre highlight=css>
2465+ .box {
2466+ width: random(???, 100px, 200px);
2467+ height: random(???, 100px, 200px);
2468+ border: thin solid;
2469+ }
2470+ </pre>
2471+
2472+ Depending on what <<random-key>> you provide
2473+ in place of the ''???'' ,
2474+ you'll get significantly different behavior for the elements:
2475+
2476+ : ''auto'' /omitted, <b> maximum random</b> : <span class="box-example auto"><b></b><b></b><b></b><b></b></span>
2477+ ::
2478+ Each property gets a different value,
2479+ and it's different per element too,
2480+ so you get a bunch of <strong> different</strong> random <strong> rectangles</strong> .
2481+
2482+ : ''--foo'' , <b> shared by name</b> : <span class="box-example name"><b></b><b></b><b></b><b></b></span>
2483+ ::
2484+ Both properties use the same value,
2485+ and every element shares that value,
2486+ so you get a bunch of <strong> identical</strong> random <strong> squares</strong> .
2487+
2488+ : ''element-scoped'' , <b> scoped per element</b> : <span class="box-example element-scoped"><b></b><b></b><b></b><b></b></span>
2489+ ::
2490+ Both properties use the same value,
2491+ but each element gets a different value,
2492+ so you get a bunch of <strong> different</strong> random <strong> squares</strong> .
2493+
2494+ : ''property-scoped'' , <b> scoped per property</b> : <span class="box-example property-scoped"><b></b><b></b><b></b><b></b></span>
2495+ ::
2496+ Each property gets a different value,
2497+ but each element shares that value,
2498+ so you get a bunch of <strong> identical</strong> random <strong> rectangles</strong> .
2499+
2500+ <style>
2501+ .box-example {
2502+ white-space: pre;
2503+ > b {
2504+ border: 2px solid;
2505+ display: inline-block;
2506+ margin: 0 .2em;
2507+ }
2508+ &.name > b {
2509+ aspect-ratio: 1/1;
2510+ width: .5em;
2511+ }
2512+ &.auto > b {
2513+ &:nth-child(1) { aspect-ratio: 3/1; height: .5em;}
2514+ &:nth-child(2) { aspect-ratio: 1/2; width: .5em;}
2515+ &:nth-child(3) { aspect-ratio: 3/2; height: .5em;}
2516+ &:nth-child(4) { aspect-ratio: 1/3; width: .5em;}
2517+ }
2518+ &.element-scoped > b {
2519+ aspect-ratio: 1;
2520+ &:nth-child(1) { width: .5em;}
2521+ &:nth-child(2) { width: .2em;}
2522+ &:nth-child(3) { width: .8em;}
2523+ &:nth-child(4) { width: .4em;}
2524+ }
2525+ &.property-scoped > b {
2526+ aspect-ratio: 2/1;
2527+ height: .5em;
2528+ }
2529+ }
2530+ </style>
2531+ </div>
2532+
24592533
24602534 See [[#random-evaluation]] and [[#random-caching]]
24612535 for details on how the function is evaluated.
@@ -2856,79 +2930,6 @@ Sharing (Or Not) Random Values: the <<random-key>> value</h3>
28562930 but otherwise will never show up in an element's styles.
28572931 </dl>
28582932
2859- <div class=example>
2860- Imagine you have several ''.box'' elements,
2861- all styled with the following CSS:
2862-
2863- <pre highlight=css>
2864- .box {
2865- width: random(???, 100px, 200px);
2866- height: random(???, 100px, 200px);
2867- border: thin solid;
2868- }
2869- </pre>
2870-
2871- Depending on what <<random-key>> you provide
2872- in place of the ''???'' ,
2873- you'll get significantly different behavior for the elements:
2874-
2875- : ''auto'' /omitted, <b> maximum random</b> : <span class="box-example auto"><b></b><b></b><b></b><b></b></span>
2876- ::
2877- Each property gets a different value,
2878- and it's different per element too,
2879- so you get a bunch of <strong> different</strong> random <strong> rectangles</strong> .
2880-
2881- : ''--foo'' , <b> shared by name</b> : <span class="box-example name"><b></b><b></b><b></b><b></b></span>
2882- ::
2883- Both properties use the same value,
2884- and every element shares that value,
2885- so you get a bunch of <strong> identical</strong> random <strong> squares</strong> .
2886-
2887- : ''element-scoped'' , <b> scoped per element</b> : <span class="box-example element-scoped"><b></b><b></b><b></b><b></b></span>
2888- ::
2889- Both properties use the same value,
2890- but each element gets a different value,
2891- so you get a bunch of <strong> different</strong> random <strong> squares</strong> .
2892-
2893- : ''property-scoped'' , <b> scoped per property</b> : <span class="box-example property-scoped"><b></b><b></b><b></b><b></b></span>
2894- ::
2895- Each property gets a different value,
2896- but each element shares that value,
2897- so you get a bunch of <strong> identical</strong> random <strong> rectangles</strong> .
2898-
2899- <style>
2900- .box-example {
2901- white-space: pre;
2902- > b {
2903- border: 2px solid;
2904- display: inline-block;
2905- margin: 0 .2em;
2906- }
2907- &.name > b {
2908- aspect-ratio: 1/1;
2909- width: .5em;
2910- }
2911- &.auto > b {
2912- &:nth-child(1) { aspect-ratio: 3/1; height: .5em;}
2913- &:nth-child(2) { aspect-ratio: 1/2; width: .5em;}
2914- &:nth-child(3) { aspect-ratio: 3/2; height: .5em;}
2915- &:nth-child(4) { aspect-ratio: 1/3; width: .5em;}
2916- }
2917- &.element-scoped > b {
2918- aspect-ratio: 1;
2919- &:nth-child(1) { width: .5em;}
2920- &:nth-child(2) { width: .2em;}
2921- &:nth-child(3) { width: .8em;}
2922- &:nth-child(4) { width: .4em;}
2923- }
2924- &.property-scoped > b {
2925- aspect-ratio: 2/1;
2926- height: .5em;
2927- }
2928- }
2929- </style>
2930- </div>
2931-
29322933 <div class=example>
29332934 Note that only the [=random cache name=]
29342935 controls whether two [=random functions=] have the same value or not;
0 commit comments