I'm trying to create an RGB additive color model on my website.
I'm using the following code:
#colorBox1 {
background-color: rgb(255, 0, 0);
}
#colorBox2 {
background-color: rgb(0, 255, 0);
mix-blend-mode: screen;
}
#colorBox3 {
background-color: rgb(0, 0, 255);
mix-blend-mode: screen;
}
#colorBox4 {
background-color: rgb(255, 255, 255);
border: 1px solid black;
}
<div id="color">
<div id="colorBox1" class="colorBox"></div>
<div id="colorBox2" class="colorBox"></div>
<div id="colorBox3" class="colorBox"></div>
<div id="colorBox4" class="colorBox"></div>
</div>
* I've skipped some of the positioning rules to make the code as clear as possible
So I was expecting the 3 colors to blend into white color of rgb(255, 255, 255). But when I preview the page the color is a little bit off-white. It is actually rgb(248, 255, 253). Although rgb(255, 255, 255) (colorBox4) does display as pure white of (255, 255, 255) - all via a color picker.
Is this it - css colors are different?
Is it just the monitor?
Or is there a CSS blending method or a chain of CSS blending methods where I can achieve "true" color additive mode?
I am not seeing the results you are. In this test the colors are correctly blended. How are you determining the color of the blended region?
.colorBox{
position:absolute;
width: 100px;
height: 100px;
border-radius: 50%;
}
#colorBox1 {
background-color: rgb(255,0,0);
}
#colorBox2 {
background-color: rgb(0, 255, 0);
mix-blend-mode: screen;
left: 70px;
}
#colorBox3 {
background-color: rgb(0, 0, 255);
mix-blend-mode: screen;
top: 70px;
left:40px;
}
<div id="color">
<div id = "colorBox1" class="colorBox"></div>
<div id = "colorBox2" class="colorBox"></div>
<div id = "colorBox3" class="colorBox"></div>
</div>
Related
.subtle {background-color: rgb(0,0,255); }
i can't get background color to be blue
For example, like this:
.subtle {
background-color: rgb(0, 0, 255);
height: 200px;
width: 200px;
color: #fff;
}
<div class="subtle">content</div>
Let's say I have a CSS variable:
div {
--test: "hey"
}
And I would like to check what is inside this variable and do something based on this.
For example:
if var(--test) == "Hi":
margin-left: 1rem;
else:
padding-bottom: 1rem;
natively isn't possible, but with a css compiler you can!
I suggest you use SASS/SCSS for this:
https://sass-lang.com/ (is a CSS compiler, that let you write CSS in a comfortable way, then compile it (translating it) to a CSS native)
for using IF/ELSE see these docs https://sass-lang.com/documentation/at-rules/control/if
I would like to check what is inside this variable and do something based on this.
Yes, you can check the value of a CSS Custom Property natively using:
window.getComputedStyle(myDiv).getPropertyValue('--test')
Once you know the value of --test, you can either update one (or several) properties:
myDiv.style.setProperty('padding-bottom', '1rem');
or you can add a class which updates one property (or any number of properties) of myDiv:
myDiv.classList.add('increaseBottomPadding');
Working Example:
const divs = document.querySelectorAll('div');
divs.forEach((div) => {
let testValue = window.getComputedStyle(div).getPropertyValue('--test');
switch (testValue) {
case ('rainbow1') : div.classList.add('background1'); break;
case ('rainbow2') : div.classList.add('background2'); break;
case ('rainbow3') : div.classList.add('background3'); break;
case ('rainbow4') : div.classList.add('background4'); break;
}
});
div {
display: inline-block;
float: left;
width: 120px;
height: 120px;
margin-right: 12px;
background-color: rgb(255, 0, 0);
border: 8px solid rgba(255, 255, 255, 0.5);
border-radius: 50%;
box-shadow: 0 0 12px rgba(0, 0, 0, 0.5);
}
.div1 {
--test: rainbow1;
}
.div2 {
--test: rainbow2;
}
.div3 {
--test: rainbow3;
}
.div4 {
--test: rainbow4;
}
.background1 {
background-color: rgb(255, 0, 0);
}
.background2 {
background-color: rgb(255, 127, 0);
}
.background3 {
background-color: rgb(255, 255, 0);
}
.background4 {
background-color: rgb(0, 127, 0);
}
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<div class="div4"></div>
I have a heading. On a desktop screen the heading is three lines, on a phone screen it is six lines.
The text is left aligned (not justified).
I want all lines of text to be 'underlined' and the line to be 100% of the width of the containing div (not the width of the text).
The line height is measured in ems. And at smaller break-points the font size is measured in vw.
I've tried created a repeating background-image linear-gradient, but because the line-height is measured in ems and I only want the underline to be 1px heigh, browsers are calculating the height of the underline to be less than 1px (see second image showing a border-top of 1px compared to the linear-gradient - both are rgb(255,255,255). Hence the underlines look very faint. And at smaller viewports are very hard to see.
Any suggestions?
html {
font-size: 62.5%;
}
.hero_image {
color: rgb(255, 255, 255);
background-color: rgb(0, 0, 0);
padding-bottom: 8rem;
max-width: 111.6rem;
}
.hero_image h1 {
font-size: 12rem;
line-height: 1.1em;
background-image: linear-gradient(to bottom, rgb(0, 0, 0) calc(1.1em - 1px), rgb(0, 220, 200) 1.1em);
background-repeat: repeat-y;
background-size: 100% 1.1em;
}
#media screen and (max-width:660px) {
html {
font-size: 56%;
}
.hero_image h1 {
font-size: 10vw;
}
}
<div class="hero_image">
<h1>XYZXYZ <br>fancy design agency for posh stuff</h1>
</div>
https://jsfiddle.net/4exgf7zs/1/
POSSIBLE SOLUTION
By adding in a third stop on the linear gradient it now seems to work. And increasing the line to 2px. Although I don't understand why?
background-image: linear-gradient(to bottom, black calc(1.1em - 2px), white calc(1.1em - 2px), white 1.1em);
While I couldn't exactly explain why this issue occurs, it can be avoided using repeating-linear-gradient over the whole element instead of a linear-gradient which gets tiled.
html {
font-size: 62.5%;
}
.hero_image {
color: rgb(255, 255, 255);
background-color: rgb(0, 0, 0);
padding-bottom: 8rem;
max-width: 111.6rem;
}
.hero_image h1 {
font-size: 12rem;
line-height: 1.1em;
background-image: repeating-linear-gradient(
to bottom,
rgb(0, 0, 0),
rgb(0, 0, 0) calc(1.1em - 1px),
rgb(0, 220, 200) calc(1.1em - 1px),
rgb(0, 220, 200) 1.1em
);
}
#media screen and (max-width:660px) {
html {
font-size: 56%;
}
.hero_image h1 {
font-size: 10vw;
}
}
<div class="hero_image">
<h1>XYZXYZ <br>fancy design agency for posh stuff</h1>
</div>
This solution seems to be causing some issues where a line may or may not appear below the last line, you might want to fiddle some more with it.
Let's say we have a list of classes storing background colors.
.bgr-red //background-color: rgb(255, 0, 0);
.bgr-green //background-color: rgb(0, 0 , 255);
.bgr-blue //background-color: rgb(0, 128, 0);
And we have a div using one of these classes.
<div class="bgr-red">...</div>
Is there any way that I can create a new set of classes which contain alpha channels? Something like this (I tried this method, it didn't work):
.alpha-90 //background-color: rgba(inherit, inherit, inherit, .9);
.alpha-80 //background-color: rgba(inherit, inherit, inherit, .8);
.alpha-70 //background-color: rgba(inherit, inherit, inherit, .7);
The end objective being to be able to place background color opacity into a div separate from the rest of the background color value? Creative a div something like this:
<div class="bgr-red alpha-80">...</div>
Thank you.
Use CSS variables:
.bgr-red {
background-color: rgba(255, 0, 0, var(--a, 1));
}
.bgr-green {
background-color: rgba(0, 0, 255, var(--a, 1));
}
.bgr-blue {
background-color: rgba(0, 128, 0, var(--a, 1));
}
.alpha-90 {
--a: 0.9;
}
.alpha-70 {
--a: 0.7;
}
.alpha-10 {
--a: 0.1;
}
<div class="bgr-red">...</div>
<div class="bgr-red alpha-70">...</div>
<div class="bgr-red alpha-10">...</div>
And for better support you can consider pseudo element to create the background layer and adjust opacity:
div {
position: relative;
z-index: 0;
}
div::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
}
.bgr-red::before {
background-color: rgb(255, 0, 0);
}
.bgr-green::before {
background-color: rgb(0, 0, 255);
}
.bgr-blue::before {
background-color: rgb(0, 128, 0);
}
.alpha-90::before {
opacity: 0.9;
}
.alpha-70::before {
opacity: 0.7;
}
.alpha-10::before {
opacity: 0.1;
}
<div class="bgr-red">...</div>
<div class="bgr-red alpha-70">...</div>
<div class="bgr-red alpha-10">...</div>
Im creating a CSS triangle, code:
display: block;
width: 0px;
height: 0px;
border-style: solid;
border-width: 0px 0px 9px 9px;
border-color: transparent transparent rgb(255, 255, 255);
position: absolute;
top: 14px;
left: 133px;
The problem is that this triangle is rendering a border in Firefox 16.0.2 while using windows 7.
Screen Shot of triangle in FF - There are two triangles, superior and inferior, creating the same shadow
I checked in MAC's FF and it does not show any border for the triangle.
The triangle displays correctly in Chrome, Safari, IE, Opera, MAC and Windows
Any idea why this is happening??
EDIT:
you can check it here: https://metrikstudios.com/want/fbapp/triangle-display.php The page displays the code shown above with a larger triangle
Try using rgba colours instead, like so:
border-color: rgba(255, 255, 255, 0) rgba(255, 255, 255, 0) rgb(255, 255, 255);
The default border colour is black, so maybe these borders are a weird transition artifact.
Instead of moving from invisible black to solid white, you'd be moving from invisible white to solid white.
Do you mean the fine line between the two triangles in my example?
.one {
width: 0;
height: 0;
border-style: solid;
border-width: 0px 0px 90px 90px;
border-color: transparent transparent rgb(0, 0, 0);
position: absolute;
}
.two {
width: 0;
height: 0;
border-style: solid;
border-width: 0px 0px 90px 90px;
border-color: transparent rgb(0, 0, 0) transparent;
position: absolute;
}
<div class="one"></div>
<div class="two"></div>
I see this line on every Browser on Win7 i have tested. I think it is rendered this way and you won't get rid of this. Fiddle