I'm trying to give an hover effect to a div (a background picture) with the "filter" property. But it has got an influence on another div (my text) which is supposed to be over.
I applied the z-index property (without forgetting the position of my divs) but it doesn't work. You'll see, my text is blurring too and is not supposed to. Could you tell me please what's wrong with my code ?
Here is the codepen showing my problem : https://codepen.io/Gillian-D/pen/qmqEQy
HTML
<div class="container">
<div class="row">
<div class="col-sm-6 left_part-padding">
<div class="left_part">
<div class="left_part_content">
Left part
</div>
</div>
</div>
</div>
CSS
.container {
margin-right: auto;
margin-left: auto;
}
.left_part {
height: 40vh;
position: relative;
z-index: 0;
background-image: url(img/book2.jpeg);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
background-color: #000;
box-shadow: 0 50px 60px 0 rgba(0,0,0,.35);
border-radius: 10px;
}
.left_part:hover {
-webkit-filter: blur(5px);
filter: blur(5px);
-webkit-transition: .5s ease-in-out;
position: relative;
z-index:0;
}
.left_part_content:hover {
color: #fed136;
position: relative;
z-index: 2;
}
.left_part-padding, .right_part-padding, .bottom_part-padding {
padding-left: 10px;
padding-right: 10px;
}
.left_part_content {
color: white;
font-family: "Raleway", Helvetica, Arial, sans-serif;
text-transform: uppercase;
font-size: 1.2rem;
font-weight: 400;
letter-spacing: .300em;
margin-right: -.300em;
text-align: center;
vertical-align: middle;
line-height: 40vh;
position: relative;
z-index: 2;
}
Thanks a lot!
When you add an effect on an element, in most cases their children gets affected as well, so in this case, you could use a pseudo element for the background-image
Updated codepen
Changed CSS rules
.left_part {
height: 40vh;
position: relative;
background-color: #000;
box-shadow: 0 50px 60px 0 rgba(0,0,0,.35);
border-radius: 10px;
}
.left_part::before {
content: '';
position: absolute;
top: 0; left: 0;
width: 100%;
height: 100%;
background-image: url(http://lorempixel.com/500/200/nature/1/);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
background-color: #000;
border-radius: 10px;
}
.left_part:hover::before {
-webkit-filter: blur(5px);
filter: blur(5px);
}
Have a look here:
https://codepen.io/anon/pen/EmNPVZ
I took the text part element out of the to-be-blurred background div, now both have the same parent. Next I solved the centering differently, the usual way (absolute position, top and left 50%, transform: translate(-50%, -50%). I then applied pointer-events: none; to the text layer so the hover below it could word. And I added a different hover rule that affects the text - see my codepen. HTH
Related
Do you maybe know how (and if) I can add an opacity for the background image but only to PART of it?
The effect should be like this one: https://i.stack.imgur.com/HYvaU.png.
I have only added the image as a background but I cannot find any solution for this oppacity.
My HTML:
<header>
<img src="images/logo.svg" />
<h1>A history of everything you copy</h1>
<p>
Clipboard allows you to track and organize everything you copy.
Instantly access your clipboard on all your devices.
</p>
</header>
And CSS:
body {
font-family: "Bai Jamjuree", sans-serif;
text-align: center;
}
#media (min-width: 1200px) {
header {
width: 100%;
background-image: url(images/bg-header-desktop.png);
background-size: 100%;
background-repeat: no-repeat;
padding-top: 50px 150px;
}
}
h1 {
color: hsl(210, 10%, 33%);
font-size: 35px;
margin-bottom: 15px;
}
header > p {
color: hsl(201, 11%, 66%);
font-size: 18px;
}
Thank you in advance!
I have tried to use mask-image but it didn't work:
#media (min-width: 1200px) {
header {
width: 100%;
background-image: url(images/bg-header-desktop.png);
mask-image: linear-gradient(180deg, rgba(0, 0, 0, 1), transparent 74%);
background-size: 100%;
background-repeat: no-repeat;
padding-top: 50px 150px;
}
}
Do you have maybe any idea if I can give an opacity only for the bottom part of this background image using CSS?
With more than 1 background, you can put image in 1 and opacity on the other.
You can change 2nd background color as you want. It's opacity value is given by the RGBA background color (here 0.75 in the snippet).
body {
margin: 0;
padding: 0;
}
.wrapper {
position: absolute;
width: 100vw;
height: 50vh;
top: 50%;
transform: translateY(-50%);
font-size: 10em;
font-weight: bold;
font-family: sans-serif;
background: url("https://picsum.photos/id/22/1280/600");
}
.wrapper1 {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
clip-path: inset(50% 0 0 0);
background-color: rgba(255, 255, 255, 0.75);
display: flex;
justify-content: center;
align-items: center;
}
.wrapper2 {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
z-index: 2;
}
<div class="wrapper">
<div class="wrapper1"></div>
<div class="wrapper2">Hello World!</div>
</div>
Look at the snipper in full scree, for this demo I put width 100vw, so in small result is "strange"
I have a div :
<div class="titre_section" id="identity_section_titre_section">Identité du déclarant</div>
i need to put a background outside the div to apply a bigger height than the div
for the moment i have :
.titre_section {
position: relative;
#include media-breakpoint-down(sm) {
top: -2em;
}
top: -5em;
left: -2em;
padding-left: 20px;
font-family: $titre_section-font-family;
font-style: normal;
font-weight: bold;
font-size: 22px;
line-height: 25px;
letter-spacing: 0.25px;
color: $form-dark-color;
background: url("/custom/images/titre_section_rectangle.png") no-repeat;
background-size: contain;
}
here the result :
i tried to make this in order to modify the height of the background :
.titre_section::before{
content: "";
background: url("/custom/images/titre_section_rectangle.png") no-repeat;
background-size: contain;
}
but it's not working i don't see the background.
the result need to be like. i can't edit the html because we use zend form system
Here's a quick example using position: absolute to ensure that the background doesn't take up space, and z-index to ensure that the background is behind the content.
.section {
position: relative;
}
.section:before {
content: '';
position: absolute;
width: 400px;
height: 100px;
background: red;
z-index: -1;
}
<div class="section">Identité du déclarant</div>
<div>Lorem ipsum</div>
I have used :pseudo element to add the border effect in the left
.titre_section {
position: relative;
padding: 0px 0 10px 35px;
border-bottom: 1px solid #d2cfc7;
font-weight:bold;
margin-bottom:20px
}
.titre_section:before {
content: '';
position: absolute;
top: 0;
bottom: -20px;
width: 2px;
background: #bb8f29;
left: 20px;
}
<div class="titre_section" id="identity_section_titre_section">Identité du déclarant</div>
I'm using the background-image prop to get an image in the bg and a text on the foreground:
fiddle:
https://jsfiddle.net/zvy0j3r1/5/
however I dont see any image getting displayed. i'm not sure what I'm I missing here
CSS:
.main {
padding: 40px 70px;
display: inline-block;
width: 100%; //customizable user controlled width (not necessarily be 100% all time)
color: #AFBEC6;
text-align: center;
border: 3px solid #E7ECEE;
background-color: #F7F8F9;
}
.icon {
background-image: url(https://mdn.mozillademos.org/files/7693/catfront.png);
width: 100%;
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.text {
font-size: 24px;
position: relative;
top: -18px;
}
Just set the .main as relative and .icons as absolute.
.main {
padding: 40px 70px;
display: inline-block;
width: 100%;
color: #AFBEC6;
text-align: center;
border: 3px solid #E7ECEE;
background-color: #F7F8F9;
position: relative;
}
.icon {
background-image: url(https://mdn.mozillademos.org/files/7693/catfront.png);
width: 100%;
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: absolute;
left: 0;
top: 0;
}
.text {
font-size: 24px;
position: relative;
top: -18px;
}
<div class="main">
<div class="icon"></div>
<div class="text">No Data available</div>
</div>
The background image is not showing because the element doesn't have any height. You might think that using height: 100% to the element, would make it take up the same height of it's parent, but it doesn't work like that.
When a child element has height: 100%, it will only take up 100% of it's parent if the parent has an explicit height set, like with pixels, ems, vm, etc.
I have a div in CSS which is to show a piece of tape.
The problem is that the background in the middle is overlapping and appearing on both ends of the tape, so the transparency that should be at the ends of the tape div is not there.
Here is my CSS.
.tape {
background-image: url(../graphics/tapeleft.png), url(../graphics/taperight.png), url(../graphics/tapemiddle.png);
background-repeat: no-repeat, no-repeat, repeat;
background-position: left, right, center;
font-size: 1.05em;
height:32px;
min-width:75px;
line-height:32px;
text-align:center;
border:0 solid #000000;
margin:0;
padding: 0;
display:inline-block;
color: black;
}
.tape span { padding-left:16px; padding-right:16px; }
How do I stop the middle background from appearing beneath the background on the ends, while having the three backgrounds in one div? I have tried using background-clip and background-origin but I can't get it to work.
You need to use a pseudo element for the repeated image, as you can't set both a start and an end offset for it.
body {
background-color: magenta;
}
.tape {
position: relative;
background-image: url('http://i.imgur.com/vVnpGzx.png'),
url('http://i.imgur.com/Po3AT0u.png');
background-repeat: no-repeat;
background-position: left, right;
font-size: 1.05em;
height: 32px;
min-width: 75px;
line-height: 32px;
text-align: center;
display: inline-block;
color: black;
}
.tape::before {
content: '';
position: absolute;
top: 0;
left: 8px; /* start offset */
right: 8px; /* end offset */
height: 100%;
background: url('http://i.imgur.com/7aGUUgo.png') center;
z-index: -1
}
.tape span {
padding-left: 16px;
padding-right: 16px;
}
<div class="tape">
<span>$60 annual revenue</span>
</div>
I have a main div which has a background image with filter:blur and a box-shadow overlay.
How can I override filter:blur and box-shadow from parent div on a contained div?
The following is my attempt:
<style type="text/css">
#home_main {
margin: -30px;
background-size: cover;
padding: 0;
background-image: url('img/bg.jpg') !important;
filter: blur(2px);
overflow: hidden;
box-shadow: inset 0 0 0 1000px rgba(0,0,0,.3);
}
body {
overflow: hidden !important;
}
#home_content {
text-align: center;
color: #fff !important;
font-weight: 600;
position: fixed;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
text-shadow: none;
font-family: 'Open Sans' !important;
filter: initial !important;
box-shadow: initial !important;
}
#home_content h1 {
font-size: 42px;
font-weight: bold;
}
</style>
<div id="home_main">
<div id="home_content">
Info Management System
</div>
</div>
You could add a wrapper around both divs. Your'e already using positioning.
.wrap { position: relative; }
#home_main {
margin: -30px;
background-size: cover;
padding: 0;
filter: blur(2px);
overflow: hidden;
box-shadow: inset 0 0 0 1000px rgba(200,0,0,.3);
/* added so the div shows here */
width: 300px;
height: 300px;
background-image: url('https://static.pexels.com/photos/130763/pexels-photo-130763.jpeg');
}
#home_content {
text-align: center;
color: #fff ;
font-weight: 600;
position: absolute;
z-index: 2;
top: 40%;
transform: translateY(-50%);
width: 240px; /* width of image div minus it's negative margins */
}
#home_content h1 {
font-size: 42px;
font-weight: bold;
}
<div class="wrap">
<div id="home_content">
Info Management System
</div>
<div id="home_main"></div>
</div>
This will allow you to apply the filter and box shadow to only one of the divs. But as a direct child, you can't remove the parent's filter or box shadow. Much like opacity, some properties affect the parent and all its' children.