Applying CSS shadow effects to background images of child elements

The parent header element has a nice inset shadow applied to it.

 -webkit-box-shadow:inset 0px 0px 50px 10px #e5e5e55; box-shadow:inset 0px 0px 50px 10px #e5e5e5;

However, when it comes to the child element "Logo" with a JPG background image, things get a bit strange. The shadow seems to be affecting the top of the image in an unexpected way. It appears as if the image has been partially immersed in the shadow rather than fully covered by it. The image below clearly shows the correct shadow (purple lines) and the incorrect shadow (red lines).

It's worth noting that the image in the screenshot is a transparent PNG.

I've tested this issue on Chrome, Firefox, and IE, and unfortunately, all three browsers display the same problem. Although it might be difficult to spot in the photo, this glitch definitely gives the design a rough look. I've also experimented with using different types of images (PNG and JPG) and placing them within the element rather than as a background image, but the results remain consistent.

Here is the full HTML code for the header:

<div id="header">
  <div id="header-level-1">
    <div id="header-logo">
      <img src="images/logo.png">
    </div>
    <div id="header-contact">
      <p class="header-contact-title">For More Information Call</p>
      <p class="header-contact-phone"><a href="tel:xxx">xxx</a></p>
    </div>
  </div>

  <div id="header-level-2">
    <div id="header-nav">

    </div>
  </div>
</div>

And here is the full CSS:

Please note that the image is currently placed inside the element instead of being set as a background image, although the outcome remains the same either way.

  #header {width:950px; height:220px; margin:0 auto; margin-top:30px; background-color:#fff; border-radius:15px; -webkit-box-shadow:inset 0px 0px 50px 10px #e5e5e55; box-shadow:inset 0px 0px 50px 10px #e5e5e5;}
#header-level-1 {width:950px;}
#header-level-2 {width:950px;}
#header-logo {width:700px; height:130px; display:inline-block; vertical-align:top;}
#header-contact {width:240px; height:100px; padding-top:30px; color:#76a410; font-size:1.3em; display:inline-block; vertical-align:top;}
#header-contact a:link {color:#00446e; text-decoration:none; font-weight:900; font-size:1.6em;}
#header-contact a:hover {text-decoration:underline; font-weight:800;}
.header-contact-title {display:block; padding:0px; margin:0px;}
.header-contact-phone {display:block; padding:0px; margin:0px; padding-top:5px;}

#header-nav {width:900px; margin-left:25px; height:66px; margin:0 auto; text-align:center; bottom:5px; position:relative; background:url('../images/nav-background.jpg'); border-radius:5px;}
#header-nav a:link, #header-nav a:visited, #header-nav a:active {color:#fff; text-decoration:none; padding-left:6px; padding-right:6px; padding-top:18px; display:inline-block;}

Answer №1

Utilizing various classes on HTML elements is totally possible.

Simply generate a distinct class solely for the shadow effect and apply it selectively.

This way, you can easily reapply the same shadow effect to other elements as well if needed.

Answer №2

The issue with CSS Shadow not applying to children background image is likely due to the image format you are using for your logo, specifically the .JPG format. To resolve this, consider using a transparent image format such as .gif or .png. I would suggest opting for .PNG for best results.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Changing the Color Scheme of the Shinydashboard Header

I'm currently working on designing a dashboard that must adhere to the company's style guidelines. One of the requirements is to change the background color of the header. I have managed to update the color successfully, however, there's an ...

Why might Apple's HTML5 demos incorporate HTML4 doctypes?

Several of Apple's HTML 5 demonstrations include an html4 loose doctype: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> What reasons might they have for opting not to use the HTML5 doctyp ...

What is the reason that <!DOCTYPE> prevents JavaScript from generating iFrames?

After completing most of my website, I suddenly realized that I forgot to set a doctype for the page. Unfortunately, whenever I try to add a doctype tag, regardless of which one I use, it causes my popup iframes to malfunction. I'm not sure why this ...

Is there a way to accomplish this using Bootstrap?

