html - 带有文本椭圆的编号列表也隐藏了订单号

标签 html css

我正在处理带有文本椭圆的 ol 列表,但是当我添加 overflow: hidden ; 属性时,它还会隐藏数字顺序。

如何使用 text ellipse 并保持数字可见

CodePen

.wrapper{width:300px; background-color:#ccc; padding:10px;}
.tab-ol li { 
list-style-position:inside;
  white-space: nowrap;
  overflow: visible;
  text-overflow: ellipsis;  
}
.ol-2 li{
  list-style-position:inside;
  white-space: nowrap;
  overflow: hidden ;
  text-overflow: ellipsis;  
}
ol {
	counter-reset:li; /* Initiate a counter */
	margin-left:0; /* Remove the default left margin */
	padding-left:0; /* Remove the default left padding */
}
ol > li {
	position:relative; /* Create a positioning context */
	margin:0 0 6px 2em; /* Give each list item a left margin to make room for the numbers */
	padding:4px 8px; /* Add some spacing around the content */
	list-style:none; /* Disable the normal item numbering */
	border-top:0px solid #666;
	background:#f6f6f6;
}
ol > li:before {
	content:counter(li); /* Use the counter as content */
	counter-increment:li; /* Increment the counter by 1 */
	/* Position and style the number */
	position:absolute;
	top:-2px;
	left:-2em;
	-moz-box-sizing:border-box;
	-webkit-box-sizing:border-box;
	box-sizing:border-box;
	width:2em;
	/* Some space between the number and the content in browsers that support
	   generated content but not positioning it (Camino 2 is one example) */
	margin-right:8px;
	padding:4px;
	border-top:0px solid #666;
	color:#fff;
	background:#666;
	font-weight:bold;
	/* font-family:"Helvetica Neue", Arial, sans-serif; */
	text-align:center;
}
li ol,
li ul {margin-top:6px;}
ol ol li:last-child {margin-bottom:0;}
<div class="wrapper">
<ol class="tab-ol">
<li>This is article number one for this month</li>
<li>This is article number one for this month</li> 
<li>This is article number one for this month</li>
<li>This is article number one for this month</li>
</ol> 
</div>
<p>ANOTHER LIST WITH HIDDEN NUMBER</p>
<div class="wrapper">
<ol class="tab-ol ol-2">
<li>This is article number one for this month</li>
<li>This is article number one for this month</li> 
<li>This is article number one for this month</li>
<li>This is article number one for this month</li>
</ol> 
</div>

最佳答案

用padding代替margin,让数字在li里面:

.wrapper {
  width: 300px;
  background-color: #ccc;
  padding: 10px;
}

.tab-ol li {
  list-style-position: inside;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

ol {
  counter-reset: li;
  margin-left: 0;
  padding-left: 0;
}

ol>li {
  position: relative;
  margin: 0 0 6px 0;/*remove the margin here*/
  padding: 4px 8px 4px 2.1em;/* Add the padding here*/
  list-style: none;
  border-top: 0px solid #666;
  background: #f6f6f6;
}

ol>li:before {
  content: counter(li);
  counter-increment: li;
  position: absolute;
  top: 0;
  left: 0;/*adjust the new position*/
  box-sizing: border-box;
  width: 2em;
  padding: 4px;
  border-top: 0px solid #666;
  color: #fff;
  background: #666;
  font-weight: bold;
  text-align: center;
}

li ol,
li ul {
  margin-top: 6px;
}

ol ol li:last-child {
  margin-bottom: 0;
}
<div class="wrapper">
  <ol class="tab-ol">
    <li>This is article number one for this month</li>
    <li>This is article number one for this month</li>
    <li>This is article number one for this month</li>
    <li>This is article number one for this month</li>
  </ol>
</div>

关于html - 带有文本椭圆的编号列表也隐藏了订单号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50041527/

相关文章:

css - Bootstrap 容器内容未居中超过 1200 像素视口(viewport)宽度

html - 轻松定位比其他图像高两倍的图像

javascript - CSS选择 previous sibling

javascript - 为什么只有Chrome在页面之间闪烁白色?

java - 为什么 Swing Parser 的 handleText 不处理嵌套标签?

css - 停止 Bundle Transformer 在 LESS 中转换相对路径

html - div 中的 anchor 标记应该包裹 div

javascript - Angular cdkDropList 拖动元素限制

javascript - 如何构建全屏 html 5 网络应用程序?

css - CSS 可以选择特定内容的元素吗?