-1

デフォルトの幅を持たない div 要素を水平方向に中央揃えするために jQuery を使用しています。次のコードを使用していますが、機能していません。誰かが理由を理解するのを手伝ってくれるなら、それは非常に役に立ちます。PS、高さのデフォルトの高さは 20 なので、-10px はそこから来ます。

var w = ($(".notec").width() + 51) / 2;
$(".buttons").css("margin", "-10px 0 0 -" + w + "px");
4

2 に答える 2

0

に関するセンタリング.notec。要素がブロック要素として表示されている場合、幅は必要ありません。

var h = ($(".notec").height() - $(".buttons").height()) / 2;
$(".buttons").css("margin", h+"px auto 0 auto');
于 2012-04-29T15:48:28.960 に答える
0

見てください:UI/API/1.8/Position http://bit.ly/IvUhLF

$(".overlay").hide();
$(".photo_hold").hover(
  function () {
      $(".overlay", $(this)).show();
      $(".buttons", $(this)).position({
          my: "center",
          at: "center",
          of: $(this)
      });
   },
  function () {
      $(".overlay", $(this)).hide();
  }
);

変数をいじって、必要なことを実行させます

于 2012-04-29T15:52:01.663 に答える