- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有重复元素的全宽 div。溢出时,我 overflow hidden 的内容并且不显示空白。我的问题是我想计算隐藏项(或我猜显示的项)的数量,但不知道如何计算。
您可以在 https://codepen.io/joshuaohana/pen/aqPJMr 上看到一个基本示例
在这种情况下,控制隐藏的 css 是
div {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
white-space: nowrap;
overflow: hidden;
}
如果你删除溢出线你会得到一个滚动条,把它放回去,没有滚动条。
当溢出设置为隐藏时,我需要一种方法来计算丢失的溢出部分中隐藏的元素。
我发现的唯一事情是尝试计算哪些元素已隐藏,但这不适用于溢出项。我找不到任何可以搜索的不同限定词。
最佳答案
这是 jQuery 的一种方法。检测包含 div
的宽度。然后使用 offset()
方法计算 left
坐标超出此宽度的元素数。
var parentContainerWidth = $("div").width();
var elementCount = $('span').filter(function() {
return $(this).offset().left >= parentContainerWidth;
}).length;
alert(elementCount);
div {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
white-space: nowrap;
overflow: hidden;
}
span {
background: pink;
margin: 2px;
padding: 1rem;
font-family: sans-serif;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<span>here is an item 1</span>
<span>here is an item 2</span>
<span>here is an item 3</span>
<span>here is an item 4</span>
<span>here is an item 5</span>
<span>here is an item 6</span>
<span>here is an item 7</span>
<span>here is an item 8</span>
<span>here is an item 9</span>
<span>here is an item 10</span>
<span>here is an item 11</span>
<span>here is an item 12</span>
<span>here is an item 13</span>
<span>here is an item 14</span>
<span>here is an item 15</span>
<span>here is an item 16</span>
<span>here is an item 17</span>
<span>here is an item 18</span>
<span>here is an item 19</span>
<span>here is an item 20</span>
<span>here is an item 21</span>
<span>here is an item 22</span>
<span>here is an item 23</span>
<span>here is an item 24</span>
</div>
关于javascript - 通过 overflow hidden 统计隐藏元素的个数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49021065/
我正在使用 bootstraptable 并试图让单元格显示溢出的内容但只显示向下(即 overflow-y)。问题是,bootstraptable css 使用 overflow: hidden o
来自文档:溢出: The overflow shorthand CSS property sets what to do when an element's content is too big to
有多个这样命名的问题,但我没有找到一个适用于我的情况,所以我在这里: 在这段代码中: #container:hover { overflow-x: hidden; } #container {
我正在学习 Haskell,但遇到了我没想到的异常“堆栈溢出”。 代码相当简单: type Reals = Double prod :: Reals -> Reals -> Reals prod a
我通读了this question并且没有看到我的问题是否有解决方案。 我创建了一个 CodePen这表明了这个问题。我希望隐藏红色边框左侧和右侧 (overflow-x) 的所有内容,但保持顶部和底
我有一张 bootstrap 4 卡,我想在其中隐藏字幕的溢出(并显示“...”)。我怎样才能实现这个目标?如果可能的话使用纯引导代码... Test object Added by
我今天更新了我的 flutter ,现在堆栈小部件中的溢出参数不再有效。 Flutter 1.22.0-10.0.pre.252 • channel master • https://github.c
使用 border-radius Opera 实际上不会隐藏元素的溢出部分。我已经尝试应用我设法在类似线程中找到的东西,例如定义边框样式或注意使用绝对和相对参数进行定位。但它仍然无法正常工作。 htm
我在固定大小的 div 中有一个表。如果表格溢出 div,我希望滚动条出现。我还想在向下滚动时克隆表格的标题,以便标题持久存在。我遇到的问题是我希望水平滚动条滚动克隆的标题和原始表格,而垂直滚动条
奇怪,我以为 overflow-x 和 overflow-y 都被广泛支持,但后来我才看到它只支持 CSS3( http://reference.sitepoint.com/css/overflow
unsigned long long terms; unsigned long long test; unsigned long long digit = 1; unsigned long long
我有一个案例,我必须使用 overflow-x:scroll; 水平显示内容。 现在在这个Fiddle第一个 block 有 overflow-y:scroll; 提供滚动,用户可以滚动内容。在第二个
您好,我正在尝试只使用 overflow-x 而不是 overflow-y 结构是这样的 Head1 feild1
我有一个正在运行的计划作业,我想计算过去 30 天的时间。为此,我收到一条警告,表示在表达式中检测到数字溢出。我怎样才能安全地给予 30 天? @Override @Scheduled(cro
我有一个父级,它有多个子级,当父级宽度溢出时,我喜欢显示水平滚动条。 我不想使用“display:inline-block”属性,因为它们之间会产生空白。 这是我的尝试: .parent{ wid
我正在为导航栏编写一些 CSS,我需要为下拉菜单使用 max-height 和 overflow-y: scroll 以便确保它适合页面。但是,每当我将 overflow-y 属性设置为滚动时,它似乎
这是我的问题。我有一个旋转木马,它也像菜单一样。当选项卡的数量高于浏览器可用的宽度空间时,将出现轮播控件。一切正常。但我还在每个选项卡上添加了一个下拉菜单,这就是问题所在。如果我设置 overflow
这个问题在这里已经有了答案: CSS overflow-x: visible; and overflow-y: hidden; causing scrollbar issue (10 个答案) 关
这个问题在这里已经有了答案: How do you keep parents of floated elements from collapsing? [duplicate] (15 个答案) W
这是一个代码片段: div.one { width: 98%; border: 5px solid black; overflow-x: visible; overflow-y: hi
我是一名优秀的程序员,十分优秀!