This is my jQuery code:
<script type="text/javascript" src="js/jquery.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
get_font_size();
set_sidebar();
});
function get_font_size()
{
var b=$(window).width();
var side_size=b*260/1440;
b=b-side_size;
$("#sidebar").css({"width":side_size});
$("#alexa-widget img").css({"width":side_size});
$(".fb-like-box").attr("data-width",side_size);
}
function set_sidebar()
{
var b=$(window).width();
var font_size=b*65/1440;
var font_size_2=b*133/1440;
var margin_top=b*10/1440;
margin_top*=-1;
margin_top=Math.round(margin_top);
$("#my_tabs li").css({"font-size":font_size});
$("#header").css({"font-size":font_size_2,"margin-top":margin_top});
}
</script>
Everything works fine except the margin-top property.I can’t assign margin-top to a negative value.It fails but font size and other properties work’s fine.Why jquery css settings fails with negative values?If I do the the same inside css it work’s perfect.I need this to alter the webpage according to screen resolutions So I can’t do that inside CSS.I need jQuery fix for this.I already have viewport meta tag in my code so please don’t suggest viewport or media query solutions.I have checked the margin_top variable with alert(margin_top) and it shows me a correct negative value as desired so the calculation takes place correctly only the css setting part fails.Please help me fix this.Thank You.
When setting the margin-top using jQuery, you must add the units (in this case: px) at the end
Example:
EDIT (to make it more clear on how to fix your code:
Change the line in your code that looks like:
to