私はHTMLを持っています:
<header class="title">
<h1>Title</h1>
<a href="#" class="back">Back</a>
</header>
そしてCSS:
.title {
height: 36px;
line-height: 36px;
position: relative;
overflow: hidden;
background-color: #eee;
margin-bottom: 30px;
}
.back {
position: absolute;
top: 0;
left: 0;
margin: 0 15px;
height: 36px;
line-height: 36px;
width: 42px;
overflow: hidden;
background-color: #ccc;
}
.title h1 {
margin: 0;
font-size: 24px;
text-align: center;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
http://jsfiddle.net/EZwaQ/をご覧ください:)
(1)テキストが短いときは中央揃えにしたいが、(2)長すぎるときは左側の戻るボタンを覆わないようにしたい。
その jsfiddle でわかるようmargin-left
に、2 番目の例で a を追加しました。
それにアプローチする普遍的なCSSの方法はありますか?