How to take CSS values from one element and apply to other elements. Stick Footer

Asked

Viewed 5,787 times

1

I’m using the solution Ryan Fait’s Stick Footer, but wanted to make it more dynamic using Javascript, allowing the footer height to automatically calculate the other values of the CSS properties of the other elements. Can be included inline even.

So far I’ve got something like what I want in jQuery. Can someone give me a hand?

Detail, I replaced the .wrapper of Ryan’s solution by #content in my code.

$(function(){
    var footerHeight = $(".footer").height();
    $("#content").css("margin-bottom", -footerHeight);
    $(".push").css("height", footerHeight);
});
  • You want to get color values and backgrounds or just height/width?

2 answers

1

Ryan’s solution says nothing about colors whether from source or background

but if you want to take css from an element do the request like this

<script>
    var cor_texto = $('#Id_da_tag').css('color');
    var cor_background = $('#Id_da_tag').css('background');
    $('#id_destinno').css('color',cor_texto);
    $('#id_destinno').css('background',cor_background );
</script>

1

You can assign the style of one element to another as follows:

$("#destino").attr("style", $("#origem").attr("style")).addClass($("#origem").attr("class"));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.