block
要素内に要素を配置inline-block
すると、インライン ブロックはその中の最も幅の広いブロックに合わせて拡張されます。
<h1>Original Structure</h1>
<div id="latest-text1">
<p id="text-wrapper1">
<span style="display: inline-block;" id="title1">ABFDFDFJEKJRKEREJRKE</span>
<span style="display: inline-block;" id="subtitle1">GJKJGKEJKEJFKAJKEJRE</span>
</p>
</div>
<h1>Same, but using <code>block</code></h1>
<div id="latest-text2">
<p id="text-wrapper2">
<span style="display: block;" id="title2">ABFDF DFJEKJ RKER EJRKE</span>
<span style="display: block;" id="subtitle2">GJKJ GKEJKEJF KAJKEJRE</span>
</p>
</div>
<h1>Restructured as HTML5</h1>
<p>This also gets rid of inline styles, which are a leading cause of nightmares.</p>
<section id="latest-text3">
<header>
<hgroup>
<h1>ABFDF DFJEKJ RKER EJRKE</h1>
<h2>GJKJ GKEJKEJF KAJKEJRE</h2>
</hgroup>
</header>
<article>
<p> ... the ... first ... paragraph ... </p>
<p> ... the ... second ... paragraph ... </p>
</article>
</section>
は<hgroup>
厳密には必要ではありませんが、最もセマンティックな意味を持ちます。
そして、CSS
#latest-text1, #latest-text2, section#latest-text3 {
margin: 1em;
padding: 1em;
border: 1px solid black;
}
#latest-text1 {
background-color: #f0f0ff;
}
#latest-text2 {
background-color: #f0fff0;
}
section#latest-text3 {
background-color: #fff0f0;
}
#latest-text3 {
display: inline-block; /* THE IMPORTANT ONE */
}
その CSS のほとんどは、 http://jsfiddle.net/J3NzC/で全体を視覚化するのに役立ちます。
<div>
HTML5 は、適切なクラスで使用することにより<div class="section">
、HTML4 としてやり直すことができます。<div class="hgroup">