By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,208 Members | 1,456 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,208 IT Pros & Developers. It's quick & easy.

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

P: 97
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?
Jun 18 '15 #1
Share this Question
Share on Google+
5 Replies

P: 278
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?
Jun 18 '15 #2

P: 97
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.
Jun 18 '15 #3

P: 97
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
Jun 19 '15 #4

P: 97
Actually, there were two problems. The 'top' values were set to percentages rather than pixels.
Jun 19 '15 #5

P: 278
Good job td!
Very proud of you
Jun 20 '15 #6

Post your reply

Sign in to post your reply or Sign up for a free account.