Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8666567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:45:50+00:00 2026-06-12T17:45:50+00:00

This is my jQuery code: <script type=text/javascript src=js/jquery.js> </script> <script type=text/javascript> $(document).ready(function() { get_font_size();

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:45:51+00:00Added an answer on June 12, 2026 at 5:45 pm

    When setting the margin-top using jQuery, you must add the units (in this case: px) at the end

    Example:

    >>> $("body").css("margin-top");
    "0px"
    >>> $("body").css("margin-top", "10");
    [body]
    >>> $("body").css("margin-top");
    "0px"
    >>> $("body").css("margin-top", "10px");
    [body]
    >>> $("body").css("margin-top");
    "10px"
    

    EDIT (to make it more clear on how to fix your code:

    Change the line in your code that looks like:

    $("#header").css({"font-size":font_size_2,"margin-top":margin_top});
    

    to

    $("#header").css({"font-size":font_size_2,"margin-top":margin_top + "px"});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my jQuery code <script type=text/javascript> jQuery(document).ready(function($){ $(#'.$tag.').dcFlickr({ limit: '.$nFlickr.', style: thumb, q:
Ok, I have this code: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script> <script type=text/javascript> function get()
I have this Javascript/JQuery code: <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js></script> <script type=text/javascript> name = $(#name).val(); alert(Name:
OK i have this code HTML: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js> </script> <script type=text/javascript>
Im using jquery 1.3.2 and this is the code: <script type=text/javascript> //<![CDATA[ jQuery(function(){ jQuery('.news_bullet
I run this code here <html> <script type=text/javascript src=lib/jquery-ui-1.8.21.custom.min.js></script> <script src=http://127.0.0.1:5984/_utils/script/jquery.couch.js></script> <!--<script type=text/javascript src=lib/jquery-1.7.2.js></script>-->
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
I made this bookmarklet: javascript:(function(){var s=document.createElement('script');s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');document.getElementsByTagName('body')[0].appendChild(s);$('#hldIntMain').hide();$('#fadeBackground').hide();return false;})() Formatted code: // Add in jQuery var
this is my ajax call <script src = js/jquery.js type = text/javascript></script> <script type=text/javascript>
<script type=text/javascript> if (typeof jQuery == 'undefined') { var script = document.createElement('script'); script.type =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.