html - 用省略号制作中间跨度而不破坏图标和正确的数字

标签 html css

我想将 ellipsis 添加到 li.text 但同时我想保留正确的 span (带数字)和距离(填充)在数字 spantext span 之间。

我怎样才能做到这一点?

.right {
  float: right;
  padding: 0 8px;
}

.menu {
  width: 155px;
  border-right: 1px solid #ccc;
  list-style-type: none;
}

body {
  font-family: "Segoe UI", "Open Sans", Helvetica, Arial, sans-serif;
}
a {
  text-decoration: none
}
    .p {
     width: 155px;

      white-space: nowrap; 
      overflow: hidden;
      text-overflow: ellipsis;
      display: inline-flex;
    }
      .text {
        white-space: nowrap; 
        overflow: hidden;
        text-overflow: ellipsis;
        width: 45%;
        padding-right: 16px;
      }
      .right {
        width: 10%;
      }
<link href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet"/>
<ul class="menu">
	<li class="" data-action="switchFolder" data-sign-in="false" id="inbox">
		<a href="javascript:void(0);">
            <div class="p">
			   <i class="icon ion-ios-filing-outline"></i>
			   <span class="text">This is a very long element that wil exceed limit</span>
			   <span class="right">429</span>
            </div>
		</a>
	</li>	
</ul>

预期结果:

result

注意429text之间的空格。我尝试了一些,但似乎接近 429。而且无论我尝试什么,它都会因图标而中断到下一行。

最佳答案

只要您使用 inline-flex100% 宽度就可以完美地满足您的需求:

.text {
  width: 100%;
  padding-left: 5px;
}

.right {
  width: 10%; /* remove it */
}

.right {
  float: right;
  padding: 0 8px;
}

.menu {
  width: 155px;
  border-right: 1px solid #ccc;
  list-style-type: none;
}

body {
  font-family: "Segoe UI", "Open Sans", Helvetica, Arial, sans-serif;
}
a {
  text-decoration: none
}
    .p {
     width: 155px;

      white-space: nowrap; 
      overflow: hidden;
      text-overflow: ellipsis;
      display: inline-flex;
    }
      .text {
        white-space: nowrap; 
        overflow: hidden;
        text-overflow: ellipsis;
        width: 100%;
        padding-left: 5px;
        padding-right: 16px;
      }
      .right {
        /*width: 10%;*/
      }
<link href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet"/>
<ul class="menu">
	<li class="" data-action="switchFolder" data-sign-in="false" id="inbox">
		<a href="javascript:void(0);">
            <div class="p">
			   <i class="icon ion-ios-filing-outline"></i>
			   <span class="text">This is a very long element that wil exceed limit</span>
			   <span class="right">429</span>
            </div>
		</a>
	</li>	
</ul>

关于html - 用省略号制作中间跨度而不破坏图标和正确的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55324687/

相关文章:

javascript - 使Firefox和Chrome以特定名称下载图像

html - 按钮宽度占父项的百分比

html - 将 3D 悬停效果应用于多个 Div

html - 标记( block )引用作者的正确方法是什么?

javascript - 从外部 javascript 文件添加 html

javascript - 注入(inject)的 Javascript 错误(Python Web Scraper)

javascript - Skrollr 背景动画不会交换

html - 网站适用于 firefox,但不适用于 chrome 或 safari。导航行在 chrome 和 safari 中没有正确排列

html - 从 Bootstrap .nav-tabs 中删除一些边框

jquery - 寻找一种在 div 之间滑动底部边框的方法