I'm working on Squarespace for a client that needs to add special blog post that are styled different.
The problems is that this template doesn't allow it and the client can't code, so I'm trying to do it with custom CSS in a way that prevents errors.
All this "special" post have a link with href that contains the word "special", so I'm styling them with the css selector:
[href*="Special"] { style }.
My question is if the client add more special post like "Special landscape", "Special Images", "Special theme" and so on, i can target them with:
[href*="Special+l"] { style }.
[href*="Special+I"] { style1 }.
[href*="Special+t"] { style2 }.
Is there a way to style them differently based on the href without needing to know the first letter of the second word?
Otherwise if the client put a different second word the style will not be applied.
I tried with nth-of-type() and so on but since each link are child of different blog's cards it doesn't work.
I hope explain myself :)
I think it is not possible the way you would have like it.
If you want to have different stylings for these links, for example:
// in blue
// in red
// in green
you need to know what is the second word of the link to give it a special styling.
ATM in your case you can have different styling for normal links, links with "special" in the href-attribute and links with "special-" plus more words in the href-attribute.
If you do not know the second word, all you can do is to prepare stylings for as many cases you can think of.
Another way COULD be, that you give your customer a list of special string combinations which you prepare to have an own styling if he uses them in the link.
// in blue
// in green
// in red
and in your CSS you have:
a[href*=c0000FF] {
color: blue;
}
a[href*=c00FF00] {
color: green;
} a[href*=cFF0000] {
color: red;
}
You can tell him to use these special strings if he wants to have his link in a special color. But this is 1. not really comfortable for him and 2. quite a strange look in the URLs.
Edit: and be sure not to use real words or strings that could be used in other links if you don't want them to be colored by mistake.
you can use href attr to select it
a[href*="http://abc.go.com"] {
color: #db4344;
}
link 1
Since you accepted the above answer, here is another way I think it could be better as am not sure appending color like that inside links is a good idea.
You can rely on CSS variable and do something like this:
a[href*=special] {
color: var(--c);
}
link 1
link 2
link 2
Or you can directly apply inline-style:
link 1
link 2
link 2
Or use data-attribute:
a[data-color="red"] {
color:red;
}
a[data-color="blue"] {
color:blue;
}
a[data-color="green"] {
color:green;
}
link 1
link 2
link 2
Related
I am working on a website, https://wordpress-625707-2032312.cloudwaysapps.com/, with the WP Shopify Plugin, and trying to change the default button colors. I have gone into dev tools and found the div class to change the button background. I can clearly see it's labeled as "wps-btn wps-btn-secondary wps-add-to-cart css-7k7g1c-buttonCSS-addToCartCSS-AddButton"
But when I use this class for my css changes, it doesn't work. The change is "wps-btn wps-btn-secondary wps-add-to-cart css-7k7g1c-buttonCSS-addToCartCSS-AddButton {
background-color: #D71614 !important;
}"
Why is this not working?? I can't attach screenshots since I'm too new on here...sorry!
Actually you are pretty lost here.
This is not actually a class:
wps-btn wps-btn-secondary wps-add-to-cart css-7k7g1c-buttonCSS-addToCartCSS-AddButton
There are 4 classes there, separated by spaces. The last one is actually unique for the first button. And in css, when you are styling a class, you should start with a dot, like: .class-name
The code you are looking for is:
.wps-btn.wps-btn-secondary.wps-add-to-cart {
background: red;
}
We concatenate 3 classes here with dots and NO spaces.
You should take a look at CSS Selectors:
https://www.w3schools.com/cssref/css_selectors.asp
We are building a prototype shop using Squarespace with the four pages:
Home, Store, About, Contact.
Unfortunately all pages inherit the same style from the site's design templates. What we would like to do is something similar to this where the colour of the link on certain pages could be changed.
Is there a method of overcoming the fact that the same class class="header-nav-item header-nav-item--collection"is being used for all pages in order for this type of solution using custom CSS can be applied?
Yes, this is possible. Using nth-child() selectors is an option, though you might consider referencing the element via its href attribute instead, like so (of course, substituting the color of your choice):
.header-nav-item a[href='/about'] {
color: red;
}
If you choose to use nth-child(), do like so:
.header-nav-item:nth-child(3) a {
color: red;
}
Finally, to edit the color of the nav item that corresponds to the active page (whatever page the user is on), you'd write something like:
.header-nav-item.header-nav-item--active a {
color: blue;
}
Finally, if you'd like to change the color of all navigation items when the user is on a specific page, you can do so by using the collection ID, which is used as the id attribute on the body element in most if not all Squarespace templates:
#collection-5d7ef2011673f45f239d1c51 .header-nav-item a {
color: green;
}
As a helpful tip (which you may already be aware of), you can use your browser's developer tools web inspector to inspect the element and then write your own CSS according to the rules generated by Squarespace.
I would like to change the colour of comments in the Atom editor. From a bit of googling, I found I can put the following in my .atom/styles.less file:
atom-text-editor::shadow .comment {
color: #ffffaa;
}
That's great - now I have bright yellow comments that demand to be noticed rather than fading into the background. The trouble is that it now looks like the below
As you can see, the text colour of the comments has changed, but the comment delimiters and links within comments remain in the default almost-invisible-grey, which looks a bit silly.
My questions are (1) how can I change the colour of these items, and more importantly (2) where can I look up how to change the colour of these items?
Please note that I am not a web programmer and know nothing of CSS or any related technologies. I am therefore looking for a fairly step-by-step solution, in contrast to solutions found, for example, in the answers to this question, which assume a substantial amount of background in the inner workings of this stuff.
Using 1.14.4:
// This styles comment text
atom-text-editor .syntax--comment {
color: #53FFA1;
}
// This styles comment punctuation (i.e. //, and /*...*/)
.syntax--punctuation.syntax--definition.syntax--comment {
color: #008C3F;
}
To find out the CSS classes of any element you want to style, follow these steps in the editor:
Use your cursor to highlight the element you want to inspect. I'm following your example of a double slash (i.e. a comment) here.
Press Ctrl+Alt+Shift+P (or Cmd+Alt+P on OS X). A pop-up will tell you all classes of that element. Usually, it's the last line of that notification that is of interest for us. For //, it is comment.line.double-slash.js.
Disregard the last dot and everything following it, since keeping it would apply your changes to a specific file type only (js in this case). Now prepend a dot. The remaining string is the element we want to style: .comment.line.double-slash.
Open the .atom/styles.less by opening the command pallette (Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on OSX) and searching for "Application: Open Your Stylesheet".
Append these lines to .atom/styles.less, if not already present:
atom-text-editor::shadow {
// custom comment styling goes here
}
Inside the brackets you can place CSS/LESS code for any element you want to customize.
atom-text-editor::shadow {
.comment.line.double-slash {
color: #ffffaa;
}
}
Additional advice: you can enumerate element identifiers as a comma-and-space-separated list, if the same changes should apply to them. So if you want to make links the same color as comments, there are two possibilities:
.comment.line.double-slash {
color: #ffffaa;
}
.markup.underline.link.hyperlink { // I removed the '.https' to apply this to all protocols
color: #ffffaa;
}
or
.comment.line.double-slash, .markup.underline.link.hyperlink {
color: #ffffaa;
}
With long class names as they are used here, I'd prefer the first option for readability. But that's up to your choice.
The syntax is changed in 1.14.
Now, you need to use this for changing the comment color
atom-text-editor .syntax--comment {
color: #228B22;
}
An update to #Hexaholic's now out-dated answer:
Find the CSS class of the element you want to style
Launch the Developer Tools window using Ctrl+Shift+i (Windows; command: window:toggle-dev-tools)
Activate the Element Inspector (Ctrl+Shift+C from within the developer tools window, or click the cursor icon)
Hover over the element you wish to style
Identify the appropriate style name: each style name begins with a dot and proceeds to the next dot. This example applies the styles .syntax--comment, .syntax--block and .syntax--bibtex.
Apply custom CSS
Open the custom stylesheet .atom/styles.less ("Application: Open Your Stylesheet" in the command finder (Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P, OSX)
Enter the appropriate CSS. For example, to colour all comments:
atom-text-editor .syntax--comment {
color: #ffffaa;
}
Or to colour all comments also tagged as bibtex:
atom-text-editor .syntax--comment.syntax--bibtex {
color: #ffffaa;
}
As usual with CSS, more specific comments (as the latter) will override more general classes (as the former).
Further reading
Atom's guide to Further Customization
I am using a WordPress premium theme that has a 25.000+ lines styles.css. I want to change the font and main color sitewide, and for this I would like to catch ALL classes and IDs that use them for my childtheme.
Manually searching through 25.000 lines and then selecting and copying the classes together is a very slow procedure, and I am sure this can be automated with RegEx and the preg match all thing or the like, but I know too little about creating such a script.
But at least I could figure out the logic that a script for such a task would need to follow.
So let's say I need a rule that collects ALL classes and IDs to which the font Roboto is assigned.
Basically it needs to
1. find Roboto, then
2. go back to the { and
3. collect everything before { until
4. the last } before, so it needs to go backwards searching
5. This it needs to do through the whole document, to catch all classes to which Roboto is assigned.
The result will be a very big list of comma-separated classes which I can then easily assign the new font to.
Does any of the RegEx experts see the string already in front of his eyes? I am sure it is not that difficult for someone who "speaks" RegEx fluently, but I got soon lost trying to learn it myself, I only succeeded in simple replacments.
...
last CSS rule ending here.
}
.some,
.classes,
.and,
#IDs to collect them all,
#not only from this one css rule,
. but from a whole 25.000+lines stylesheet
{
font-family: 'Roboto', sans-serif;
font-size: 32px;
color: ...
etc.
}
...
There is currently no way of targeting all classes with a specific CSS Rule like font-family either with CSS, JavaScript, or jQuery
But, you can do searches for:
'begins with..'
div[class^="something"] { } /* target divs */
*[class^="something"] { } /* targets everything */
div[id^="something"] { } /* target divs */
*[id^="something"] { } /* targets everything */
which would work on something like this:-
<div class="something-else-class"></div>
'contains..'
div[class*="something"] { }
which would work on
<div class="is-something-here"></div>
<!-- class name can be anything. "something" can be anywhere -->
'ends with...'
div[class$="something"] { }
which would work on
<div class="you-are-something"></div>
This way you can target all classes and/or id's that have a font-family Rule and change it.
Reference
CSS3 Attribute Selectors: Substring Matching
As the title says I would like to create a unique div ID for some class in css. Here is some examples:
http://prntscr.com/29rom4
These two blocks are using the same class in the wordpress' css. They are both named as td_block4.
http://prntscr.com/29rp81
Now I would like to create a unique div in the css file of the wordpress theme, where I can put a different background for each "block4".
Here is the example of what I actually want to do: prntscr.com/29rpvd (not a perfect improvisation) :)
And... when I put (in example):
.td_block4 {background-color:#000;}
...in the css, I get this: prntscr.com/29rqbh , and that's not what I want to get.
I hope I'm clear enough, how can I fix this?
Thanks in advance.
I think you can do that only via javascript.You can attack div data-image's with their background , and on load check it and write some js like ".css('background-image',dataimage)"
Take it easy
Your <div>s are surrounded by some more unique parents, so you can simply do:
.span6 .td_block4 { background-color: #f00; }
.span4 .td_block4 { background-color: #000; }
Sometimes, it's not about hooking onto a unique element you want, but by finding a way to use its parents to hook onto a common element, differentiated by unique parents.
Try jquery for this
$(document).ready(function(e) {
$('.td_block4:first').css('background-color','#000');
});
And you can use css for the rest