实现方法:css
html: <div class="outer2"> <div class="outer"> <span class="inner">朗御2单元29F弱电井F-RRU637677_05</span> </div> </div> css: .outer{ max-width: 100px; overflow-x: hidden; white-space: nowrap; text-overflow: ellipsis; /* 若是超过字段须要显示为... */ } .inner{ max-width: 400px; }
max-width内外元素都要设置,为的是实现元素的溢出效果;html
overflow-x: hidden; 溢出spa
white-space: nowrap; 内容不换行htm
text-overflow: ellipsis; 超过字段显示省略号ip
以上三个样式设置是为了实现上图所示的效果,三者必须同时使用。it
注意:此方式只是用于一个层级嵌套的元素,若是设置在类outer2,class
则不会出现这个效果,注意这个坑。方法