2011-10-03 15 views
18

私はdivでテーブルレイアウトをシミュレートしており、その中にいくつかのスパンがあります。私はラップするテキストをインデントするために、右側のスパンを望みます。私はいくつかのことを試しましたが、それを働かせることはできません。どんな助けもありがとう。<span>インデントがラップされたテキスト

jsFiddle:http://jsfiddle.net/2Wbuv/

HTML

<div class="display-element"> 
    <span class="display-label">Field 1</span> 
    <span class="display-field">This is my string of data, some times it is pretty long. Sometimes it is not. This one is.</span> 
</div> 
<div class="display-element"> 
    <span class="display-label">Field 2</span> 
    <span class="display-field">This is another string of data.</span> 
</div> 

CSS

.display-element  {} 

.display-label   {display: inline-block; 
         width: 100px; 
         padding-left: 5px;} 

.display-field   {display: inline;} 
+6

なぜ 'display:table-cell'を使わないのですか? – sdleihssirhc

+0

うん、天才...私はそれを前に使ったことがないし、今なぜ私は考えていない。私はあなたにポイントを与えることができるように答えてください。 –

+0

ああ、今は100%幅にすることはできません...それでもやっています。 –

答えて

22

はこれをチェックしてください:http://jsfiddle.net/2Wbuv/2/

.display-element { 
 
} 
 

 
.display-label { 
 
    display: inline-block; 
 
    width: 100px; 
 
    padding-left: 5px; 
 
} 
 

 
.display-field { 
 
    display: inline-block; 
 
    padding-left: 50px; 
 
    text-indent: -50px; 
 
    vertical-align: top; 
 
    width: 200px; /* for testing purposes only */ 
 
}
<div class="display-element"> 
 
    <span class="display-label">Field 1</span> 
 
    <span class="display-field">This is my string of data, some times it is pretty long. Sometimes it is not. This one is.</span> 
 
</div> 
 
<div class="display-element"> 
 
    <span class="display-label">Field 2</span> 
 
    <span class="display-field">This is another string of data.</span> 
 
</div>

+0

これは、両方のインラインブロックを作成することで、次の行に最初の行を配置するという問題です。幅300ピクセル以下のウィンドウ)。 –

+0

'.display-field'に固定幅を指定しない場合は、スパン要素であるためインラインからインラインブロックへの切り替えが必要です。非クロスブラウザを使用してテーブルセルをエミュレートする必要があります互換性のある 'display:table-cell'です。代わりに、これは私が行く方法です、実際のテーブルを使用します。 – simshaun

8

ぶら下げしたいように聞こえます。このようなCSSの何かがトリックを行う必要があります。

.hanging-indent 
{ 
    text-indent : -3em ; 
    margin-left : 3em ; 
} 

をしかし、あなたの<span>は、インライン要素、テキストインデントプロパティだけでなく、ブロックに関連する他のCSSプロパティであるため、無意味です。

2

CSS 3 draft specifies a hanging indent。ブラウザでサポートされている場合は、以下の作業をする必要があります:CSS Text Module Level 3の仕様は、まだドラフトであるよう

.hanging-indent 
{ 
    text-indent: 3em hanging each-line; 
} 

は、残念ながらどちらもhangingeach-line値がcurrently supported in modern browsersです。

この機能は、WebKitChromiumのブラウザ固有のプレフィックスで実装されています。 Firefox there is an open Bug you may vote onの場合。

関連する問題