- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我试图显示一个指示器(橙色点)来表示列表项上发生了一个操作。我还使用 overflow: hidden;
和 text-overflow: ellipsis;
来处理文本溢出。
我面临的问题是,当发生文本溢出时,指示器不可见。
.root {
width: 200px;
border: 1px solid black;
}
ul {
margin: 0;
padding: 0;
list-style-type: none;
}
li {
border-bottom: 1px solid gray;
display: flex;
}
li .name {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
li .name:after {
content: '';
display: inline-block;
width: 6px;
height: 6px;
background: orange;
}
<div class="root">
<ul>
<li>
<div class="name">
This is one
</div>
</li>
<li>
<div class="name">
This is one
</div>
</li>
<li>
<div class="name">
This is one
</div>
</li>
<li>
<div class="name">
This Long Long Long Long Text Is Here
</div>
</li>
</ul>
</div>
最佳答案
伪元素被视为 inline-block
内容,这意味着它直接位于文本之后。
您可以强制显示伪元素,方法是使用 position: absolute;
将其从文档流中取出,并将其放置在 .name
容器的末尾。
需要进行以下更改:
position: relative;
和 padding-right: 10px;
到 li .name
,这将相对于它定位伪元素并提供一些喘息的空间position: absolute;
, right: 2px;
, top: 0;
, bottom: 0;
和 margin: auto;
将伪元素定位在 .name
.root {
width: 200px;
border: 1px solid black;
}
ul {
margin: 0;
padding: 0;
list-style-type: none;
}
li {
border-bottom: 1px solid gray;
display: flex;
}
li .name {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
position: relative;
padding-right: 10px;
}
li .name:after {
content: '';
display: inline-block;
width: 6px;
height: 6px;
background: orange;
position: absolute;
right: 2px;
top: 0;
bottom: 0;
margin: auto;
}
<div class="root">
<ul>
<li>
<div class="name">
This is one
</div>
</li>
<li>
<div class="name">
This is one
</div>
</li>
<li>
<div class="name">
This is one
</div>
</li>
<li>
<div class="name">
This Long Long Long Long Text Is Here
</div>
</li>
</ul>
</div>
关于css - :after node is not visible with text overflow ellipsis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44156015/
我制作了一个 DIV 和 visibility: hidden 并附加了一个 ::before 这个 DIV 的伪元素 visibility : 可见。这在 Firefox、Chrome 和 Safa
我正在使用 jquery 可见选择器来检查子元素是否可见。但令人惊讶的是 .is("visible") 和 .is(":visible") 在使用 css Visibility:hidden 时显示不
我有这个代码 #checkboxDIV { visibility: hidden; } #itemcard:hover #checkboxDIV {
我有一个用 ul 创建的菜单/li列出。 为了创造一个不错的效果,我有以下 css: #menu ul { /* ... */ visibility:hidden; /* ..
我想要的是,当我点击 Dashboard Button 时,它会像 SlidingDrawer 一样打开,打开后再次点击它会关闭。我使用这个自定义抽屉是因为 SlidingDrawer 已弃用。 现在
如何使用 jQuery 只选择可见元素? jQuery 选择器 :visible 和 :hidden 只尊重 display:none 作为真的隐藏?不是可见性:隐藏或可见性:可见。 我知道它们在技术
为什么我的 $('#myDiv').css('visibility', 'visible'); 不起作用? $('#clickdiv').click(function() { alert($(
在 $(document).ready 函数中通过 JavaScript 将子容器设置为 visibility: visible 时,我遇到了一个奇怪的问题。 问题是: 我有一个父元素,它有 boot
在 jQuery 中: e.is(':visible'); 检查元素是否显示。 jQuery 中是否有一个函数可以检查元素是否具有隐藏或可见属性可见性? 现在我必须自己实现这个功能。但我想使用 jQu
我在 mvc 中使用一个帖子表单,在帖子中我想显示一个隐藏的 div(惊喜)。 我正在使用 js/jquery 来显示 div,它可以在所有浏览器中工作,除了 mac 上的 safari :( 我现在
我似乎无法获得我的 jquery {{NotificationNavDot}} 功能正常工作! 在下面找到帮助文件: {{NotificationNavDot}} 在下面找到我的帮助
WPF 中的 Visibility.Collapsed 和 Visibility.Hidden 有什么区别? 最佳答案 不同之处在于,Visibility.Hidden隐藏了控件,但保留了它在布局中占
我有一个 if 语句来检查我的 div 下面是否没有任何可见内容,如果是,我会隐藏子元素的同级元素。 var $remainingprojects = $searchproject.s
这是我的菜单模型 HTML Menu 1 (overflow:hidden) Item 1 submenu 1 submen
编辑 3 实际上,我根本不需要弄乱可见性/不透明度...所以我删除了那些行(如编辑 2 所示)...添加了动画 -播放状态:暂停/运行.... 得到了我想要的效果... 编辑 2:感谢 Gineto
在我的应用程序中有一个广告 WebView ,它在 Activity 开始时调用一个 url。一切都很好,除了一件小事,它更像是一个可见性问题......所以问题是,当我开始 Activity 时,我
根据 the "visible" binding documentation , 如果 visible 的值为 false,Knockout 使用 display: none 隐藏元素。我怎样才能让它
* { margin: 0; padding: 0; border: 0; } .navBar { background-color: #2A2A2A; min-width: 10
android 布局使用 layout_weight。我的目标是所有组件的 1/3,但有时页脚实际上设置为消失,然后可见。从 gone 设置为 visible 时,权重计算如何工作?我没有看到具有 1
我有两个单选按钮,两个文本框和一个按钮。 当我点击第一个按钮时,应该只会出现一个文本框,当我点击第二个按钮时,应该会出现两个文本框。 但我想使用 visibility:hidden|visible 属
我是一名优秀的程序员,十分优秀!