【问题标题】:Background image showing through picture with transparent background背景图片通过透明背景图片显示
【发布时间】:2013-08-16 19:28:54
【问题描述】:

我正在尝试为网站创建横幅。出于 SEO 的目的,我决定看看是否可以创建类型的横幅而不是导入的图像。我取得了不错的进展,但由于某种原因,我的背景图片通过覆盖在其上的徽标显示出来。

我将背景图像(在 css 中设置)设置为不透明度,因为我不希望它充分发挥作用。我在它上面放置了具有透明背景但没有不透明度的徽标。

目标横幅位于:

http://arielbalter.com/cio/

我正在尝试的代码位于:

http://jsfiddle.net/abalter/QzNpQ/

*** HTML *****

<header>
    <div id="outer">
        <div id="background-image"></div>
        <div id="logo">
            <img id="house-logo" src="http://arielbalter.com/cio/img/CheckItOutHouseNoBackground.png" />
    </div>
        <div id="lines">
            <h1 id="line1">check it out!</h1>
            <h1 id="line2">Home Inspection</h1>
        </div>
    </div>
</header>

** CSS ****

header {
    border: 3px double black;
    width: 100%;
    height: 7em;
}
#outer {
    background-size: 100% 100%;
    height: 100%;
    position: relative;
}
#background-image {
    background-image: url("http://arielbalter.com/cio/img/3tab_slanted.jpg");
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    opacity: 0.3;
}
#logo {
    float: left;
    border: 1px dashed green;
    height: 100%;
}
#logo img {
    height: 100%;
}
#lines {
    display: inline-block;
    border: 2px dotted blue;
    top: 0;
    bottom: 0;
}
#line1 {
    display: block;
    position: relative;
    font-family:"KGLoveSomebody", "Comic Sans MS", sans-serif;
    font-weight: bold;
    font-size: 3em;
    color: FireBrick;
    padding: 0.1em 0 0 0;
    margin: 0 0 -0.4em 0;
    border: 2px dashed green;
    letter-spacing: 0.05em;
}
#line2 {
    display: block;
    position: relative;
    font-family:"Trebuchet", sans-serif;
    font-size: 2em;
    color: black;
    font-weight: bold;
    padding: 0 0 0 0;
    margin: 0 0 0 0;
    border: 2px dashed orange;
    font-variant: small-caps;
}

谢谢!

【问题讨论】:

  • 你的 JSfiddle 是空白的
  • 您的小提琴中没有代码,从第一个链接中并不清楚您指的是什么“横幅”,以及实际问题是什么?
  • @abalter:请填写您的小提琴,以便我们为您提供帮助
  • 我对 jsfiddle 感到非常抱歉!我能想到的唯一想法是我忘了保存它。而且 HTML 下没有代码。严重犯规。这一定是它:jsfiddle.net/abalter/f68xn/1 我能够使用相对和绝对来修复它。 jsfiddle.net/abalter/F7wx6 Everntually,我没有使用带有图像的背景,而是使用了两个图像,因此它们都可以缩放。再次抱歉。
  • HTML 代码没有显示,因为我没有将其格式化为代码。再次抱歉。我编辑了帖子以修复它。

标签: css seo transparency opacity png-transparency


【解决方案1】:

诊断:

根据我对您的 CSS 的了解,#background-image 的不透明度正在影响 #logo 的不透明度。

解决方案 1:

如果可能,请考虑使用 background-color: rgba(x,y,z,a) 的父元素而不是照片的背景颜色,其中数字 a 负责不透明度。

解决方案 2:

如果您想在顶部使用两个图像,并且只有父元素具有不透明度,position absolute 将帮助您将它们显示在单独的 div 中,而不会出现任何不透明度问题。

【讨论】:

  • 是的,问题是徽标最终位于背景图像后面。我认为这很奇怪,因为背景图像位于它自己的 div 中,并且位于 html 中的徽标之前。徽标图像位于它自己的 div (
猜你喜欢
  • 2011-09-24
  • 1970-01-01
  • 2017-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-02
  • 1970-01-01
  • 2014-01-09
相关资源
最近更新 更多