简体   繁体   English

使用 CSS 排列隐藏元素

[英]Arranging hidden elements using CSS

OK, this is what I need :好的,这就是我需要的:

  • I've got a horizontal container (let's call that C), containing 2 elements (A,B)我有一个水平容器(我们称之为 C),包含 2 个元素 (A,B)
  • Of these two elements, only one has to be visible at any time.在这两个元素中,只有一个必须随时可见。 So, the other's visibility property is set to hidden .因此,另一个的visibility属性设置为hidden
  • Let's say these elements are placed with this exact sequence : |<----------- AB ->|假设这些元素按以下确切顺序放置: |<----------- AB ->| , and thus right-aligned. ,因此右对齐。
  • When element B is active, everything is OK.当元素 B 处于活动状态时,一切正常。
  • When element A is active (and thus B is invisible), the A element doesn't float to the right side and remains where it is : |<----------- A --->|当元素 A 处于活动状态(因此 B 不可见)时,A 元素不会浮动到右侧并保持原位: |<----------- A --->|

The question :问题:

  • How can I "push" element A to the right ("above" element B), so that it is like it's floating right/如何将元素 A 向右“推”(“上方”元素 B),使其就像向右浮动/

Use display:none;使用display:none; instead of visibility:hidden;而不是visibility:hidden; as visibility:hidden;作为visibility:hidden; will hide the element but still occupy the space将隐藏元素但仍占据空间

Visibility: hidden will prevent the element from being rendered, but it will still take up space. Visibility: hidden将阻止元素被渲染,但它仍然会占用空间。

Display: none will prevent the element from being rendered AND from affecting the layout. Display: none将阻止元素被渲染并影响布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM