固定幅のヘッダー タグがあり、場合によっては 2 行、場合によっては 1 行のテキストが含まれます。これ。
マークアップを変更せずにこれを達成したいと考えています。
<h1>This would be 2 lines of text</h1>
<h1>This is 1 line</h1>
<h1>This would be 2 lines of text</h1>
<h1>This is 1 line</h1>
<h1>This would be 2 lines of text</h1>
<h1>This is 1 line</h1>
<h1>This would be 2 lines of text</h1>
<h1>This is 1 line</h1>
CSS:
h1 {
float:left;
margin:5px;
padding:5px;
width:100px;
height:50px;
vertical-align:middle; /*obvi doesn't work because it's not an inline element */
text-align:center;
background:#336699;
color:#fff;
}
多分...自動高さに基づいて2つの異なるパディングプロパティを決定するCSSセレクターのように? 同様に、高さを auto に設定し、ヘッダー タグが 60px (2 行の場合) を超える場合は、パディングをthisにしますが、自動高さがそれより小さい場合は、パディングをthisにします。 ..
h1[height>60px] { padding:10px 0px; }
h1[height<60px] { padding:20px 0px; }
それが理にかなっていることを願っています。私はそれを書く方法がわからない...またはより良い方法はありますか?
例を参照してください。
どうもありがとう