2016-11-07 5 views
0

私は次のようにスパンに取り付けたCSSのツールチップを持っている:擬似クラスの最大幅は?

<span class="mytooltip" data-mytooltip="Text here. Text here. Text here. Text here. Text here. Text here. Text here. Text here. Text here. "> 
    Has Tooltip 
</span> 

CSSは短いです:予想通り.mytooltip:hover:after{} width: 400pxmax-width: 400px; white-space: nowrap; 作品で

.mytooltip { 
    display: inline-block; 
    position: relative; 
} 
.mytooltip:hover:after { 
    content: attr(data-mytooltip); 
    display: block; 
    margin-top: 0.7rem; 
    margin-left: -1rem; 
    left: auto; 
    bottom: auto; 
    padding: .3rem 1rem; 
    position: absolute; 
    z-index: 98; 
    width: 400px; 
} 

。後者はあまり意味がありません。擬似要素は正しい幅を持っていますが、テキストは400pxよりも長いときに浮いているためです。 テキストが内部にラップされた疑似要素でmax-widthを使用する方法はありますか?

私はアドバイスに非常に感謝しています。

答えて

0

最後に、私は唯一のツールヒントのテキストは終わり、最大幅よりも長く、私ができる時に手動で

.mytooltip { 
 
    display: inline-block; 
 
    position: relative; 
 
    margin:15px; 
 
    border: 1px solid red; 
 
    overflow:visible; 
 
} 
 

 
.mytooltip:hover:after { 
 
    content: attr(data-mytooltip); 
 
    display: table-cell; 
 
    margin-top: 0.7rem; 
 
    margin-left: -1rem; 
 
    left: auto; 
 
    bottom: auto; 
 
    padding: .3rem 1rem; 
 
    position: absolute; 
 
    z-index: 98; 
 
    max-width: 400px; 
 
    white-space:pre; 
 
    border: 1px solid #000; 
 
    overflow:hidden; 
 
}
<span class="mytooltip" data-mytooltip="Text here. Text here. &#xa;Text here. Text here. Text here. &#xa;Text here. Text here. Text here. Text here. "> 
 
    Has Tooltip 
 
</span>
テキストがで切断されたChromeの

+0

...ラップすることをお勧めすることができますそれを表示しないでください。それは目標ではありませんでした。テキスト全体が表示される解決策がありますか? – Anja

+0

これは複数行になっていますので、スニペットをもう一度チェックしてくださいplz –

+0

これは、相対位置を設定しているために機能しますが、ツールチップがそのフィールド内のフィールドを伸ばしてはいけません。私は幅を試しました:要素上のauto、何が良いアイデアのように聞こえましたが、残念ながら、max-widthはあなたのデータと位置を持つ擬似要素では認識されません:absolute。 – Anja