Sass - lighten color without color reference - sass

I have a page here to illustrate my question
www.ttmt.org.uk/color
It's just blocks of color that have a base color and then I'm using sass to lighten and darken the colors form the center.
I have done it here by giving eavh div(color block) a class name and then referencing that name in the sass and lightening or darkening the base color.
It's a bit of sass so I was thinking is it possible to give lighten or darken a color without referencing that color in the sass statment
So instead of have
<div class="at-blue-lightest"></div>
//
at-blue{
background-color: $base-blue;
}
.at-blue-lightest{
background: lighten($base-blue, 30%);
}
I could have:
<div class="at-blue lightest"></div>
//
.at-blue{
background-color: $base-blue;
}
.lightest{
background: lighten( 30%);
}
So instead of referencing the color it would just lighten/darken what ever the color is.
This is all the sass
$base-blue: #267EC8;
$base-green: #00A504;
$base-red: #EA002A;
$base-gray: #aaaaaa;
.box{
height: 150px;
margin: 0 10px 10px 0;
width: 150px;
float: left;
}
.con{
overflow: auto;
}
.at-blue{
background-color: $base-blue;
}
.at-red{
background-color: $base-red;
}
.at-green{
background-color: $base-green;
}
.at-blue-lightest{
background: lighten($base-blue, 30%);
}
.at-blue-lighter{
background: lighten($base-blue, 20%);
}
.at-blue-light{
background: lighten($base-blue, 10%);
}
.at-blue-dark{
background: darken($base-blue, 10%);
}
.at-blue-darker{
background: darken($base-blue, 20%);
}
.at-blue-darkest{
background: darken($base-blue, 30%);
}
.at-red-lightest{
background: lighten($base-red, 30%);
}
.at-red-lighter{
background: lighten($base-red, 20%);
}
.at-red-light{
background: lighten($base-red, 10%);
}
.at-red-dark{
background: darken($base-red, 10%);
}
.at-red-darker{
background: darken($base-red, 20%);
}
.at-red-darkest{
background: darken($base-red, 30%);
}
.at-green-lightest{
background: lighten($base-green, 30%);
}
.at-green-lighter{
background: lighten($base-green, 20%);
}
.at-green-light{
background: lighten($base-green, 10%);
}
.at-green-dark{
background: darken($base-green, 10%);
}
.at-green-darker{
background: darken($base-green, 20%);
}
.at-green-darkest{
background: darken($base-, 30%);
}

Sass always compiles to CSS, so if there's no way that CSS can do it, neither can Sass. There's no way that CSS can know what's underneath a given element; since that depends on the HTML delivered to the page too.
However, you can just use CSS's more advanced color value specifications, which include semi-transparent functionality with RGBA and HSLA. For example:
background: rgba(255, 255, 255, .25);
is white that's 25% transparent. Thus it will lighten whatever is behind it by 25%.

background-color: darken($black-blue, 10%);

Related

Changing the button color after it is clicked

I would like to change the background colour of "After" to blue upon clicking, but no matter what it just doesn't show. I'm not sure what is wrong here in SCSS. Would really appreciate any advice!
Here's the JS Fiddle: https://jsfiddle.net/u1h9fe6v/
.grid-list {
--color: #f6f8ff;
--background: #2b3044;
--background-hover: green;
--background-active: blue;
padding: 6px 12px 6px 8px;
margin: 0;
display: flex;
outline: none;
position: relative;
border: none;
border-radius: 9px;
background: var(--b, var(--background));
cursor: pointer;
-webkit-appearence: none;
-webkit-tap-highlight-color: transparent;
transform: scale(var(--scale, 1)) translateZ(0);
}
.grid-list:active {
--scale: 0.95;
--background-active: blue;
}
.grid-list:hover {
--b: var(--background-hover);
}
It looks like you can set the background color in the
".grid-list.animation.active {" style. Like this ...
.grid-list.animation.active {
--span-name: text-active;
--dots-name: move;
--lines-name: scale;
--lines-duration: 0.15s;
--lines-delay: 0.3s;
background: blue;
}

Render comma separated selectors separately in SCSS

