LoginSignup
nkarishu
@nkarishu

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

footer高さを取得してmarginに代入したい

解決したいこと

footer高さを取得してmainのmargin-bottomに指定したい

例)
紙芝居のようにフッターを表示させたい。

該当するソースコード

$(function () {
    $(".header").on("click", function () {
        let height1 = $(".footer").css("height");
        alert(height1);
        $(main).css("margin-bottom", height1);
    });
});
0

1Answer

JQuery詳しくないですが、記載されている内容で問題ないと思います。
marginが聞かない理由はいくつかあります。
例えば、ほかの要素でmarginが効いていると、効かない場合があります。
また、ブロック要素でない場合もmarginが思った通りに効かない場合があります。
記載された内容でどう効かないかわかりませんが、以下のサイトを参照してみるのはどうでしょうか?
https://qiita.com/7note/items/3eaecf9688e957eeb93d

0

Your answer might help someone💌