I'm trying to put a gradient on a background image using this code
background: url('../img/newspaper.jpeg'),linear-gradient(to bottom right,#002f4b, #dc4225);
background-size: cover;
I'm getting the image but the gradient is not being applied
Add the gradient first and then add the image url, just like this:
background: linear-gradient(rgba(244, 67, 54, 0.95),
rgba(33, 150, 243, 0.75),
rgba(139, 195, 74, 0.75),
rgba(255, 87, 34, 0.95)),
url("http://placehold.it/200x200");
Or look at the snippet below:
.bg {
background: linear-gradient(
rgba(244, 67, 54, 0.45),
rgba(33, 150, 243, 0.25),
rgba(139, 195, 74, 0.25),
rgba(255, 87, 34, 0.45)),
url("http://placehold.it/200x200");
width: 200px;
height: 200px;
}
<div class="bg"></div>
Hope this helps!
div {
width: 350px;
height: 350px;
background: linear-gradient(to bottom right, rgba(0,47,75,.9), rgba(220,66,37,.9)), url(http://placehold.it/350x350);
background-size: cover;
}
<div></div>
do it in one line like below, I gave an example for that, see it
background-image: linear-gradient(to start-direction end-direction, color1, color2, url("imageUrl");
#hero {
height: 320px;
width: 100%;
background-image: linear-gradient(to right bottom, rgba(99, 102, 241, .9), rgba(219, 99, 139, .9)), url("https://i.picsum.photos/id/305/600/300.webp?hmac=QcFzy6dHM3Qs5MQwTjvnHEkSoTGAfg_VRgbH5g7pUQM");
background-size: cover;
}
<div id="hero"></div>
Related
I am working on a projekt where I need to check Sonar analyzis due to clean code and quality.
I face the following issue and have unfortunately no clue what is the problem.
I have the following CSS file:
/* progress bar IE */
progress {
color: #507311;
background: transparent;
border-radius: 2px;
border: solid 1px;
padding: 0px;
width: 160px;
height: 14px;
}
/* progress bar FF */
progress::-moz-progress-bar {
background-image: -moz-linear-gradient(center bottom, rgba(75, 108, 16, 1) 37%, rgba(134, 181, 29, 1) 69%);
}
/* progress bar Chrome */
progress::-webkit-progress-bar {
background: transparent;
}
progress::-webkit-progress-value {
background-image: -webkit-linear-gradient(bottom, rgba(75, 108, 16, 1) 37%, rgba(134, 181, 29, 1) 69%);
border-radius: 2px;
}
At -moz-progress-bar I got the following Sonar issue:
Unexpected nonstandard direction
I have tried the followings:
progress::-moz-progress-bar {
background-image: -moz-linear-gradient(to bottom, rgba(75, 108, 16, 1) 37%, rgba(134, 181, 29, 1) 69%);
}
and
progress::-moz-progress-bar {
background-image: -moz-linear-gradient(center bottom, rgba(75, 108, 16, 1) 37%, rgba(134, 181, 29, 1) 69%);
background-image: linear-gradient(to bottom, rgba(75, 108, 16, 1) 37%, rgba(134, 181, 29, 1) 69%);
}
They did not help.
Has anybody a clue what is wrong?
https://rules.sonarsource.com/css/RSPEC-4651
Header left and right side should display white and blue colors while body background-color grey.
White color for left side area with logo inside header and blue color for right one.
Using colorzilla, I've made background for the container1 horizontally half blue for the right side. Then I included a couple pseudo elements for razor-blade effect. And when I set background-color for body I realized that the area with my logo inside header colored with body color.
I read about linear-gradient but I was told that using it I'll face cross-browsing issues because even if you do it the way it should still there are a list of versions or even browsers that wouldn't understand it.
That's exactly where I find myself stuck. I need that all browsers and versions understood this code or as much as possible in this case. Please tell me how can I do that without using Colorzilla and linear-gradient.
#media only screen and (min-width: 900px) {
.container1 {
width: 100%;
margin: 0 auto;
/* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#1e5799+44,1e5799+44,7db9e8+45,1e5799+45,7db9e8+46,7db9e8+46,7db9e8+46,7db9e8+46,7db9e8+46,7db9e8+46,1e5799+46,7db9e8+50,1e5799+50,1e5799+100&0+44,0+46,1+47 */
background: -moz-linear-gradient(left, rgba(30, 87, 153, 0) 44%, rgba(30, 87, 153, 0) 45%, rgba(30, 87, 153, 0) 46%, rgba(30, 87, 153, 1) 47%, rgba(30, 87, 153, 1) 50%, rgba(30, 87, 153, 1) 100%);
/* FF3.6-15 */
background: -webkit-linear-gradient(left, rgba(30, 87, 153, 0) 44%, rgba(30, 87, 153, 0) 45%, rgba(30, 87, 153, 0) 46%, rgba(30, 87, 153, 1) 47%, rgba(30, 87, 153, 1) 50%, rgba(30, 87, 153, 1) 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, rgba(30, 87, 153, 0) 44%, rgba(30, 87, 153, 0) 45%, rgba(30, 87, 153, 0) 46%, rgba(30, 87, 153, 1) 47%, rgba(30, 87, 153, 1) 50%, rgba(30, 87, 153, 1) 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#001e5799', endColorstr='#1e5799', GradientType=1);
/* IE6-9 */
}
.logo {
width: 250px;
}
header {
display: flex;
justify-content: space-between;
padding: 0em 3.15em;
}
.cont {
position: relative;
}
.cont::before {
position: absolute;
content: '';
width: 40em;
height: 15rem;
background: blue;
bottom: -.8em;
z-index: -1;
}
.cont::before {
left: 42%;
transform: skew(-30deg);
}
.cont::after {
position: absolute;
content: '';
width: 1.6em;
height: 10rem;
background: green;
bottom: -.8em;
}
.cont::after {
left: 38.9%;
transform: skew(-30deg);
}
<div class="container1">
<div class="cont">
<header>
<img src="/images/logo.png" alt="O-Credit logo" class="logo">
<nav>
<div id="menu-bar" class="hide-desk">
<div class="menu" id="menu">
<div id="bar1" class="bar"></div>
<div id="bar2" class="bar"></div>
<div id="bar3" class="bar"></div>
</div>
</div>
<ul class="show-desk hide-mob" id="nav">
<li id="exit" class="exit-btn close hide-desk">
</li>
<li>Обрати позику</li>
<li>Компанії</li>
<li>Види позик</li>
<li>Блог</li>
<li></li>
</ul>
</nav>
</header>
</div>
</div>
Left side of header with logo to show background white. Right side of the same header to show background blue. And set Body to show background grey everywhere but header.
.header {
display: flex;
justify-content: space-between;
padding: 0em 3.15em;
background: linear-gradient(to right, blue 50%, red 50%)
}
How do I achieve a texture like this using CSS3 gradients?
The first background is easy using repeating-linear-gradient:
body {
height:100vh;
width:100vw;
background:repeating-linear-gradient(
to bottom,
#58D68D 0,
#58D68D 30px,
#2ECC71 30px,
#2ECC71 60px
);
}
The second background is much more complicated and should not be a CSS solution. I recommend to use a background-image instead!
It is not impossible to solve it with CSS (using perspective):
body {
transform: perspective(100em) rotateX(50deg) scale(2);
overflow:hidden;
}
div {
height:100vh;
width:100vw;
background:repeating-linear-gradient(
to bottom,
rgba(46, 204, 113, 0.5) 0,
rgba(46, 204, 113, 0.5) 30px,
rgba(88, 214, 141, 0.5) 30px,
rgba(88, 214, 141, 0.5) 60px
), repeating-linear-gradient(
to right,
rgba(46, 204, 113, 0.5) 0,
rgba(46, 204, 113, 0.5) 30px,
rgba(88, 214, 141, 0.5) 30px,
rgba(88, 214, 141, 0.5) 60px
);
}
<div></div>
Can anyone help me write the gradient CSS for the following image(without the text)?
This is the image:
You could use radial-gradient.
body, html {
width: 100%;
height: 100%;
margin: 0;
background: -webkit-radial-gradient(center, ellipse, #2D84A7 5%, #0D354E);
background: -moz-radial-gradient(center, ellipse, #2D84A7 5%, #0D354E);
background: radial-gradient(center, ellipse, #2D84A7 5%, #0D354E);
}
Exercise time
html, body {
height: 100%;
}
body {
margin: 0;
background: -moz-radial-gradient(circle, rgb(49, 139, 176), rgb(14, 70, 93));
background: -webkit-radial-gradient(circle, rgb(49, 139, 176), rgb(14, 70, 93));
background: radial-gradient(circle, rgb(49, 139, 176), rgb(14, 70, 93));
}
I am trying to do this
Using CSS, can you apply a gradient mask to fade to the background over text?
but I want to apply the gradient from top and bottom.
-webkit-mask-image: -webkit-gradient(linear, left 30%, left bottom, left top, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
http://jsfiddle.net/QZMyd/
but it doesn't work
Please test this demo in Chrome: http://jsfiddle.net/95vPC/5/
<div class="element">
<p>Lorem ipsum dolor sit … amet.</p>
</div>
* {
margin: 0px;
padding: 0px;
}
.element {
width: auto;
height: 300px;
overflow: hidden;
color: #fff;
background: #000045;
-webkit-mask-position: 0 0;
/*-webkit-mask-size: 200px 200px;*/
-webkit-mask-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(30, 87, 153, 0)), color-stop(19%, rgba(30, 87, 153, 0.66)), color-stop(29%, rgba(45, 70, 237, 1)), color-stop(100%, rgba(45, 70, 237, 0)));
}