你是正確的,這是行不通
這裏的,如果你被允許使用BR標記,有效的解決方案我已經提示合作很多次,這是我的最佳解決方案。
Codepen: https://codepen.io/btn-ninja/pen/JNJrgp
它的工作原理是利用空白NOWRAP使用CSS轉換:
<button type="button" class="btn btn-block hasTooltip">
Tooltip on top
<i class="tip">Most tooltips are short<br>but you can add line breaks.</i>
</button>
<button type="button" class="btn btn-block hasTooltip right">
Tooltip on the right.
<i class="tip">Tooltip on right<br>vertically centered.</i>
</button>
.hasTooltip .tip {
position: absolute;
bottom: 100%; left: 50%;
transform: translateX(-50%); }
.hasTooltip.right .tip {
bottom: auto; left: 100%; top:50%;
transform: translateY(-50%); }
翻譯允許絕對定位的工具提示水平或垂直居中對內容。帶有BR的空白空間實現了長內容的包裝,同時允許較短的工具提示與工具提示文本的寬度相匹配。
下面是完整的CSS:
.hasTooltip {
position:relative; }
.hasTooltip .tip {
display:block;
background: #333; color: #fff;
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
font-size:inherit;
font-style:normal;
line-height: 1rem;
text-align:center;
padding: 8px 16px;
border-radius:4px;
margin-bottom:5px;
pointer-events: none;
position: absolute;
bottom: 100%; left: 50%; transform: translateX(-50%);
opacity: 0;
transition: opacity .34s ease-in-out;
white-space:nowrap;
z-index:99; }
.hasTooltip .tip:before {
content: "";
display:block; position:absolute; left:0; bottom:-5px;
width:100%; height:5px; }
.hasTooltip .tip:after {
border-left: solid transparent 6px;
border-right: solid transparent 6px;
border-top: solid #333 6px;
bottom: -4px;
content: "";
height: 0;
left: 50%;
margin-left: -6px;
position: absolute;
width: 0; }
.hasTooltip:focus .tip,
.hasTooltip:hover .tip {
opacity: 1;
pointer-events: auto; }
.hasTooltip.right .tip {
bottom: auto; left: 100%; top:50%; transform: translateY(-50%);
margin-bottom:0;
margin-left:5px; }
.hasTooltip.right .tip:before {
left:-5px; bottom:auto; }
.hasTooltip.right .tip:after {
border-left: 0;
border-top: solid transparent 6px;
border-bottom: solid transparent 6px;
border-right: solid #333 6px;
bottom:auto;
left: -4px;
top:50%;
margin-left: 0;
margin-top: -6px; }
你能告訴我們任何代碼指定的值?也許你試圖解決這個問題的代碼?會有幫助 –
@OvidiuUnguru因爲它的CSS我不明白的互動,我不知道我可以告訴你顯示我試圖「修復」它......如我所描述的,我嘗試了一些不同的屬性,但沒有一個獲得理想的效果。我發佈了基本代碼,但沒有給出相同的代碼3次,它們之間有一個屬性差異,不知道要提供什麼。 – RhoVisions
https://codepen.io/anon/pen/yodpao看到這個,如果這確實能解決你的問題 –