我可以让span元素忽略列吗?

时间:2017-08-29 21:31:34

标签: html css django tooltip css-multicolumn-layout

我正在创建一个Web应用程序,用户将包含单词/短语的框拖动到某个区域。当用户将鼠标悬停在方框上时,会显示一个工具提示,其中包含单词的定义。当用户将盒子拖入区域时,我希望它们分成两列。但是,使用列时,工具提示会在越过区域边缘时中断。有什么方法可以解决这个问题吗?

How tooltips are at the moment

How I would like them to be

#div1 {
  float: left;
  width: 328px;
  height: 400px;
  margin-left: 4px;
  padding: 10px;
  border: 1px solid black;
  border-radius: 6px;
  background-color: white;
  -webkit-columns: 2;
  -moz-columns: 2;
  columns: 2;
  -moz-column-fill: auto;
  column-fill: auto;
}

.box {
  height: 54px;
  width: 160px;
  text-align: center;
  background-color: white;
  color: purple;
  border: 1px solid black;
  border-radius: 4px;
  margin-bottom: 2px;
  position: relative;
  text-align: center;
}

.tooltiptext {
  visibility: hidden;
  width: 160px;
  background-color: purple;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  top: 100%;
  left: 50%;
  margin-left: -80px;
}

.box:hover .tooltiptext {
  visibility: visible;
}
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">
  {% for c in cards1 %}
  <div id="drag{{c.id}}-{{c.carddata.position}}" class="box" draggable="true" ondragstart="drag(event)">
    <span class="tooltiptext">{{c.carddata.description}}</span>
    <div id="text{{c.id}}-{{c.carddata.position}}" class="text"><br>{{c.carddata.name}}</div>
  </div>
  {% endfor %}
</div>

1 个答案:

答案 0 :(得分:1)

如果您将display的{​​{1}}重置为.box,则不会转到下一列:

inline-block
#div1 {
  float: left;
  width: 328px;
  height: 250px;
  margin-left: 4px;
  padding: 10px;
  border: 1px solid black;
  border-radius: 6px;
  background-color: white;
  -webkit-columns: 2;
  -moz-columns: 2;
  columns: 2;
  -moz-column-fill: auto;
  column-fill: auto;
}

.box {
display:inline-block;/* to keep in a single column */
  height: 54px;
  width: 160px;
  text-align: center;
  background-color: white;
  color: purple;
  border: 1px solid black;
  border-radius: 4px;
  margin-bottom: 2px;
  position: relative;
  text-align: center;
}

.tooltiptext {
  visibility: hidden;
  width: 160px;
  background-color: purple;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  top: 100%;
  left: 50%;
  margin-left: -80px;
}

.box:hover .tooltiptext {
  visibility: visible;
}

由于您使用固定高度,您可能还需要考虑在父

上设置这些规则的flex方法
<div id="div1">
  <div  class="box">
    <span class="tooltiptext">c.carddata.description c.carddata.description c.carddata.description c.carddata.description c.carddata.description</span>
    <div class="text">c.carddata.name<br/>c.carddata.name</div>
  </div>
  <div  class="box">
    <span class="tooltiptext">c.carddata.description c.carddata.description c.carddata.description c.carddata.description c.carddata.description</span>
    <div class="text">c.carddata.name<br/>c.carddata.name</div>
  </div>
  <div  class="box">
    <span class="tooltiptext">c.carddata.description c.carddata.description c.carddata.description c.carddata.description c.carddata.description</span>
    <div class="text">c.carddata.name<br/>c.carddata.name</div>
  </div>
  <div  class="box">
    <span class="tooltiptext">c.carddata.description c.carddata.description c.carddata.description c.carddata.description c.carddata.description</span>
    <div class="text">c.carddata.name<br/>c.carddata.name</div>
  </div>
  <div  class="box">
    <span class="tooltiptext">c.carddata.description c.carddata.description c.carddata.description c.carddata.description c.carddata.description</span>
    <div class="text">c.carddata.name<br/>c.carddata.name</div>
  </div>
  <div  class="box">
    <span class="tooltiptext">c.carddata.description c.carddata.description c.carddata.description c.carddata.description c.carddata.description</span>
    <div class="text">c.carddata.name<br/>c.carddata.name</div>
  </div>
  <div  class="box">
    <span class="tooltiptext">c.carddata.description c.carddata.description c.carddata.description c.carddata.description c.carddata.description</span>
    <div class="text">c.carddata.name<br/>c.carddata.name</div>
  </div>
</div>

(列CSS仍处于实验状态,似乎不再发展)

  display:flex;
  flex-flow:column wrap;
#div1 {
  float: left;
  width: 328px;
  height: 250px;
  margin-left: 4px;
  padding: 10px;
  border: 1px solid black;
  border-radius: 6px;
  background-color: white;
   display:flex;
  flex-flow:column wrap; 
}

.box {
  height: 54px;
  width: 160px;
  margin:0 5px 0 0;
  text-align: center;
  background-color: white;
  color: purple;
  border: 1px solid black;
  border-radius: 4px;
  margin-bottom: 2px;
  position: relative;
  text-align: center;
}

.tooltiptext {
  visibility: hidden;
  width: 160px;
  background-color: purple;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  top: 100%;
  left: 50%;
  margin-left: -80px;
}

.box:hover .tooltiptext {
  visibility: visible;
}