【问题标题】:Positioning element within parent element在父元素中定位元素
【发布时间】:2012-11-07 11:08:42
【问题描述】:

我有以下脚本,它将一些按钮(现在是假按钮)添加到 div:

$("<div class='divButtons'>").appendTo( $(this).closest(".widget").find(".widget_header") );
// not real buttons, just text at the moment.  Trying to get the position right first.
$(".divButtons").text("(close), (min), (max), (help)").css({background:"red",float:"right"});

问题是,我不知道如何让divButtons 的右上角将自己定位到父.widget_header 的右上角。我尝试添加top:some_number_here,但是在使用jQueries ui-sortable 移动div 时效果不佳。

【问题讨论】:

  • 如果你使用css('right', 0)会怎样?
  • @x4f4r,我刚刚试过这个.css({background:"red",float:"right",right:"0px",top:"0px"}); 并没有什么不同。

标签: jquery jquery-ui jquery-selectors jquery-ui-sortable


【解决方案1】:

您不必通过 javascript 指定样式属性,尝试在 .css 文件中添加类似这样的内容:

.widget_header {
    position: relative;
}

.your-top-right-corner-class {
    position: absolute;
    top: 0;
    right: 0;
}

【讨论】:

  • 这几乎可以工作,唯一的问题是,如果我使用 IE8 使用 jquery-ui-sortable 移动 .widget-header,整个 .widget_header 就会消失。我必须在.widget_header 上将鼠标移出和鼠标移入才能再次出现。删除样式表修复了 .widget_header 在移动时消失的行为。
猜你喜欢
  • 1970-01-01
  • 2018-03-08
  • 2013-06-16
  • 1970-01-01
  • 2014-10-06
  • 1970-01-01
  • 2012-09-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多