- This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hi.
I can’t find a clear answer for this:
Can I style an element by its URL?
E.g.
<style>
[data-url-id=name-of-page] h1 {
color: Tomato !important;
}
</style>
I work lots with a template driven platform (Squarespace) where it is a pain to style an element in a specific way on a specific page, being able to target by URL would be a life-saver. But the above isn’t working.
Any thoughts appreciated…
Not really (AFAIK) the URL isn’t part of the DOM so there’s no element to be selected by the CSS.
Does SquareSpace give each page a unique class or ID? Then you could do it.
Hey.
Bummer. I thought that might be the case. Squarespace kind of sucks as they give elements weird IDs (like: id=”yui_3_17_2_3_1424765035111_2446″) that you can’t use because they change. But I’ll have a poke around and see if there’s a class or page ID I can specify that doesn’t change.
Thanks.
Yeah I’m 99.9% certain those “#yui_big_long_number” IDs are dynamic or something. They aren’t reliable.
For any other sad bastards like me who are trying to target specific elements in a Squarespace template (elements you have NOT necessarily created yourself) I believe it’s best to target specific elements with their #collection ID coming first. Each page <body> in Squarespace gets given its own #collection ID.
E.g.
<style>
#collection-54c80d1de1b051522508c579 .page-title {
color: Tomato;
}
</style>
This means you can style the page title (or whatever) in a unique way on a per-page basis. I hope this helps someone sometime…
I was able to style an element using its Data Url in Squarespace using:
<style>
[data-url-id=”intro”] .page-desc p{
color: Tomato;
}
</style>
Thanks for your last post also, the #collection ID worked great too.