Parent div's hover attribute doesn't affect child image? - html

I have a parent div with two child divs inside of it, one with an image and one with just text. I've assigned a :hover style to my parent class so that when a user hovers the entire div gets an inset shadow... however when I test it, the child that contains the image either is not affected or is on top of the effect..
Is there a way to get the :hover style to affect the image as well?
updated fiddle
edit: updated the fiddle with empty div to illustrate desired effect...
css:
.main-box {
border:2px solid #656565;
}
.main-box:hover {
-webkit-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.3) inset;
-moz-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.3) inset;
box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.3) inset;
}
.image {
display:inline-block;
}
.text {
display:inline-block;
}
<div class="main-box">
<div class="image">
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQM2EEo-JUTyhdaFxM3UCMvTM-yotCWzz_v6XeCL6RIYMdY4ZjJ" />
</div>
<div class="text">asdfasfda;lskjf</div>
</div>

The solution to this is actually not too far from what you have, simply change your CSS to say
.main-box:hover img {
-webkit-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.3) inset;
-moz-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.3) inset;
box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.3) inset;
}
and the effect should be what you are looking for.
Updated fiddle to show results
EDIT:
The best solution for this problem would be to add a :hover:before element in your CSS. This will create new content above the div on the page for as long as the user's mouse is over the div in question, and by giving it an absolute position and z-index, all effects you add to the box will show above the contents of the hovered div.
The following CSS will give you what you want:
.main-box:hover:before {
content: "";
display: inline-block;
position: absolute;
z-index: 2;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.3) inset;
-moz-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.3) inset;
box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.3) inset;
}
The problem with this method is that the :before content is now effectively covering everything in the div; any links, input fields or buttons you would want the user to be able to select are now rendered useless.
While pointer-events would be the easiest way of getting through this new overlay, it has terrible browser compatibility, so I would recommend the following:
.main-box a, .main-box input { position: relative; z-index: 3; }
// etc.
Doing this for all links, text or inputs you would want your users to be able to select should be clickable, and this solution should be compatible on all browsers.
Newer fiddle

Related

How to add shadow effect on left, right and bottom sides of background image

how might I add a shadow effect on a background image, using CSS ? I would like to have a shadow on the left, right and bottom of the background image ?
The command to add the shadow is the "box-shadow". But you can use this site to do this automatically for you:
https://www.cssmatic.com/box-shadow
There's a really handy tool that may help you here https://cssgenerator.org/box-shadow-css-generator.html.
This is an example of a shadow that appears in the areas you mentioned
box-shadow: 0px 6px 10px 0px rgba(0, 0, 0, 0.57);
I've made an example for you:
.shadow {
width: 90%;
margin: 20px;
height: 100px;
background: url(https://placekitten.com/640/360);
box-shadow: 0px 6px 10px 0px rgba(0, 0, 0, 0.57);
-webkit-box-shadow: 0px 6px 10px 0px rgba(0, 0, 0, 0.57);
-moz-box-shadow: 0px 6px 10px 0px rgba(0, 0, 0, 0.57);
}
<div class="shadow"></div>
div {
width: 300px;
height: 300px;
box-shadow: 0 15px 30px #888 inset
}
<div>
</div>
Refer inset property of box-shadow: https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow#Values

CSS shadow property isnt showing on an polygon object

I'm trying to style a div that I shaped with the clip-path: polygon CSS property. I want to give it some shadows so it looks a bit three dimensional.
The problem is that the shadow property doesn't work. When I inspect the element in the browser, the CSS code for shadow is grayed out.
I tried to make the shadow the following ways and none of them worked
box-shadow: 0 -2px 2px 0 rgba(0, 0, 0, 0.14), 0 -3px 1px -2px rgba(0,
0, 0, 0.12), 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
filter: drop-shadow(0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px
rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2));
filter: box-shadow 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px
rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2);
Here is the HTML code:
<div id="first" class="row">
<div class="container-fluid">
...some content inside...
</div>
</div>
And SCSS code:
#first {
padding-top: 60px;
padding-bottom: 30px;
-webkit-box-shadow: 0 -2px 2px 0 rgba(0, 0, 0, 0.14), 0 -3px 1px -2px rgba(0, 0, 0, 0.12), 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0 -2px 2px 0 rgba(0, 0, 0, 0.14), 0 -3px 1px -2px rgba(0, 0, 0, 0.12), 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
.container-fluid {
background: red;
clip-path: polygon(0 0%, 100% 0%, 100% 88%, 0 100%);
}
}
Try instead with filter: drop-shadow()
#first {
padding-top: 60px;
padding-bottom: 30px;
filter: drop-shadow(4px 4px 1px rgba(0, 0, 0, 0.3));
}
#first .container-fluid {
background: red;
clip-path: polygon(0 0%, 100% 0%, 100% 88%, 0 100%);
}
<div id="first" class="row">
<div class="container-fluid">
...some content inside...
</div>
</div>
It's working fine. Try changing the h-offset, v-offset, blur spread, color
#first {
padding-top: 60px;
padding-bottom: 30px;
/*-webkit-box-shadow: 0 -9px 9px 0 rgba(0, 0, 0, 0.14), 0 -3px 1px -2px rgba(0, 0, 0, 0.12), 0 -1px 5px 0 rgba(0, 0, 0, 0.2);*/
/*box-shadow: 0 -2px 2px 0 rgba(0, 0, 0, 0.14), 0 -3px 1px -2px rgba(0, 0, 0, 0.12), 0 -1px 5px 0 rgba(0, 0, 0, 0.2);*/
-webkit-box-shadow: 5px 10px 18px rgba(0, 0, 0, 0.14), 5px 10px 18px rgba(0, 0, 0, 0.12), 5px 10px 18px rgba(0, 0, 0, 0.2);
box-shadow: 5px 10px 18px rgba(0, 0, 0, 0.14), 5px 10px 18px rgba(0, 0, 0, 0.12), 5px 10px 18px rgba(0, 0, 0, 0.2);
}
.container-fluid {
background: red;
clip-path: polygon(0 0%, 100% 0%, 100% 88%, 0 100%);
}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<div id="first" class="row">
<div class="container-fluid">
...some content inside...
</div>
</div>

