#1
  1. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115

    Jquery css() Top-property weirdness


    Hi guys,

    I have a weird problem. I am trying to set the absolute position of an image with jquery. For some reason the 'top'-property is not working.

    Code:
    $("img.current").css({"position":"absolute","top":"90px","left":"70px"});
    When I inspect it the result looks like this:
    Code:
    <img width="100%" height="auto" alt="" class="current" src="images/aaa.jpeg" style="position: absolute; left: 70px;">
    Clearly the top property is not declared inline.

    Anyone an idea?

    P.s. I am now using margin-top but that is not really desired
    Last edited by aeternus; October 19th, 2012 at 10:19 AM.
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,131
    Rep Power
    4304
    Hello, aeternus.

    Do you have an example page you could show us?

    By the way, while "auto" is a valid value for the CSS "height" property, it is not a valid value for the HTML <img> element's "height" attribute. Just remove that attribute, if you don't want to set it to a specific number.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115
    Originally Posted by Kravvitz
    Hello, aeternus.

    Do you have an example page you could show us?

    By the way, while "auto" is a valid value for the CSS "height" property, it is not a valid value for the HTML <img> element's "height" attribute. Just remove that attribute, if you don't want to set it to a specific number.
    Ha You are right! (my jquery will fill that thing in)

    I haven't got an online example of the problem. But I will post one on some dummie site.

    I'll keep you posted.
  6. #4
  7. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115
    Lol i am such a dumb *** :P

    Below all the code I had a little snippet that states:
    Code:
    $("img.current").css("top"," ");
    That explains it lol.

    That was a little comment I made before writing lol.

    Cheers kravitz problem is solved
  8. #5
  9. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,131
    Rep Power
    4304
    Congratulations on finding the problem.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  10. #6
  11. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115
    Originally Posted by Kravvitz
    Congratulations on finding the problem.
    Lol cheers! Its so easy to overlook things after a days work

IMN logo majestic logo threadwatch logo seochat tools logo