inline_formatting_06.rml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <rml>
  2. <head>
  3. <title>Inline formatting 06</title>
  4. <link type="text/rcss" href="../style.rcss"/>
  5. <link rel="help" href="https://drafts.csswg.org/css2/#propdef-vertical-align" />
  6. <meta name="Description" content="Line height with inline-blocks." />
  7. <meta name="Assert" content="The baseline of an inline-block is the baseline of its last line box in the normal flow, unless it has either no in-flow line boxes or if its overflow property has a computed value other than visible, in which case the baseline is the bottom margin edge." />
  8. <style>
  9. p.value {
  10. position: absolute;
  11. margin: 0.4em 0.6em;
  12. top: 0;
  13. right: 0;
  14. color: #45e;
  15. }
  16. .wrapper {
  17. background-color: #eee;
  18. border: 3px #bbb;
  19. padding: 8px;
  20. position: relative;
  21. margin-top: -0.3em;
  22. }
  23. .wrapper > div {
  24. display: inline-block;
  25. background: #fcc;
  26. border: 1px #999;
  27. width: 150px;
  28. line-height: 35px;
  29. text-align: center;
  30. }
  31. .scroll-container > div { overflow: auto; }
  32. .offset-up > div { vertical-align: -12px; }
  33. .vertical-center > div { vertical-align: center; }
  34. </style>
  35. </head>
  36. <body>
  37. <p>Normally, the baseline of an inline-block is set to its last line, nicely aligning with its neighboring text.</p>
  38. <div class="wrapper">
  39. X <div>Start Game</div><br/>
  40. X <div>High Scores</div><br/>
  41. X <div>Options</div>
  42. </div>
  43. <p>However, after making the inline-block a scroll container (such as by setting a non-visible overflow value), it is instead aligned to its bottom edge. Due to the line's text descent, there is additional spacing appearing below the box.</p>
  44. <div class="wrapper scroll-container">
  45. <p class="value">overflow: auto;</p>
  46. X <div>Start Game</div><br/>
  47. X <div>High Scores</div><br/>
  48. X <div>Options</div>
  49. </div>
  50. <p>We can manually adjust the vertical alignment to make sure we remove that additional space. However, it won't perfectly line up the baselines anymore.</p>
  51. <div class="wrapper scroll-container offset-up">
  52. <p class="value">overflow: auto;<br/>vertical-align: -12px;</p>
  53. X <div>Start Game</div><br/>
  54. X <div>High Scores</div><br/>
  55. X <div>Options</div>
  56. </div>
  57. <p>Instead of manually adjusting the vertical alignment, we can use 'center' for perfect centering. Note that baselines will still not line up.</p>
  58. <div class="wrapper scroll-container vertical-center">
  59. <p class="value">overflow: auto;<br/>vertical-align: center;</p>
  60. X <div>Start Game</div><br/>
  61. X <div>High Scores</div><br/>
  62. X <div>Options</div>
  63. </div>
  64. <handle size_target="#document"/>
  65. </body>
  66. </rml>