I'm trying to style progress bars using SCSS. To get this working in both Webkit and Gecko browsers I need to use both -webkit and -moz prefixes:
progress {
height: 50px;
-webkit-appearance: none;
appearance: none;
background: cyan;
&::-moz-progress-bar,
&::-webkit-progress-value {
background-color: orange;
}
&::-webkit-progress-bar {
background-color: cyan;
}
}
which renders to
progress {
height: 50px;
-webkit-appearance: none;
appearance: none;
background: cyan;
}
progress::-moz-progress-bar, progress::-webkit-progress-value {
background-color: orange;
}
progress::-webkit-progress-bar {
background-color: cyan;
}
This works great in Firefox, but Chrome doesn't seem to like it. Compare the following two implementations:
Comma separated selectors
progress {
height: 50px;
-webkit-appearance: none;
appearance: none;
background: cyan;
}
progress::-moz-progress-bar, progress::-webkit-progress-value {
background-color: orange;
}
progress::-webkit-progress-bar {
background-color: cyan;
}
<progress max="1" value="0.5"></progress>
Entirely separate declarations
progress {
height: 50px;
-webkit-appearance: none;
appearance: none;
background: cyan;
}
progress::-webkit-progress-value {
background-color: orange;
}
progress::-moz-progress-bar {
background-color: orange;
}
progress::-webkit-progress-bar {
background-color: cyan;
}
<progress max="1" value="0.5"></progress>
The above code snippets render in Firefox and Chrome as shown below
Firefox
Chrome
comma separated
separate declarations
It seems like the problem comes from rendering the CSS with vendor-specific pseudos in comma-separated lists. Is there any way to force the SASS processor to render each selector in a comma separated list as its own declaration?
It would be nice to not use mix-ins, but if it's the only way it's the only way.
Yes, you are able to do so! If you want to render SASS to seperate CSS rules simply divide the comma seperated list into two seperate rules. SASS keeps different rules seperate and will not wrap them together. Example:
// ### > SASS
xprogress {
height: 50px;
appearance: none;
background: cyan;
//## divide comma seperated selectors
//## into different rules
&::-moz-progress-bar {
background-color: orange;
}
&::-webkit-progress-value {
background-color: orange;
}
&::-webkit-progress-bar {
background-color: cyan;
}
}
// ### > compiles to css
progress {
height: 50px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: cyan;
}
//## when compiling CSS
//## different rules will survive
progress::-moz-progress-bar {
background-color: orange;
}
progress::-webkit-progress-value {
background-color: orange;
}
progress::-webkit-progress-bar {
background-color: cyan;
}

Scss parent selector, hover and active

I am very new to Scss and I am trying to have some logic whereby when I hover on the a element I get an underlying bar to appear and if I select that element in the nav menu the bar stays fixed.
I have the following, but I do not seem to correctly nest the active action:
nav {
max-width:100%;
background: lightblue;
ul{
background: yellow;
li {
background: yellow;
text-align: center;
a {
color: red;
display: inline-block;
}
&:hover { background: linear-gradient(to top, green 4px, transparent 0); }
&:active { background: linear-gradient(to top, green 4px, transparent 0); }
}
}
}
Is that how I correctly use hover and active on the a element? Can you help? I am rather confused about it.
Thank you,
P.
Your :hover and :active selectors are related to li element. You should put these rules to a section.
nav {
max-width:100%;
background: lightblue;
ul{
background: yellow;
li {
background: yellow;
text-align: center;
a { // <a> starts here
color: red;
display: inline-block;
&:hover {
background: linear-gradient(to top, green 4px, transparent 0);
}
&:active {
background: linear-gradient(to top, green 4px, transparent 0);
}
} // and ends here
}
}
}

SASS apply to only one style