Alternative to drop-shadow filter for displaying shadow around custom shape

In an attempt to create shadows around custom shapes, I discovered the drop-shadow filter CSS property. However after having implemented it, I realised that it slowed the website down significantly.
I am therefore searching for an alternative to gain the same effect without compromising the load speed of the page.
The main content of the site is surrounded by a shadow-box wrapper using a box shadow, but this could not be used for the end section due to the transparent part of the background.
I am trying to achieve a shadow which resembles the shadow of the shadow-box.
Here is a jsFiddle illustrating how it currently looks
and here it can bee seen on the real site
HTML
<div class="container shadow-box no-padding"></div>
<div class="container justify-content-center">
<section class="light-bg end-section" id="portfolio"></section>
</div>
CSS
.container{
width:70%;
margin:auto;
}
.shadow-box{
background:green;
height:200px;
-webkit-box-shadow: 0px 0px 21px 8px rgba(0, 0, 0, 0.6) !important;
-moz-box-shadow: 0px 0px 21px 8px rgba(0, 0, 0, 0.6) !important;
-ms-box-shadow: 0px 0px 21px 8px rgba(0, 0, 0, 0.6) !important;
-o-box-shadow: 0px 0px 21px 8px rgba(0, 0, 0, 0.6) !important;
box-shadow: 0px 0px 21px 8px rgba(0, 0, 0, 0.6) !important;
}
.end-section {
background: radial-gradient(circle at 50% 100%, transparent 50px, #c1c1c1 50px);
z-index: 5;
height:200px;
filter: drop-shadow(0 30px 15px rgba(0, 0, 0, 0.6))
drop-shadow(0 10px 5px rgba(0, 0, 0, 0.6));
}
.light-bg:before {
content: '';
position: absolute;
z-index: 3;
top: -50px;
left: 50%;
margin-left: -50px;
height: 50px;
width: 100px;
border-top-left-radius: 100px;
border-top-right-radius: 100px;
background: #c1c1c1;
}

Aligning a submenu

I'm trying to align the submenu in the image but even I have found the code in the template I'm still stuck with it.
image link
/* sub sub menu*/
.sf-menu ul ul {
position: absolute;
top: -999em;
padding: 32px 0 21px;
background: #c7c7c7 url('../images/bg_sub2.jpg') 0 0 repeat-x;
-webkit-box-shadow: 0px 1px 0 rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0px 1px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0px 1px 0 rgba(0, 0, 0, 0.2);
}
Move just the arrow image with margin or top value based on what is selected.

Is there a more efficient way of making div backgrounds and borders with CSS?

In my application, I have a large number of div's that have the same background and borders but have different sizes.
Using one specific background image for every single one of them is very inefficient, especially for bandwidth and performance.
I will show you the background div and border and will tell you what I want to do instead.
So I thought it would be more efficient to separate the div into 4 corners (always the same ones), 4 sides (with background-repeat: repeat x or repeat y) and one center div
Do you think there is a better way of doing this with CSS 2? (I don't want to use CSS 3, for maximum compatibility)
Is this going to be resource-consuming for the client's browser or the server?
I would reccomend using box-shadow and border-radius:
div {
width: 200px;
height: 125px;
margin: 25px auto;
background: white;
border: 1px solid #aaaaaa;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-ms-border-radius: 3px;
-o-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1), -1px 0 3px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1), -1px 0 3px rgba(0, 0, 0, 0.1);
box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1), -1px 0 3px rgba(0, 0, 0, 0.1);
}
Demo