How to create a overlay gradient background? - html

I've been looking for some answers to solve that issue I've found while developing a webpage. I'm trying to create a overlay gradient background like these examples I found on the web:
http://meridianthemes-demo.net/the-traveler/
http://demo.themeruby.com/innovation_personal/
My code currently looks like this:
.image-bg{
width: 100%;
height: 100%;
margin: 0px;
background: url('../images/background.jpg') center center no-repeat;
background-size: cover;
background-attachment: fixed;
&:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-image: linear-gradient(to bottom right, #e2dce1, #e8d5e4);
opacity: .8;
}
}
<body class="image-bg">
<div class="container" id="main">
<div class="logo">
<h1>Background Overlay Image</h1>
</div> <!-- ./ logo -->
</div> <!-- ./Container -->
...
Any ideas of how to change that code to something similar to the themes I've mentioned above?
Thanks in advance!

Instead of using a gradient of solid colors with opacity on the element, you can create a gradient with rgba (red/green/blue/alpha) colors, where one side of the gradient can be semi-transparent while the other is opaque.
I modified your code to show how to pull this off.
Also, you had nesting in your CSS (&:before) which doesn't work in native CSS - only a preprocessor like SCSS. I formatted it to work below.
.image-bg {
width: 100%;
height: 100%;
margin: 0;
background: url('http://i.imgur.com/NRdrfQw.jpg') center center no-repeat;
background-size: cover;
background-attachment: fixed;
}
.image-bg::before {
content: '';
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 1));
z-index: -1;
}
.container {
height: 800px;
}
<body class="image-bg">
<div class="container" id="main">
<div class="logo">
<h1>Background Overlay Image</h1>
</div>
<!-- ./ logo -->
</div>
<!-- ./Container -->
</body>

You should use rgba for the background gradient rather than opacity. Opacity will make every element within the body inherit that opacity.
As you're going to the bottom right in your example, I rotated the gradient by 135 deg in my example below..
I would also suggest you apply a position:relative to the container as the gradient will overlay any content within the body. Unless that's the desired effect?
.image-bg {
width: 100%;
height: 100%;
margin: 0px;
background: url('http://lorempixel.com/output/nature-q-c-1313-1259-2.jpg') center center no-repeat;
background-size: cover;
background-attachment: fixed;
}
.image-bg:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: linear-gradient(135deg, rgba(226, 220, 225, 0.37) 0%, rgba(232, 213, 228, 1) 100%);
}
.container {
position: relative;
}
<body class="image-bg">
<div class="container" id="main">
<div class="logo">
<h1>Background Overlay Image</h1>
</div>
<!-- ./ logo -->
</div>
<!-- ./Container -->

Related

Why isn't backdrop-filter: blur() working properly?

