BEM hierarchy in stylus-lang and namespace - namespaces

Consider this html (written with BEM aproach):
<div class="app app--light">
<div class="longblockname longblockname--modifier">
<div class="longblockname__element">
...
</div>
</div>
</div>
I'm trying to find convenient and short stylus stylesheet for this and avoid repeating longblockname everywhere. I'll replace the real styles with simple color: #111, but in real case there're a lot of code:
I start with:
.longblockname
&__element
color #111
Then I want the block modifier to affect on the element:
.longblockname
&__element
color #111
&--modifier
// How to refer to &__element here?
// If I use &__element, it will compile to `.longblockname--modifier__element`
// But I need `.longblockname--modifier .longblockname__element`
I see 2 ways to achieve this:
Do not use line break:
.longblockname
&__element
color #111
&--modifier &__element
color #222
This will work, but if we want to use nested feature of stylus, is there any way to avoid ugly ^[-1] syntax like that:
.longblockname
&__element
color #111
&--modifier
& ^[-1]
&__element
color #222
Well, ok, probably that's just syntax preference, but for me it would be much nicer to have something like && to refer to the nested parent.
Then, there's the real question. Is there any way to declare css namespace in stylus? The whole application wrapped with the container that has app app--light style. I want this style to affect on everything within the container. I start with putting everything inside the .app-light:
.app--light
.longblockname
&__element
color #333
&--modifier
& ^[-1]__element
color #444
But this will not work because & ^[-1]__element compiles into .app-light .longblockname--modifier .app--light .longblockname__element while the correct syntax should be .app--light .longblockname--modifier .longblockname__element. I want .app--light to prepend any style declaration, but only the first time. Is there any way to do that?

You can do with Ranges in partial references to get only the selectors in the tree you want:
Stylus
.app--light
& .longblockname
&__element
color #333
&--modifier
& ^[1..1]__element
color #444
Output
.app--light .longblockname__element {
color: #333;
}
.app--light .longblockname--modifier .longblockname__element {
color: #444;
}

Related

Possible to use :hover with Foundation for Emails?

I'm designing an email newsletter using Foundation for Emails. I know that inlining a hover style doesn't really work. However, having hover styles would really add a nice touch to my newsletter. I'm wondering if Foundation found a way to make this work, and if there is anything I can do to get these styles in my email.
Yes, you can use :hover in the style sheet, global or specific:
a:hover, .linkname:hover {
background: #ff0000 !important;
border: 1px solid: #ff0000 !important;
}
Beyond that, in the SASS version, there's a section to declare all of your href values:
$anchor-text-decoration: none;
$anchor-color: $primary-color;
$anchor-color-visited: $anchor-color;
$anchor-color-hover: darken($primary-color, 10%);
$anchor-color-active: $anchor-color-hover;
You can modify: $anchor-color-hover: darken($primary-color, 10%); by adjusting the values or just putting in the color you wish to use instead.
Some email clients do not work with :hover, but many do:
https://www.campaignmonitor.com/css/selectors/hover/
Good luck.

Modifying Browser Root Color Palettes

Is it possible to change the root color palette of a browser on a certain page?
For example.
<div style="color:blue">Blue Text</>
color: blue => color:#0000FF (browser assume)
I want to tell the browser that "blue" is #0000BB. (either through stylesheet.css or javascript modifying its default palletes )
Plus, is it possible to add more standard color to the pallete?
Like: navyblue => #3e3e80
I'm not sure if it's possible to overwrite the root colour palette itself, but what you can do is make use of custom CSS properties to achieve almost the same thing.
Simply define the colours that you want in the :root, using -- as a prefix. You can then reference these colours by using var(--variable) as the color value.
This can be seen in the following:
:root {
--blue: #0000FF;
--navyblue: #3e3e80;
}
div {
color: var(--blue);
}
span {
color: var(--navyblue);
}
<div>Blue</div>
<span>Navy Blue</span>
Using CSS variables in this way allows you to easily change a colour throughout the entire site by only changing one line of code, and also allows for additional colours to be easily mapped out.

Why are my pseudo classes not being detected as valid syntax by Sublime Text?

I'm trying to take out all the underlines of my visited links on a website. In my CSS file, I put
nav li a:visited {
text-decoration: none;
}
And the term "visited" comes out as white text in Sublime Text, meaning the syntax is not recognized. I tried other pseudo classes too like
a:hover {
color: #FF00FF;
}
And the "hover" is also not recognized. All my other CSS rules are working, by the way. Am I missing something really obvious here?
That is the expected behaviour by default.
You can solve this by writing a custom color scheme or using an existing color scheme that colors the pseudo-class selectors the way you like.
There's no simple way to color the selectors. Extensive documentation on writing color schemes can be found here.

How do I change the color of the arrows?

I have this site:
http://dl.dg-site.com/
In this site we have a menu arrow gray colored ...
How can I change the color of the white arrows without modifying anything else?
I found this code here ... and do not change color but only arrow
header,
nav>ul ul,
#magic-line,
#topbar.announcement_bar_style_3,
#topbar.announcement_bar_style_2,
#topbar.announcement_bar_style_1,
.testimonial_small p,
.ABs_pricing-table-2 .ABs_pricebox_feature:last-of-type{
border-bottom-color:#969696 !important;
}
Can you help me to solve this problem?
Thanks in advance!
#magic-line {
border-bottom-color: #fff !important;
}
The !important declaration is required since to override the rule you've shown in your question. Generally you should avoid using !important.
I suspect this is an off-the-shelf WordPress theme though, and the rule you showed in your question is injected into the page by the theme, so you may not be able to edit it directly. In which case the !important will be required, and you will need to ensure that your new rule appears after the rule that sets the gray border color.
If for some reason you can't load your custom styles after the theme generated styles then you will need a rule that is more specific to ensure it takes precedence, e.g.
nav #magic-line {
border-bottom-color: #fff !important;
}

Theme CSS selection element conflict in Wordpress

I have edited my custom CSS to include ::selection{color: white; background: #2f3f58;} or multiple similar variations including copy/pasting and then editing code from W3Schools, W3C, stack overflow, and other sites. The code does nothing. I am using the http://alxmedia.se/themes/hueman/ Hueman theme and it has almost the exact same code that seemed to be working. So i copied this code into my custom CSS and edited it and that did not work either. Finally i disabled the theme CSS pertaining to selections. No matter what I do my selection color is the same red set in the theme options menu as a primary color. The hex for that red is not in the theme CSS however except in the commented out selection element that I am replacing. Is there any way to override the highlight color using CSS that is not the ::slection: element or am I using the element wrong?
the code is now
::selection {
color: white !important;
background-color: #2f3f58 !important;
}
much thanks to #citizenen and is wonderful suggestion
That's the right element for selection color. You can use the "!important" property to raise the specificity and force the style over others. Also use "background-color" instead of just "background". Try changing it to this:
::selection {
color: white !important;
background-color: #2f3f58 !important;
}
More on !important here: http://www.smashingmagazine.com/2010/11/02/the-important-css-declaration-how-and-when-to-use-it/
You are missing a closing brace in your CSS file (custom.css) that's preventing styles after that point from applying correctly. In the future, copy your code into a tool like Lint (http://csslint.net/) and it will find the errors for you.
Cheers!