gpt4 book ai didi

html - 如何使工具提示拉伸(stretch)以适合文本(没有预定义的宽度)

转载 作者:行者123 更新时间:2023-11-28 11:59:56 25 4
gpt4 key购买 nike

所以,我有一个工具提示,我希望它可以拉伸(stretch)以适合其中的所有文本。我实际上有大约 30 个工具提示,我不想手动更改它们(我试过了但没有用,所以我不确定我会怎么做)。这是我的代码:

.programButton {
width: 1000px;
height: 100px;
background: #EAEAEA;
border: 1px solid black;
text-align: left;
}
#programButtonText, .programButtonExtra {
font-family: 'Open Sans', sans-serif;
font-size: 34px;
margin-left: 8px;
}
.extraBox {
width: 180px;
background: white;
border: 2px solid #999999;
top: -55px;
left: 380px;
margin-bottom: -92px;
/*margin-top: -80px;
margin-left: 1000px;*/
position: relative;
display: block;
}
.extraBox1 {
font-family: 'Open Sans', sans-serif;
font-size: 25px;
color: #47BC47;
background: white;
margin: 5px;
margin-bottom: 10px;
}
.extraBox1:hover {
cursor: pointer;
background: #47BC47;
color: white;
}
.extraBox2:hover {
cursor: pointer;
background: #D41B1B;
color: white;
}
.extraBox2 {
font-family: 'Open Sans', sans-serif;
font-size: 25px;
color: #D41B1B;
background: white;
margin: 5px;
margin-top: 0px;
}
#programButtonText {
line-height: 65px;
}
.hoverText {
cursor: pointer;
}
.lastVisited {
font-family: 'Open Sans', sans-serif;
font-size: 22px;
margin-top: -35px;
margin-left: -793px;
}
.entireProgramButton {
display: block;
cursor: default;
}
.programButtonExtra {
margin-top: -41px;
margin-left: 980px;
}
span.tooltips {
position: relative;
display: inline;
}
span.tooltips span {
font-family: 'Open Sans', sans-serif;
font-size: 22px;
position: absolute;
color: #FFFFFF;
background: #000000;
height: 40px;
line-height: 40px;
text-align: center;
display: none;
visibility: hidden;
border-radius: 9px;
}
span.tooltips span:after {
content: '';
position: absolute;
top: 100%;
left: 50%;
width: 0; height: 0;
border-top: 8px solid #000000;
border-right: 8px solid transparent;
border-left: 8px solid transparent;
}
span:hover.tooltips span {
visibility: visible;
display: block;
opacity: 1;
bottom: 30px;
right: -378px;
top: -35px;
margin-left: -76px;
}
<br><br><br>
<center>
<div id = "entireProgramButton9" class = "entireProgramButton">
<div id = "programButton9" class = "programButton"><div id = "programButtonText"><span id = "programName9" class = "hoverText">Tic-Tac-Toe&nbsp;<span class = "tooltips" id = "information">ⓘ<span>The Tic-Tac-Toe game lets you play against AI or another player.</span></span></span></div><div class = "programButtonExtra" id = "programButtonExtra9"><span class = "hoverText">⋮</span></div></div>
<div class = "lastVisited">Last visited: Never</div>
<div class = "extraBox" id = "extraBox9">
<div id = "extraBox19" class = "extraBox1">Save for later</div>
<div id = "extraBox29" class = "extraBox2">Report a bug</div>
</div>
</div>
</center>

因此,如您所见(整页结果中的最佳结果),当您将鼠标悬停在 ⓘ 上时,它会显示一个小工具提示,告诉您相关信息。这行得通,但您会注意到文本两边有很多空白区域。这是因为当我制作它时,width800px 在工具提示上起作用。由于我有大约 30 个工具提示,我怎样才能让它的宽度大约拉伸(stretch)以适合文本?

编辑:事实证明,在这个特定的框上,如果去掉宽度,工具提示看起来还不错(除了移动之外)。我用另一个我想要的程序替换了该程序。

我还拿出了宽度来告诉你没有它会发生什么。

最佳答案

只需从 span.tooltips span 中取出宽度。跨度将根据内容调整大小。我还向该类添加了一些左右填充,使其看起来更整洁。

.programButton {
width: 1000px;
height: 100px;
background: #EAEAEA;
border: 1px solid black;
text-align: left;
}
#programButtonText, .programButtonExtra {
font-family: 'Open Sans', sans-serif;
font-size: 34px;
margin-left: 8px;
}
.extraBox {
width: 180px;
background: white;
border: 2px solid #999999;
top: -55px;
left: 380px;
margin-bottom: -92px;
/*margin-top: -80px;
margin-left: 1000px;*/
position: relative;
display: block;
}
.extraBox1 {
font-family: 'Open Sans', sans-serif;
font-size: 25px;
color: #47BC47;
background: white;
margin: 5px;
margin-bottom: 10px;
}
.extraBox1:hover {
cursor: pointer;
background: #47BC47;
color: white;
}
.extraBox2:hover {
cursor: pointer;
background: #D41B1B;
color: white;
}
.extraBox2 {
font-family: 'Open Sans', sans-serif;
font-size: 25px;
color: #D41B1B;
background: white;
margin: 5px;
margin-top: 0px;
}
#programButtonText {
line-height: 65px;
}
.hoverText {
cursor: pointer;
}
.lastVisited {
font-family: 'Open Sans', sans-serif;
font-size: 22px;
margin-top: -35px;
margin-left: -793px;
}
.entireProgramButton {
display: block;
cursor: default;
}
.programButtonExtra {
margin-top: -41px;
margin-left: 980px;
}
span.tooltips {
position: relative;
display: inline;
}
span.tooltips span {
font-family: 'Open Sans', sans-serif;
font-size: 22px;
position: absolute;
color: #FFFFFF;
background: #000000;
height: 40px;
line-height: 40px;
text-align: center;
display: none;
visibility: hidden;
border-radius: 9px;
padding-left:15px;
padding-right:15px;
}
span.tooltips span:after {
content: '';
position: absolute;
top: 100%;
left: 50%;
width: 0; height: 0;
border-top: 8px solid #000000;
border-right: 8px solid transparent;
border-left: 8px solid transparent;
}
span:hover.tooltips span {
visibility: visible;
display: block;
opacity: 1;
bottom: 30px;
right: -378px;
top: -35px;
margin-left: -76px;
}
<br><br><br>
<center>
<div id = "entireProgramButton19" class = "entireProgramButton">
<div id = "programButton19" class = "programButton"><div id = "programButtonText"><span id = "programName19" class = "hoverText">Clock&nbsp;<span class = "tooltips" id = "information">ⓘ<span>The Clock program tries to get the time.</span></span></span></div><div class = "programButtonExtra" id = "programButtonExtra9a"><span class = "hoverText">⋮</span></div></div>
<div class = "lastVisited">Last visited: Never</div>
<div class = "extraBox" id = "extraBox9a">
<div id = "extraBox119" class = "extraBox1">Save for later</div>
<div id = "extraBox219" class = "extraBox2">Report a bug</div>
</div>
</div>
</center>

关于html - 如何使工具提示拉伸(stretch)以适合文本(没有预定义的宽度),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47558832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com