次のHTML(JSFiddle here)では、「このテキストを折り返すのはなぜですか」のテキストは、幅が狭すぎてテキストの一部が切り取られてしまった場合にのみ折り返します。その後、それはラップします。このスパンを正しくラップできないのはなぜですか?
私が必要とする動作は、テキストを1つの項目として折り返して、ワード単位で折り返しを開始するためのテキストではないことに注意してください。実際にはうまくいくことに注意してください。しかし、一度幅が小さくて先の画像なしで折り返された場合にのみ機能します。先頭のイメージを削除すると、正常に動作します。
先の画像を適切な位置に配置して、希望のラッピング動作を得る方法はありますか?
#main-toolbar {
height: 140px;
white-space: nowrap;
overflow:hidden;
width: 100%;
}
#main-toolbar-text{
height: initial;
display:inline-block;
color: #2196f3;
line-height: 70px;
}
.test{
border: solid red 1px;
}
.profile-toolbar-user-wordmark{
display: inline-block;
white-space: normal;
overflow: initial;
}
.profile-toolbar-wordmark{
width: 90px;
}
.profile-toolbar-logoicon{
width: 90px;
}
.profile-toolbar-icon{
display: inline-block;
vertical-align: top;
overflow: visible;
white-space: nowrap;
}
<div id="main-toolbar" class="test" >
<span class="profile-toolbar-icon test"><img class="profile-toolbar-logoicon" src="https://pixy.org/images/placeholder.png"></span>
<span class="profile-toolbar-user-wordmark test">
<span class="profile-toolbar-icon">
<img class="profile-toolbar-wordmark" src="https://pixy.org/images/placeholder.png">
</span>
<span id="main-toolbar-text">
Why won't this text wrap?
</span>
</span>
</div>
良い質問。私はその原因や解決策はわかりませんが、回避策があります:テキストブロック(メインツールバーテキスト)に適切なパディングを与えて、そのコンテナが実際よりも広いと考えるようにし、早くラップします。 94pxで十分です。最初のアイコンの幅+中間のスペースの幅。 https://jsfiddle.net/MrLister/3L3pq5L5/5/ –
'white-space:nowrap;を削除すると、期待通りに折り返されます。 – Stickers
@Panglossこれは 'profile-toolbar-user-wordmark'クラスの要素が 'profile-toolbar-icon'要素の下にくるようにします。私はそれを包むものではありません。私はテキストを 'profile-toolbar-user-wordmark'要素内のイメージの下に折り返して、その要素自身をラップしないでください。 – WillyC