I am using the carousel component from bootstrap and also want to use the CSS blend-mode background-blend-mode: multiply; for the caption.
Unfortunately, the blend mode doesn't work.
The code is the following:
<div class="carousel-inner" role="listbox">
<div class="item">
<div class="carousel-caption">
CAPTION CONTENT
</div>
<img src="imgage.png" class="img-responsive" />
</div>
</div>
The CSS is the following:
.carousel-caption {
background-color: rgba(0, 119, 137, 0.7);
background-blend-mode: multiply;
}
Is this the wrong way?
If you want to blend an element over another, the property that you should use is mix-blend-mode.
It has the same syntax that background-blend-mode, but this one applies only to the in-element backgrounds (as M.Doye says)
You would need to assign the background-image property to same selector that you assigning background-blend-mode. So this may not work in your case.
From the Docs
The background-blend-mode CSS property describes how the element's
background images should blend with each other and the element's
background color.
Syntax Example:
.blended {
background-image: url(face.jpg);
background-color: red;
background-blend-mode: multiply;
}
Along with multiply you can also use: screen, overlay, darken, lighten, color-dodge, color-burn, hard-light, soft-light, difference, exclusion, hue, saturation, color, and luminosity. And also normal
Source
In order for your code to work, you need to add a background image to the element. So your code should look like this:
.carousel-caption {
background-image: url('image.png');
background-color: rgba(0, 119, 137, 0.7);
background-blend-mode: multiply;
}
There is a great article here you can check out, that gives a further explanation of the blend mode property.
Related
I'm using background and background-color to style the background with a gradient.
If I write only background I can see the gradient:
background: linear-gradient(35deg, #CCFFFF,#FFCCCC);
but if I write background-color I can't see it:
background-color:linear-gradient(35deg, #CCFFFF,#FFCCCC);
What could be the problem?
Because gradient kind of background isn't a color, but an image.
See the example bellow: https://jsfiddle.net/jpavnk71/4/
HTML:
<div class="color">background-color:linear-gradient(35deg, #CCFFFF,#FFCCCC);</div>
<div class="wrong">background:linear-gradient(35deg, #CCFFFF,#FFCCCC);</div>
<div class="image">background-image:linear-gradient(35deg, #CCFFFF,#FFCCCC);</div>
CSS:
div{
height:100px;
line-height:100px
}
.wrong{background:linear-gradient(35deg,#CCFFFF,#FFCCCC);}
.color{background-color:linear-gradient(35deg,#CCFFFF,#FFCCCC);}
.image{background-image:linear-gradient(35deg,#FFCCCC,#CCFFFF);}
Linear-gradient is handled like an image so you can write:
background:linear-gradient(35deg, #CCFFFF,#FFCCCC);
OR
background-image:linear-gradient(35deg, #CCFFFF,#FFCCCC);
I am using Webpack to load an image to use as a background image. When I apply it using CSS, the div takes on any property I give it other than a background image..
.cover {
background-image: url(../assets/images/childcarer_background.jpg);
background-size: cover;
min-height:500px;
}
<body>
<div class="container-fluid">
<div class="row">
<div class="cover">
</div>
</div>
</div>
<script src="homepage.js"></script>
</body>
When I inspect this in Chrome dev tools, the image is being loaded (I can access it directly) and if I copy the style from the .cover and apply it to element.style within Developer Tools, the style is applied as expected..
It will even overwrite the style when I apply it directly to the element...
This works, but obviously isn't sustainable.
If I inline the style, it works..
<div class="row" style="background-image:url(2769a294377fdc1af5fa011c9bedc6a0.jpg);">
<div class="container">
</div>
</div>
but if I try to make the stylesheet background !important...
It overwrites the background image with a blank background!
Why is this happening?
Try adding !important to your background element. So...
.cover {
background-image: url(../assets/images/childcarer_background.jpg) !important;
background-size: cover;
min-height:500px;
}
try but eliminating space between the colon and url. no space should solve it.
.cover {
background-image:url(../assets/images/childcarer_background.jpg) !important;
I tried to use a code from codepen.io to make my background switching. But after adding the code into my CSS file, the colors of the images and text is switching, and the background doesn´t change at all.
I placed the code for the body element.
How can I fix my site, so that it shows only the background color switching?
<html>
<head>
<link rel='stylesheet' id='child-theme-css' href='http://vocaloid.de/wp-content/themes/Vuturize/style.css?ver=2.1.2' type='text/css' media='all' />
</head>
<body class="home blog logged-in header-full-width full-width-content" itemscope="itemscope" itemtype="http://schema.org/WebPage">
<div class="site-container">
<div class="site-inner">
<div class="one-half start postpreview">
<img width="750" height="256" src="http://vocaloid.de/wp-content/uploads/2015/02/KAITO-6th-anniversary-2015-Project-DIVA-Arcade-Diamond-Dust-750x256.jpg" class="attachment-Beitragsbild wp-post-image" alt="KAITO 6th anniversary 2015 Project DIVA Arcade Diamond Dust"
/>
<h2 class="entry-title" itemprop="headline">TEST</h2>
</div>
<div class="soc fb">Facebook
</div>
<div class="soc tw">Twitter
</div>
</div></div>
</body>
</html>
The problem is that, in order to animate the background, you animate the filter property. But that property affects all content, not only the background, so the text color also changes.
Instead, you could animate background-image. But there is a problem: the spec defines background-image as non-animatable. However, webkit supports it.
It would help if you posted the CSS as well, but I will go ahead and try to answer the question.
One option is to make sure you only target the background-color inside of your #keyframes hue like so:
#keyframes hue {
/*hue will animate from 0 to 360. Saturation and Lightness remain constant*/
20% {background-color: hsl(72, 100%, 50%);}
40% {background-color: hsl(144, 100%, 50%);}
60% {background-color: hsl(216, 100%, 50%);}
80% {background-color: hsl(288, 100%, 50%);}
100% {background-color: hsl(360, 100%, 50%);}
}
view this example here
If you are strictly using the code from this codepen.io then the trick is to style the text/ images after your background animation like this:
a {
color: #ffff !important;
}
img {
background: none !important;
}
Which is not recommended because use of !important is considered a temporary fix and not good CSS practice.
This could be happening because you might be changing the color instead of the background-color.
I am trying to achieve the effect of having my text solid, nothing shows through, but the background color of the element holding the text, to be with opacity (o.5 for example).
I am currently do it with one element on top of the other.
Am wondering if there is a way to do it with only one element.
<div class="body">
here be a background image
<div class="title"> TITLE WITH FAINT WHITE BACKGROUND</div>
</div>
You can use rgba to define the color which supports alpha.
.title{
color:black;
background-color:rgba(255,255,255,0.5);
}
Support for this feature: http://caniuse.com/#search=rgba
Full sample
.body{
height:200px;
width:100%;
background:url('http://lorempixel.com/500/200/abstract/1');
}
.title{
color:black;
background-color:rgba(255,255,255,0.5);
}
<div class="body">
<div class="title">TITLE WITH FAINT WHITE BACKGROUND</div>
</div>
To achieve this in a single element, you need to set the rgba color as the first image, so that it will be rendered above.
And this makes impossible to set it as color, you need an image.
The 2 posibilities to achieve this are image() and linear-gradient:
.test {
background-image: image(rgba(0,0,255,.5)), url("http://placekitten.com/800/600");
}
.test {
background-image: linear-gradient(0deg, rgba(255,255,255,.5), rgba(255,255,255,.5)), url("http://placekitten.com/1000/800");
}
<div class="test">TEST</div>
However, the first one is valid CSS as the spec, but as far as I know it is not supported by any browser
w3c reference
I need to make div, which will have for example opacity:0.5, an inside of this will be another div, which won´t be transparent. I can´t figure this out. Even if I set z-index of inner div higher than the outter div, it´s still everything transparent. Now I got it like this:
<div id="outter" style="opacity:0.5; z-index:-1">
<div id="inner" style="opacity:1; z-index:1">
<img src="someImg.jpg" />
</div>
</div>
Try this
<div id="outter" style="background-color: rgba(255, 255, 255, 0.5);">
<div id="inner" style="opacity:1; z-index:1">
<img src="Your image" />
</div>
</div>
Opacity inheritance is quite finicky. You could try hack your way around it, or use rgba() on #outer (remove opacity and z-index)
Like:
#outter { background: rgba(0, 0, 0, 0.5); }
Similar quesition
opacity is inherited by all children, so it's not so useful in this scenario. A better option is to use rgba colors. So, for example, you could set the colors of the outer div to
.outer {background: rgba(0,0,0,0.1);}
... and so on.
The only other option—if you are determined to stick with opacity—is to place the inner div outside of the container and reposition it over the top of the .outer div. (You would need to wrap them both in another container with position: relative to do that, and then position the inner div absolutely in relation to it.)