Is there a way to have something like this:
.class1, .class2 {
background: green;
:not(.class1) {
//Only apply to .class2
background: red;
}
}
Compile to
.class1, .class2 { background: green; }
.class2 { background: red; }
Im trying not to have .class2 have its own separate style somewhere else.
No, it is only possible to be inclusive with Sass using nesting, not exclusive. Have you looked at the #extend directive?
%common-styles {
border: 1px solid;
}
.class1 {
#extend %common-styles;
background: green;
}
.class2 {
#extend %common-styles;
background: red;
}
Would compile to this (not sure on exact order here, don't have Sass available at the moment):
.class1 { background: green }
.class2 { background: red }
.class1, .class2 { border: 1px solid }
Obviously not the solution you are looking for, but it is the approach you would typically take with Sass. Is there a reason you can't keep the unique .class2 styling with the rest of the styles?
.class1, .class2 {
background: green;
}
.class2 {
background: red;
}
Alternately, you could do this:
.class2 {
background: red !important;
&, .class1 {
background: green;
}
}

coderay solarized

How I can add solarized-dark colors to coderay ?
I'm thinking about tweaking the alpha.rb file, but not sure which css class definitions substitute with which color code.
Any better ideas ?
Maybe there exist some out of the box solution ?
Found also this but not sure how to make usage of it.
The results of what follows are very close to the look of solarized but not perfect. Basically, I used this this stylesheet for solarize and went through selector by selector and did my best to translate it into the styles used by Coderay.
Here is the original solarized example for ruby:
Here is the results I am able to produce with coderay:
SO: it's not perfect, but will get anyone that wants to use a Solarized-like 'theme' for Coderay on their way.
Here is what you need to do (for a Rails 3 app):
First you will need to override the module within the coderay gem that it uses to generate inline styles. Create a file called coderay.rb within config/initializers.
Next paste in the following into the config/intializers/coderay.rb file you've just created:
module CodeRay
module Styles
# A colorful theme using CSS 3 colors (with alpha channel).
class Alpha < Style
register_for :alpha
code_background = '#073642'
numbers_background = 'hsl(180,65%,90%)'
border_color = '#c0c0c0'
normal_color = '#d5f6f6'
CSS_MAIN_STYLES = <<-MAIN # :nodoc:
.CodeRay {
background-color:##073642;
border:1px solid #c0c0c0;
background: #002B36;
color:#eee8d5;
}
.CodeRay pre {
margin: 0px;
}
span.CodeRay { white-space: pre; border: 0px; padding: 2px; }
table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; }
table.CodeRay td { padding: 2px 4px; vertical-align: top; }
.CodeRay .line-numbers {
background-color:#d5f6f6;
color:#808080;
text-align:right;
-webkit-user-select:none;
-moz-user-select:none;
user-select:none;
}
.CodeRay .line-numbers a {
background-color:#d5f6f6;
color:#808080;
text-decoration:none
}
.CodeRay .line-numbers a:target { color:#00f !important; }
.CodeRay .line-numbers .highlighted { color: red !important; }
.CodeRay .line-numbers .highlighted a { color: red !important; }
.CodeRay span.line-numbers { padding: 0px 4px; }
.CodeRay .line { display: block; float: left; width: 100%; }
.CodeRay .code { width: 100%; }
MAIN
TOKEN_COLORS = <<-'TOKENS'
.debug{color:#fff;background:#00f}
.annotation{color:#586E75}
.attribute-name{color:#93A1A1}
.attribute-value{color:#93A1A1}
.binary{color:#509}
.char .content{color:#d20}
.char .delimiter{color:#710}
.char{color:#2AA198}
.class{color:#268BD2;font-weight:bold}
.class-variable{color:#268BD2}
.color{color:#eee8d5}
.comment{color:#586E75}
.comment .char{color:#859900}
.comment .delimiter{color:#859900}
.complex{color:#a08}
.constant{color:#B58900;font-weight:bold}
.decorator{color:#268BD2}
.definition{color:#099;font-weight:bold}
.delimiter{color:#000}
.directive{color:#088;font-weight:bold}
.doc{color:#93A1A1}
.doc-string{color:#93A1A1;font-weight:bold}
.doctype{color:#DC322F}
.entity{color:#CB4B16;font-weight:bold}
.error{color:#93A1A1;background-color:#faa}
.escape{color:#CB4B16}
.exception{color:#CB4B16;font-weight:bold}
.float{color:#2AA198}
.function{color:#268BD2;font-weight:bold}
.global-variable{color:#268BD2}
.hex{color:#2AA198}
.imaginary{color:#f00}
.include{color:#b44;font-weight:bold}
.inline{background-color:transparent;color:#93A1A1!important}
.inline-delimiter{font-weight:bold;color:#DC322F}
.instance-variable{color:#268BD2}
.integer{color:#2AA198}
.key .char{color:#DC322F}
.key .delimiter{color:#268BD2}
.key{color:#859900}
.keyword{color:#859900;font-weight:bold}
.label{color:#93A1A1;font-weight:bold}
.local-variable{color:#268BD2}
.namespace{color:#859900;font-weight:bold}
.octal{color:#2AA198}
.operator, .predefined{color:#859900;font-weight:bold}
.predefined-constant{color:#2AA198}
.predefined-type{color:#DC322F;font-weight:bold}
.preprocessor{color:#859900}
.pseudo-class{color:#859900;font-weight:bold}
.regexp .content{color:#2AA198}
.regexp .delimiter{color:#DC322F}
.regexp .modifier{color:#CB4B16}
.regexp{background-color:transparent}
.reserved{color:#268BD2;font-weight:bold}
.shell .content{color:#2b2}
.shell .delimiter{color:#161}
.shell{background-color:transparent}
.string .char{color:#2AA198}
.string .content{color:#2AA198}
.string .delimiter{color:#DC322F}
.string .modifier{color:#2AA198}
.string{background-color:transparent}
.symbol .content{color:#2AA198}
.symbol .delimiter{color:#2AA198}
.symbol{color:#2AA198}
.tag{color: #268BD2}
.type{color:#DC322F;font-weight:bold}
.value{color:#268BD2}
.variable{color:#268BD2}
.insert{background:transparent}
.delete{background:transparent}
.change{color:#CB4B16;background:transparent}
.head{color:#CB4B16;background:transparent}
.head .filename{color:#CB4B16}
.delete .eyecatcher{background-color:rgba(255,0,0,0.2);border:1px solid rgba(230,0,0,0.5);margin:-1px;border-bottom:none;border-top-left-radius:5px;border-top-right-radius:5px}
.insert .eyecatcher{background-color:rgba(0,255,0,0.2);border:1px solid rgba(0,128,0,0.5);margin:-1px;border-top:none;border-bottom-left-radius:5px;border-bottom-right-radius:5px}
.insert .insert{color:#CB4B16;background:transparent;font-weight:bold}
.delete .delete{color:##2AA198;background:transparent;font-weight:bold}
.change .change{color:#CB4B16}
.head .head{color:#CB4B16}
TOKENS
end
end
end
You'll also add the following CSS to your application (or, if you want, make a file in assets/stylesheets called coderay.css for it):
pre {
background: #002A35!important;
color: #93A1A1!important;
}
The above will set your code background to the dark background used by solarize and any code not annotated by codeway to the fallback color used in solarize.
Now just restart your app.
** Again, this isn't perfect and youll probably want to crack open that coderay.rb file again at some point and refine things. You can use this to help with that: http://jsfiddle.net/bradleygriffith/CNTw4/ **

Resources