Can I set CSS values in jQuery depending on which document is active?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tdrsam
    New Member
    • May 2015
    • 97

    Can I set CSS values in jQuery depending on which document is active?

    I have some little icon images that are positioned nicely, but when I send the website to another page (other than the home page), the icons position differently. I'm guessing it's caused by the content on the page, but I'm wondering if I can just use JS to set different values for the positioning depending on which page the site is on.

    I can't find any information on that. Does anyone know?
  • computerfox
    Contributor
    • Mar 2010
    • 276

    #2
    Although you can definitely do this with JavaScript using the style.atrribute based on the id of the object, I would rather look over the dynamics in the CSS. It's better to do this via better dynamics in the stylesheet because then it would be set for all instances of the object on each page. Do you add extra objects on each page? That might also need to be looked at because most websites we see have at least the same structure. I wouldn't call it a template, but it's good to have consistency on the pages. What do you think?

    Comment

    • tdrsam
      New Member
      • May 2015
      • 97

      #3
      I agree, and I'm not sure what's causing this. It's only relevant to the mobile media query which is the first one in the css document. The icons are pretty close to the top of the screen and the problem only occurs when there's content added below the section where the icons are supposed to display. Maybe I should just position them with margins, seeing as though it's just a mobile screen. I could probably just use pixels to push them off the top and left without it being too much different for different screen sizes, rather than using absolute positioning with top and left properties.

      Comment

      • tdrsam
        New Member
        • May 2015
        • 97

        #4
        Wow, this is so embarrassing, but I'm going to post it just in case it helps someone in the future. It turns out that the reason the icons were displaying in different positions on different pages is that I'd forgotten to set the parent element to a relative position. Hehehe

        Comment

        • tdrsam
          New Member
          • May 2015
          • 97

          #5
          Actually, there were two problems. The 'top' values were set to percentages rather than pixels.

          Comment

          • computerfox
            Contributor
            • Mar 2010
            • 276

            #6
            Good job td!
            Very proud of you

            Comment

            Working...