【问题标题】:Div at the top of the page before other top divs页面顶部的 div 在其他顶部 div 之前
【发布时间】:2012-04-15 13:09:44
【问题描述】:

即使第一类具有相同的最高值,如何在第一类之前强制第二类? 如果可能的话,使用 jquery 或只是 css hack。 firstClass 的值可能与本例不同,但 secondClass 的值是固定的。

<html>
    <body>
        <div class="firstClass">Hello</div>
        <div class="secondClass">This is Warning!</div>
    </body>
</html>

和css

.firstClass {
    position: fixed;
    top: 0px;
}

.secondClass {
    position: fixed;
    top: -25px;
}

在线演示http://jsfiddle.net/AQUgk/

谢谢。

【问题讨论】:

  • 你不能让第一个从 30px 开始,然后将上面的空间留给像“这是警告”这样的消息。
  • 对不起,实际使用的是解析页面,这里应该告知这个页面不是我们的。这就是为什么我不使用实际的 CSS。谢谢!

标签: jquery css twitter-bootstrap


【解决方案1】:

仅使用 CSS 在屏幕上移动它:

$(".firstClass").css('top', $(".secondClass").height());
$(".secondClass").css('top', 0);

如果移动 DOM 中的元素是你所追求的:

$(".firstClass").before($(".secondClass"));

FIDDLE

【讨论】:

  • 谢谢,但是即使 firstclass 未定义,如何在底部强制 secondClass!
  • 首先你想在 firstClass 之前有 secondClass,现在你想在底部有 secondClass。在什么的底部,屏幕、元素,还是未定义的元素下方?
  • 然后设置为$(".secondClass").css('bottom', 0);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多