首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使工具提示拉伸以适合文本(没有预定义的宽度)

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

Stack Overflow用户
提问于 2017-11-29 17:51:59
回答 1查看 1.9K关注 0票数 2

因此,我有一个工具提示,我希望它伸展,以适应所有的文本在其中。我实际上有大约30个工具提示,我不想手动修改它们(我试过了,但它没有工作,所以我不知道我会怎么做)。这是我的代码:

代码语言:javascript
复制
.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;
}
代码语言:javascript
复制
<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>

因此,正如您所看到的(在整个页面的结果上最好的结果),当您悬停在i上时,它显示了一个关于它的小工具提示。这是可行的,但您会注意到,文本的两边都有很多空白。这是因为当我制作它的时候,800px of width在工具提示上工作。既然我有30个工具提示,我怎么能得到它,使它的宽度大约延伸到适合文本?

编辑:--在这个特定的框中,如果去掉宽度,工具提示看起来并不坏(除了移动)。我用我本来想要的另一个程序代替了这个程序。

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

EN

回答 1

Stack Overflow用户

发布于 2017-11-29 17:58:59

span.tooltips span的宽度取出来。跨度将调整到内容。我还添加了一些右和左填充到那个类,使它看起来更整洁。

代码语言:javascript
复制
.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;
}
代码语言:javascript
复制
<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>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47558832

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档