为什么div的“text-overflow:ellipsis”属性不适用于其子div

时间:2017-08-18 09:13:44

标签: html css

CSS属性text-overflow: ellipsis不适用于具有类名cluster-name的子div。

.ft-column {
  flex-basis: 0;
  flex-grow: 1;
  padding: 4px;
  text-overflow: ellipsis;
  overflow: hidden;
}

.ft-column>.cluster-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
<div class="ft-column">
  <div>Cluster</div>
  <div class="pull-left cluster-name">FQDN</div>
</div>

3 个答案:

答案 0 :(得分:1)

你应该给父div width,这样当孩子溢出宽度时它会触发样式。如果你给子div提供宽度,这也会有用。难以管理,因为父母是包装器所以最好来管理父div。

.ft-column {
  flex-basis: 0;
  flex-grow: 1;
  padding: 4px; 
  width: 20%;
}

.cluster-name{
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
<div class="ft-column">
  <div>Cluster</div>
  <div class="pull-left cluster-name">FQDNsaxaxasxsaxsaxasxvfdvdvfvdfvfd</div>
</div>

答案 1 :(得分:0)

.ft-column 
{
 flex-basis: 0;
 flex-grow: 1;
 padding: 4px; 
 text-overflow: ellipsis;
 overflow: hidden
 }
 div.cluster-name {
  white-space: nowrap; 
    width: 2em; 
    overflow: hidden;
    text-overflow: ellipsis; 
   
      
  }
<div class="ft-column">
    <div>Cluster</div>
    <div class="pull-left cluster-name">FQDN</div>
</div>

width定义.cluster-name,然后运行代码text-overflow: ellipsis;,请立即尝试

答案 2 :(得分:0)

请按照以下方式重新排列CSS,这里是为孩子增加宽度。

.ft-column {
  flex-basis: 0;
  flex-grow: 1;
  padding: 4px; 
  text-overflow: ellipsis;
  overflow: hidden
}
.ft-column > .cluster-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100px;
}
<div class="ft-column">
    <div>Cluster</div>
    <div class="pull-left cluster-name">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
</div>