I'm trying to implement this image:
Where, a div with text "Dog" is partially covering and blurring the image. So I tried this:
.profile {
background-image: url(https://townofbeekmantown.com/wp-content/uploads/2019/06/2-dog.jpg);
width: 250px;
height: 250px;
background-size: cover;
background-position: 0px;
}
.name {
position: absolute;
bottom: 0px;
left: 0px;
background-color: black;
color: white;
padding-top: 15px;
padding-bottom: 15px;
width: 100%;
opacity: 60%;
backdrop-filter: blur(10px); // should do the trick but not working??
}
<body class="profile">
<div class="name">Dog</div>
</body>
As you can see, although the div has the right color/opacity, it is not blurring the part of the image it covers.
If backdrop-filter is applied on <div class="name"></div>, then shouldn't it take affect on the element behind it (which is <body class="profile">)? I'm confused as to what I am doing wrong. If anyone can point me in the right direction, I would greatly appreciate it. Thanks!
This works for me:
Change <body class="profile"> to something like <div class="profile">.
<body> is a special HTML element.
Remove opacity: 0.6. It makes the entire element translucent which isn't what you want.
Instead, change the background-color to rgba( 0, 0, 0, 0.6 ) - then the backdrop will be partially visible through this semitransparent background.
Also, I replaced width: 100% with right: 0; as width: 100% will be affected by box-sizing: which will trip you up as you work on the textual content of your HTML.
You also need to add position: relative; to .profile so that the .name's position: absolute works.
.profile {
width: 250px;
height: 250px;
position: relative;
background-image: url("https://townofbeekmantown.com/wp-content/uploads/2019/06/2-dog.jpg");
background-size: cover;
background-position: 0px;
}
.name {
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding-top: 15px;
padding-bottom: 15px;
background: rgba( 0, 0, 0, 0.6 );
backdrop-filter: blur(10px);
color: white;
text-align: center;
}
<div>
<div class="profile">
<div class="name">Dog</div>
</div>
</div>
You could set a transparent background using RGBA instead of using opacity to have the blur effect on the background. Also note that you are using an invalid order of HTML code.
The order is as follow:
<html>
<head>
<!-- All meta tags -->
</head>
<body>
<!-- All your elements such as divs, navs etc.. -->
</body>
</html>
So if we take your code, you would have something like this:
background-color: rgba(0,0,0,0.55);
backdrop-filter: blur(10px);
! For the sake of demonstration, I added position: relative to the profile class, this ensures your name element stays inside of the box. Remove that line if you are planning to copy the code below or don't want to have this.
.profile {
background: url(https://townofbeekmantown.com/wp-content/uploads/2019/06/2-dog.jpg);
width: 250px;
height: 250px;
background-size: cover;
background-position: 0px;
position: relative;
}
.name {
position: absolute;
bottom: 0px;
left: 0px;
background-color: rgba(0,0,0,0.55);
color: white;
padding-top: 15px;
padding-bottom: 15px;
width: 100%;
text-align: center;
backdrop-filter: blur(15px); // should do the trick but not working??
}
<div class="profile">
<div class="name">Dog</div>
</div>

Color on background image not placing

I have been trying to place a transparent color on background image. The background image is working fine but the color is not placing.
I saw that the same question asked before. In my below code, I followed the same suggestion but not working for me.
How can I solve it?
body, html {
height: 100%;
margin: 0;
color:white;
background-image: url("../logo/background/1(2).jpg");
background-color: rgba(255,255,255, 0.5);
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
To create an overlay effect, you can use linear-gradient property in background
body,
html {
height: 100%;
margin: 0;
background: linear-gradient(0deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5)), url(https://www.freecodecamp.org/news/content/images/2021/06/w-qjCHPZbeXCQ-unsplash.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
<body></body>
The background image is working fine but the color is not placing.
Yes because your background color is overlapped by background image.
To get a transparent layer over the image use the following code -
CSS
.background {
background:url('..');
position: relative;
}
.layer {
background-color: rgba(248, 247, 216, 0.7);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Also define width and height for background class.
HTML
<div class="background">
<div class="layer">
</div>
</div>

How to add a backdrop blur filter as a gradient

I am trying to achieve a backdrop blur effect that using a gradient. I have been able to apply the blur but not make it have a gradient. I am using Tailwind so any help with using those classes would be great.
This is the result I am looking for (or something close to it), where line isn't harsh.
Here is an example using plain CSS.
.content {
position: relative;
width: 800px;
height: 420px;
display: flex;
align-items: flex-end;
}
img {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.overlay {
width: 100%;
-webkit-backdrop-filter: blur(20px);
height: 200px;
z-index: 10;
position: relative;
}
p {
text-align: center;
font-size: 18px;
}
<div class="content">
<img width="800" src="https://149351115.v2.pressablecdn.com/wp-content/uploads/2021/03/121220-Stackoverflow-Motivation-Alex-Francis-2048x1075.jpg" />
<div class="overlay">
<p>hello world</p>
</div>
</div>
I was able to solve this by adding a mask to the div.
-webkit-mask: -webkit-gradient(
linear,
left 45%,
left 0%,
from(rgba(0, 0, 0, 1)),
to(rgba(0, 0, 0, 0))
);
Thanks to Temani Afif for the suggestion.

How to Overlay Image on Background in Twitter Bootstrap Section

I have an image that I would like to overlay on top of a background gradient that I have set on a section element. Both the background gradient and image I am setting in CSS and calling via a class in HTML. Originally when just using the background gradient it worked fine, but after adding the image to place over the background gradient the background gradient disappeared?
.banner-gradient {
background: radial-gradient(circle, #ba000b, #9e0008);
color: white;
z-index: 0;
}
.banner-overlay {
background: url("../imagery/image.png");
max-width: 100%;
height: auto;
background-position: bottom;
background-repeat: repeat-x;
z-index: 1;
}
.section-align-center {
text-align: center;
}
<section class="banner-gradient banner-overlay section-align-center">
<div class="container">
<p>image over background gradient</p>
</div>
</section>
Try using background-image instead of background for image.
.banner-gradient:before {
content: " ";
width: 100%;
height: 100%;
position: absolute;
z-index: 1;
top: 0;
left: 0;
background: -webkit-radial-gradient(top center, ellipse cover, rgba(255,255,255,0.2) 0%,rgba(0,0,0,0.5) 100%);
}
.banner-overlay {
background: url('https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a') repeat;
}
.section-align-center {
height: 400px;
position: relative;
}
<section class="banner-gradient banner-overlay section-align-center">
<div class="container">
<p>image over background gradient</p>
</div>
</section>
I solved this with the help of this post. You must first place the banner-gradient in your outer div then in your inner div use banner-image.
HTML
<section class="banner-gradient section-align-center">
<div class="container banner-overlay">
<p>image over background gradient</p>
</div>
I would rather edit the class of the element you want the transparency in
<div class="background">
<div class="transbox">
<p>This is some text that is placed in the transparent box.</p>
</div>
</div>
div.background {
background: url('https://www.w3schools.com/css/klematis.jpg') repeat;
border: 2px solid black;
}
div.transbox {
margin: 30px;
background-color: #ffffff;
border: 1px solid black;
opacity: 0.6;
filter: alpha(opacity=60); /* For IE8 and earlier */
}
div.transbox p {
margin: 5%;
font-weight: bold;
color: #000000;
}
https://jsfiddle.net/mergatroid/xkmyqjec/1/

How can I position my logo correctly?

EDIT:
The chat window should be aligned to the right, with the chat area within the chat window, like this, why isn't it?: Codepen
Should be this:
I'm looking to make a simple site with a header and a rectangle on the side. For some reason, I cannot position my logo correctly! What I currently have:
html,
body {
background-color: #333;
margin: 0;
padding: 0;
}
#overlay {
position: absolute;
width: 100%;
height: 100%;
opacity: 0.2;
background: #ccc;
background: -webkit-linear-gradient(right top, #8900AB, #282828);
background: -o-linear-gradient(top right, #8900AB, #282828);
background: -moz-linear-gradient(top right, #8900AB, #282828);
background: linear-gradient(to top right, #8900AB, #282828);
}
#header {
position: absolute;
background: #404040;
width: 100%;
height: 10%;
}
#logo {
position: absolute;
background-image: url(http://csgovoid.net/img/logo.png);
background-repeat: no-repeat;
background-size: contain;
}
<html>
<body>
<div id="overlay"></div>
<div id="header">
<div id="logo"></div>
</div>
<div id="Seperator_H01"></div>
<div id="chat_extended">
<div id="chat_area"></div>
<input id="chat_input" type="text" placeholder="Chat...">
<button id="send_button" onClick="send()">SEND</buttton>
</div>
<div id="Seperator_V01"></div>
</body>
</html>
CodePen
What I'm trying to achieve:
(The text input and send button aren't included in the picture.)
It looks like you need to add a width and height :) A div has a height and width of zero by default, and since there is nothing in there you need to set it!
you need to add img tag;
<div id="logo">
<img src="http://csgovoid.net/img/logo.png">
</div>
and add following css:
#logo img{
width:2%;
//background stuff is removed -- not required in this case
}
#chat_extended
{ text-align:center;
padding-top:5%;
}
#header {
position: absolute;
background: #404040;
width: 100%;
//height is removed -- not required
}
Here is a fiddle : https://jsfiddle.net/5odd0q1n/
CSS :
html,
body {
background-color: #333;
margin: 0;
padding: 0;
width:100%;
height:100%;
}
#overlay {
position: absolute;
width: 100%;
height: 100%;
opacity: 0.2;
background: #ccc;
background: -webkit-linear-gradient(right top, #8900AB, #282828);
background: -o-linear-gradient(top right, #8900AB, #282828);
background: -moz-linear-gradient(top right, #8900AB, #282828);
background: linear-gradient(to top right, #8900AB, #282828);
}
#header {
position: absolute;
background: #404040;
width: 100%;
height: 10%;
}
#logo {
position: relative;
background-image: url(http://csgovoid.net/img/logo.png);
background-repeat: no-repeat;
background-size: contain;
height:100%;
}
HTML : (you had a typo in </button>)
<html>
<body>
<div id="overlay"></div>
<div id="header">
<div id="logo"></div>
</div>
<div id="Seperator_H01"></div>
<div id="chat_extended">
<div id="chat_area"></div>
<input id="chat_input" type="text" placeholder="Chat...">
<button id="send_button" onClick="send()">SEND</button>
</div>
<div id="Seperator_V01"></div>
</body>
</html>
Absoulute position is not good for responsivnes becuse you can't get a width or a height relative to parrent using css only :)
Anyways you asked for border line on the header : https://jsfiddle.net/5odd0q1n/3/ (you can find it here)
you only need to add
border-bottom: 10px solid purple ;
to your #header :)