简体   繁体   English

CSS Shadow应用于儿童背景图片

[英]CSS Shadow applying to children background images

I've used an inset shadow for the parent header element 我已经为父标题元素使用了插入阴影

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

This has worked nicely for the parent element. 这对于父元素非常有效。 However I have a child element "Logo" where the background image is a JPG. 但是,我有一个子元素“ Logo”,其中背景图像是JPG。 The shadow is applying to the top of the image. 阴影将应用于图像的顶部。 Its weird because it shouldn't apply but if it did I would suspect it to apply fully instead it looks like it has been dipped in to part of the shadow ! 它之所以怪异,是因为它不应该应用,但是如果这样做,我会怀疑它是否可以完全应用,好像它已经浸入阴影的一部分中了 The image below highlights the right shadow (purple lines) and the wrong shadow (red lines). 下图突出显示了正确的阴影(紫色线)和错误的阴影(红色线)。

In this screenshot the image is a transparent PNG 在此屏幕快照中,图像是透明的PNG

在此处输入图片说明

I have tried Chrome, Firefox and IE all of which have the issue. 我已经尝试过Chrome,Firefox和IE,但所有这些都有问题。 I know its a little hard to see in that photo but it definitely makes it look unrefined. 我知道在那张照片中很难看到它,但是它确实使它看起来很精致。 I have also tried placing the image within the element as opposed to a background image, as well as trying JPG and PNG files, but all have the same result. 我也尝试过将图像放置在元素中而不是背景图像中,还尝试使用JPG和PNG文件,但是结果都相同。

Full HTML code for the header 标头的完整HTML代码

<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>

Full CSS 全CSS

Note the image is currently in the element as opposed to a background image but same result 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;}

You can use multiple classes on HTML elements. 您可以在HTML元素上使用多个类。

Create a new class just for the shadow and add it only where you need. 为阴影创建一个新类,并仅在需要时添加它。

It is also reusable then on other elements... (if you will need the same shadow). 然后也可以在其他元素上重用...(如果您需要相同的阴影)。

CSS Shadow is not applying to children background image, it is caused by the .JPG image your are using for logo. CSS Shadow不适用于儿童背景图片,这是由您用于徽标的.JPG图片引起的。 You need to have a transparent image for logo, use transparent .gif or .png file. 您需要具有用于徽标的透明图像,使用透明的.gif.png文件。 I would recommend .PNG . 我会推荐.PNG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM