053-background-shorthand.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>053 background shorthand position and size</title>
  6. <style>
  7. body { background: #ffffff; color: #202020; font-family: sans-serif;
  8. margin: 12px; font-size: 18px; }
  9. .tile { width: 220px; height: 130px; border: 2px solid #202020;
  10. margin: 8px 0; }
  11. #a { background: #ffffff url(TILE.PNG) center/cover no-repeat; }
  12. #b { background: url(TILE.PNG) left top/50px 30px no-repeat; }
  13. #c { background: #204080 url(TILE.PNG) no-repeat right bottom / 100% 50%; }
  14. </style>
  15. </head>
  16. <body>
  17. <h1>053 &mdash; background shorthand</h1>
  18. <p>The position before the slash and the size after it must both survive the
  19. shorthand parser. The image is <code>TILE.PNG</code>.</p>
  20. <div id="a" class="tile"></div>
  21. <div id="b" class="tile"></div>
  22. <div id="c" class="tile"></div>
  23. <div id="result" style="background: #c8f0c8; color: #000000; padding: 8px;
  24. font-size: 18px;">checking...</div>
  25. <script>
  26. setTimeout(function () {
  27. function P(id) { return getComputedStyle(document.getElementById(id)).backgroundPosition; }
  28. function S(id) { return getComputedStyle(document.getElementById(id)).backgroundSize; }
  29. var a = P('a') + ' / ' + S('a');
  30. var b = P('b') + ' / ' + S('b');
  31. var c = P('c') + ' / ' + S('c');
  32. var ok = a === '50% 50% / cover' &&
  33. b === '0% 0% / 50px 30px' &&
  34. c === '100% 100% / 100% 50%';
  35. var r = document.getElementById('result');
  36. if (r) {
  37. r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
  38. r.textContent = (ok ? 'BACKGROUND-OK ' : 'BACKGROUND-FAIL ') +
  39. 'a[' + a + '] b[' + b + '] c[' + c + ']';
  40. }
  41. }, 300);
  42. </script>
  43. </body>
  44. </html>