Hello there! I have a piece of code that is working with both bootstrap and Pixedelic camera. Here it is: <section id="slider" class="container-fluid"> <div class="row fluid"> <div id="camera_wrap_1"> <div data-src="conten ...

Change the CSS dynamically

I'm curious about how to create a similar effect like the one on this page: On the left side, there is a panel that allows for adjusting the template. What I've noticed is that when I change the color, different CSS files are used (blue.css, pur ...

"Interactive demonstration" image toggle through file upload

I have a project to create a "demo" website for a client who wants to showcase the template to their clients. A key feature they are interested in is allowing users to upload their logo (in jpg or png format) and see it replace the default logo image insta ...

Showing the name of a class

Hello everyone, I have a piece of JavaScript code that generates HTML buttons when the page loads. The button attributes are fetched from a database through an ASP page. Everything is working fine except for displaying the class attribute - it shows as u ...

The button text in Bootstrap 5 is black instead of white as shown in their demo

During the installation of Bootstrap 5, I encountered an issue where many of my buttons are displaying a black font instead of the expected white font as shown in the Bootstrap 5 Documentation For instance, the .btn-primary button on the official Bootstra ...

Tips for integrating font styles into a Vue JS project

I have been working on my Vue project and I am trying to incorporate a specific font. However, despite importing the font locally in my App.vue file as shown below, it does not seem to be working properly: @font-face { font-family: "Open Sans Bold&q ...

Resetting CSS animations using animation-delay

My aim is to animate a series of images on my landing page using Next.js and SCSS. The issue arises when I try to add dynamic animations that reset after each cycle. The delay in the animation causes the reset to also be delayed, which disrupts the flow. I ...

How can a Vue component be created with a template that solely consists of a property's text?

Looking for a way to incorporate plain text within a Vue component template area? The current method involves wrapping the text in a div, but this causes layout issues when concatenating components with other text fragments. This results in awkward spacing ...

Exploring the ways to retrieve the returned Dynamic scope in AngularJS

There's a specific need I have - I require a single AngularJS function that can dynamically return the scope variable based on an input parameter. When it comes to controller functions, I've come across examples of how to achieve this dynamic sco ...

Is there a reason why using margin:auto doesn't work for vertically centering items?

I'm having trouble understanding how margin auto functions. In the scenario I'm dealing with, I have a parent div and a child div nested within it, both with specified widths and heights. I attempted to use margin auto in order to center the inne ...

Avoiding double tapping to zoom on Chrome Android while using the desktop version of a website

Is there a way to disable zooming when double clicking in Google Chrome with the desktop site enabled? I attempted to use <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> without success. I al ...

Highly suggested CDN for Bootstrap Tab styling

I'm encountering an issue with bootstrap.min.css and tabs. Using: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> The page format looks correct, but switching tabs doesn't display the c ...

Finding tool for locating object names in JSON

JSON data: [ { "destination": "Hawaii", "Country": "U.S.A", "description": "...and so forth", "images": { "image": [ "hawaii1.jpg", "hawaii2.jpg", ...

Developing a fresh Outlook email using a combination of javascript and vbscript

I have created a custom HTML page with fields and a button to fill out in order to generate a new Outlook mail item. To format the body of the email using HTML, I am utilizing VBScript to create the new mail item. <script> function generateEmail() { ...

CSS: Basic yet effective image display showcase

Web development is not my main focus, but when I delve into it, CSS always presents a frustrating challenge. My goal is to create a basic class that combines images with descriptions in a structured manner. Specifically, I aim to display two rows, each con ...

Is there a way to create a "navigate to" button directly from the text within a <p> element?

Within my HTML, there is a <p> tag which dynamically receives a link value from a JavaScript function. The link could be anything from www.google.com to youtube or instagram. How can I utilize the "copytoclipboard" library to copy this link to clipbo ...

Switch up the styling of a component by updating its properties with a switch statement

Although there is a similar question, my query has a unique requirement. I have defined the common styles for my button and implemented a function using a switch statement with different properties for various buttons across different pages. However, for ...