是否可以在显示内联块上创建显示/隐藏而不影响相邻元素?
我已经创建了我遇到的问题的演示: http://jsbin.com/omomit/2
当您单击显示/隐藏链接时,您会看到隐藏的文本出现。我想要修复的行为是它如何下推第一行和第二行内容,而不仅仅是其所在的父容器。
换句话说,如果您为每个列表项添加标签,它将如下所示:
AB ( <---这是一个伪行,因为它不是编程为一行)
CD
当我单击 A 的切换开关时,它看起来像这样(H 表示隐藏内容):
A B
H _
CD
D已经被推倒了,这是不应该发生的。相反,我希望它只是这样:
A B
HD
C
我知道我可以使用浮动来解决这个问题,但我不想使用浮动的原因是因为这些列需要模拟一个表,这样,无论每个人造列模块的高度如何,它们都会在人造列中对齐-排。每个人造行从上到下相互对齐是至关重要的,这就是为什么我也使用垂直对齐设置为顶部的原因。
是否可以拥有此切换脚本功能,以便它仅影响使用它的父容器?
I've created a demo of the problem I'm having: http://jsbin.com/omomit/2
When you click on show/hide link, you see the hidden text appear. The behavior I'd like to fix is how it pushes down both the 1st and 2nd row of content instead of just the parent container in which it exists.
In other words, if you label each list item, it would look like this:
A B ( <---This is a faux-row, since it's not programmed to be a row)
C D
When I click on the toggle for A, it looks like this (H for hidden content):
A B
H _
C D
D has been pushed down and this shouldn't happen. Instead, I want it to be just this:
A B
H D
C
I know I can fix this using floats, but the reason I don't want to use floats is because these columns need to emulate a table so that, no matter the height of each faux-column module, they line up in the faux-row. It's critical that each faux-row align with each other from the top down, which is why I am also used vertical-align set to top.
Is it possible to have this toggle script functionality so that it only affects the parent container in which it's being used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不能 100% 确定您的要求,但如果您在绝对定位的元素内显示/隐藏内容,它不会影响布局。
尝试将这些 CSS 属性添加到您的 .hiddentoggle 选择器中:
更新:
根据您的新信息,我很好奇您为什么不想使用浮动。我也很好奇你所说的“假行”是什么意思。
无论哪种方式,如果您希望在显示 A 内容时只让 C 框向下移动,实现这一点的唯一方法是将 A 和 C 包装在一个元素中。该元素不必是浮动的,它也可以是
display:inline-block
,但是无论您决定如何布局它,您都需要创建某种“列”为了获得您想要的效果。I'm not 100% sure what you're asking for, but if you have the show/hide content inside of an element that is absolutely positioned, it won't affect the layout.
Try adding these CSS properties to your .hiddentoggle selector:
UPDATE:
Based on your new information, I'm curious why you don't want to use floats. I'm also curious what you mean by "faux-row".
Either way, if you want only the C box to move down when showing the A content, the only way to make that happen is to wrap A and C in an element. That element doesn't have to be floated, it would also be
display:inline-block
, but however you decide to lay it out, you're going to need to make some sort of "column" in order to get the effect you're looking for.