Need help for making not blur text css [duplicate] - html

This question already has answers here:
How to apply a CSS filter to a background image
(22 answers)
Closed 5 months ago.
Is there any possible way to make text not blur (not changing the html code)
I want to make only background blurry and text not blurry.
My code looks like this
.background {
height: 400px;
background-image: url(photo);
background-repeat: no-repeat;
background-size: 100%;
background-position: center;
filter: blur(1px);
}
<div class="background">
Home
</div>

I moved the background image to an absolutely positioned pseudo element and gave it a negative z-index. I set the inset to 0 as a shorthand to cover the entire parent's dimensions. This allows the text to still be visible but not be part of the blur effect.
.background {
height: 400px;
position: relative;
}
.background:before {
content: '';
position: absolute;
inset: 0;
background-image: url("https://images.unsplash.com/photo-1659536002780-73275f63f11c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=900&q=60");
background-repeat: no-repeat;
background-size: 100%;
background-position: center;
filter: blur(2px);
z-index: -1;
}
#something {
color: white;
font-size: 2rem;
}
html, body {
margin: 0;
}
<div class="background">
Home
</div>

This is an approach to follow, especially if you don't want to change the html code as it is (code: https://jsfiddle.net/)
.background {
align-items: center;
display: flex;
justify-content: center;
height: 100%;
width: 100%;
background-color: rgba(255, 255, 255, 0.3);
border-radius: 5px;
-webkit-backdrop-filter: blur(20px);
backdrop-filter: blur(20px);
max-width: 50%;
max-height: 50%;
padding: 20px 40px;
}
html,
body {
height: 100%;
width: 100%;
}
body {
background-image: url(https://picsum.photos/id/1080/6858/4574), linear-gradient(rgb(219, 166, 166), rgb(0, 0, 172));
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}
<div class="background">
Home
</div>

Related

How to make background-image full-screen with html+css without scrollin on image

I want to create   background-image full-screen in HTML, and CSS but without scrolling   background-image doesn't to move up or down.
Any idea?
* {
margin: 0;
padding: 0;
}
img {
background-image: url("./Landing_Page_TBB.jpg");
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
background-size: cover;
height: 100%;
width: 100%;
}
<body>
<div class="background-image">
<img src="./Landing_Page_TBB.jpg" alt="">
</div>
</body>
Here is code what I have created.
You were in the right direction. Take a look at this:
background: url(mountain.jpg);
background-repeat: no-repeat;
background-size: auto;
You can test it here: https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_background-size
* {
margin: 0;
padding: 0;
}
.background-image {
background-image: url("https://i.pinimg.com/564x/0a/a8/bf/0aa8bfa73e2f93d3816b75bbd1b4a95a.jpg");
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
background-size: cover;
height: 100vh;
width: 100%;
}
<body>
<div class="background-image"></div>
</body>
Since you said that you'd like to display your image in the background in full screen mode and not scroll away, I would suggest the following:
.background-image {
position: fixed;
top: 50%;
left: 50%;
min-width: 100vw;
min-height: 100vh;
transform: translate(-50%, -50%);
z-index: -1;
}
.very-high-paragraph {
height: 1500px;
background-color: rgba(255, 255, 255, 0.5);
}
<img class="background-image" src="https://filesamples.com/samples/image/jpeg/sample_640%C3%97426.jpeg">
<h1>Hello World</h1>
<p class="very-high-paragraph">Lorem Ipsum</p>
But the better suited option would be to use the CSS property background-image and discard the <img /> tag you're currently using. I think you mixed up two things there.

Create a Fixed, Darker, Blurry Background Image, with Clear Text Elements [duplicate]

This question already has answers here:
How to apply a CSS filter to a background image
(22 answers)
Closed 2 years ago.
I am making a background image, making it darker and blurry. I also need to keep the texts all clear and unaffected by blurriness. I've written so many text already, and I am trying to figure out to bring them all back to clarity.
So far I have:
In HTML:
<body>
<div class="bg">
</div>
</body>
In CSS:
body, html {height: 100%; width:100%;}
.bg {
background-image: url("https://www.worldofhanszimmer.com/wp-content/uploads/2018/10/03_HansZimmer_Frank_Embacher_Berlin_print_klein-87.jpg");
filter: blur(3px);
-webkit-filter: blur(3px);
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
Help would be much appreciated.
I think that this would be what you were looking for:
https://css-tricks.com/apply-a-filter-to-a-background-image/
I have also provided a runnable code snippet for your convenience:
body {
height: 100vh;
padding: 0;
display: grid;
align-content: center;
justify-content: center;
}
.bg {
width: 300px;
height: 300px;
display: grid;
place-items: center;
color: white;
position: relative;
}
.bg::before {
content: "";
top: 0;
left: 0;
width: 100%;
height: 100%;
position: absolute;
background-image: url(https://www.worldofhanszimmer.com/wp-content/uploads/2018/10/03_HansZimmer_Frank_Embacher_Berlin_print_klein-87.jpg);
background-size: cover;
filter: blur(3px);
}
.module-inside {
position: relative;
font: bold 42px sans-serif;
}
<!DOCTYPE html>
<html>
<head>
<title>Title of the page</title>
</head>
<body>
<div class="bg">
<div class="module-inside">Content</div>
</div>
</body>
</html>
This will work:
Working example: https://jsbin.com/coduvusova/edit?html,css,output
HTML:
<div class="wrapper">
<div class="bg">
</div>
<div class="content">
<p>
This is the text...
</p>
</div>
</div>
CSS:
body,
html {
height: 100%;
width: 100%;
}
.wrapper {
position: relative;
}
.bg {
position: absolute;
min-height: 500px;
width: 100%;
background-image: url("https://www.worldofhanszimmer.com/wp-content/uploads/2018/10/03_HansZimmer_Frank_Embacher_Berlin_print_klein-87.jpg");
filter: blur(3px);
-webkit-filter: blur(3px);
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.content {
min-height: 500px;
display: flex;
justify-content: center;
align-items: center;
}
p {
background-color: red;
color: white;
padding: 5px 10px;
z-index: 2;
}
This might help
body, html {
height: 100%; margin: 0;font-family: Arial, Helvetica, sans-serif;}
.bg {
background-image: url("https://www.worldofhanszimmer.com/wp-content/uploads/2018/10/03_HansZimmer_Frank_Embacher_Berlin_print_klein-87.jpg");
filter: blur(8px);
-webkit-filter: blur(8px);
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.bg-text {
color: white;
font-weight: bold;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
width: 80%;
padding: 20px;
text-align: center;
}
<div class="bg"></div>
<div class="bg-text">
<h1>Your text</h1>
</div>

Transparent color of solid image? [duplicate]

This question already has answers here:
Semi-transparent color layer over background-image?
(19 answers)
Closed 2 years ago.
I am trying to have a large header where there is a background photo and then a solid color overtop it with a opacity of like 90%. (so you can barely see the photo).
This is basically what I have:
.bgoverlay {
background-image: url("https://i.pinimg.com/originals/06/51/e8/0651e8870431f9db3b26b1fd7615cec1.jpg");
}
.bgimg-1 {
background-position: center top;
background-repeat: no-repeat;
top: 0px;
background-size: 100%;
background-color: #053426;
min-height: 60%;
opacity: 0.9;
}
<header class="bgimg-1 bgoverlay"></header>
edit
Thank you everyone - adding the :before is so far working out nicely. Although, when it comes to responsive, is there a way to change the background size? I tried background-size but it isn't changing.
For example, if I have the min-height at 70% so the whole header takes up 3/4th of the page but then when I shrink it to mobile size the solid background color is revealed below and the photo is small and not large enough to cover the 71% min height.
Thanks
edit 2
nvm I ended up using an #media screen to just shrink the overall header on mobile and now it looks great. Thank you!
You can use a pseudo-element like :before.
First, add position: relative to the header element. Then, add the pseudo-element absolutely positioned with the color and opacity, occupying the whole width and height of its parent (header).
header {
width: 100%;
height: 300px;
}
.bgoverlay {
position: relative;
background-image: url("https://i.pinimg.com/originals/06/51/e8/0651e8870431f9db3b26b1fd7615cec1.jpg");
}
.bgimg-1 {
background-position: center top;
background-repeat: no-repeat;
top: 0px;
background-size: 100%;
min-height: 60%;
}
.bgoverlay:before {
content: '';
position: absolute;
height: 100%;
width: 100%;
left: 0;
top: 0;
opacity: 0.9;
background-color: #053426;
}
<header class="bgimg-1 bgoverlay"></header>
hope this help you.
.bgoverlay {
background-image: url("https://i.pinimg.com/originals/06/51/e8/0651e8870431f9db3b26b1fd7615cec1.jpg");
}
.bgimg-1 {
background-position: center top;
background-repeat: no-repeat;
top: 0px;
background-size: 100%;
min-height: 300px;
position: relative;
}
header.bgimg-1.bgoverlay:after {
content: '';
height: 100%;
width: 100%;
background: #000;
opacity: 0.9;
position: absolute;
}
<header class="bgimg-1 bgoverlay">
</header>
Use a really large inner box-shadow if the solution by Azametzin doesn't pan out for you (relative positioning might get tricky with your content). But please use their solution as a real one, and maybe mine as a fallback. It is a bit hacky after all.
header {
width: 100%;
height: 300px;
}
.bgoverlay {
position: relative;
background-image: url("https://i.pinimg.com/originals/06/51/e8/0651e8870431f9db3b26b1fd7615cec1.jpg");
box-shadow: inset 0 0 0 100vmax rgba(2, 20, 15, 0.9)
}
.bgimg-1 {
background-position: center top;
background-repeat: no-repeat;
top: 0px;
background-size: 100%;
min-height: 60%;
}
<header class="bgimg-1 bgoverlay"></header>

Background picture opacity for parallax scrolling

This might be a rookie question, but I can't find an answer anywhere. I'm writing a website with parallaxed background images and want to make said images a bit transparent as opposed to the text above them, which should be completely opaque. I followed w3school's model (with some changes) and it works considering that background image is defined in the parent container, so the text inherits the image's opacity, as seen in bgimg-2.
What I've tried to do, appart from fiddling with the stylesheet to no avail, is to create a new container section-img that encapsulates both the background and the text, so their styles don't overlap with each other. This, however, makes the image's (bgimg-1) height equal to 0.
Here's an MRE:
<!DOCTYPE html>
<html>
<style>
body, html {
height: 100%;
margin: 0;
background-color: #282828;
font-family: sans-serif;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.section-img {
position: relative;
min-height: 100%;
}
.bgimg-1 {
background-image: url("https://i.redd.it/v3wjcf1p59841.jpg");
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
opacity: 1;
z-index: -1;
}
.bgimg-2 {
position: relative;
opacity: 0.6;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-image: url("https://i.redd.it/o1a3xr4b39841.jpg");
min-height: 100%;
}
#title {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 100%;
text-align: center;
color: white;
font-size: 7vw;
letter-spacing: 2vw;
}
.section-text {
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 100%;
text-align: center;
font-weight: bold;
color: white;
letter-spacing: 2vw;
font-size: 3vw;
color: #f7f7f7;
}
</style>
<body>
<div class="section-img">
<div id="title">No background picture here!</div>
<div class="bgimg-1"></div>
</div>
<div class="bgimg-2">
<div class="section-text">I want different opacities :(</div>
</div>
</body>
</html>
What's the sanest way to achieve this difference in opacities for both items?
Why Don't you use "rgba" style(CSS input), "rgb" will set the colour of the background and the "a" command will set the opacity (transparency) of the image, it can be set between 0-1 where 0 is transparent(0% opacity) and 1 is 100% opacity. i hope this helps!!
.bgimg-1 {
background-image: url("https://i.redd.it/v3wjcf1p59841.jpg");
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
opacity: 1;
// z-index: -1; // you won't need this
// add position relative so that the ::before position absolute will be in relation to it's parent and not the body:
position:relative;
}
// .bgimg-2 { // don't need this div
.bgimg-1::before { // add this instead
// position: relative; // no this instead:
position: absolute;
top:0; left: 0; right: 0; bottom: 0;
// end this instead //
opacity: 0.6;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-image: url("https://i.redd.it/o1a3xr4b39841.jpg");
min-height: 100%;
}

How do I apply a CSS filter to ONLY the background image [duplicate]

This question already has answers here:
How to apply a CSS filter to a background image
(22 answers)
Closed 3 years ago.
I have a div tag with a background image that has some text text inside, I want to apply a filter to the background image without disrupting the texton the inside of the div layer. Is this possible? (This is my first post I hope I didn't layout anything incorrectly!)
.img_container{
box-sizing: border-box;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/a/a1/Mallard2.jpg");
background-size: contain;
width: 500px;
height: 380px;
filter: blur(2px);
color: #333;
text-align: center;
padding-top: 20%;
font-size: 20px;
}
<div class="img_container">
<div class="img_text"> I want to be clear! </div>
</div>
You can make use of the css pseudo element ::before
.img_container {
position: relative;
width: 500px;
height: 380px;
color: #333;
text-align: center;
padding-top: 20%;
font-size: 20px;
}
.img_container::before {
content: " ";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
box-sizing: border-box;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/a/a1/Mallard2.jpg");
background-size: contain;
background-repeat: no-repeat;
filter: blur(2px);
z-index: 0;
}
.img_text {
position: relative;
}
<div class="img_container">
<div class="img_text"> I want to be clear! </div>
</div>
::before with the content: " " creates a pseudo element before the div with class .img_text (use your browser inspect tool to see the element). This is the element we style and add a background to.
Note that you also have ::after pseudo element to add at the end.
Make them 2 seperate objects....
<div class="img_container">
</div>
<div class="img_text"> I want to be clear! </div>
.img_container{
box-sizing: border-box;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/a/a1/Mallard2.jpg");
background-size: contain;
width: 500px;
height: 380px;
filter: blur(2px);
color: #333;
text-align: center;
font-size: 20px;
position:relative;
z-index: 5;
}
.img_test {
position:absolute;
text-align:center;
width: 500px;
height: 380px;
z-index: 10;
top: 20%;
}