【问题标题】:How can I get an image to be in front of the background color?如何让图像位于背景颜色之前?
【发布时间】:2014-07-25 00:44:34
【问题描述】:

我有两种背景颜色。一部分是灰色的,另一部分是白色的。背景的灰色部分只覆盖了背景的一小部分,其余部分被白色覆盖。现在我想添加一个图像作为我的“标志”,它应该在背景的灰色部分。该图像当前位于两个背景下方,我只是不知道如何使图像位于背景前面。

<style type="text/css">      
  #grey-bg {
    position: fixed;
      top: 0px;
      left: 0px;
      width: 100%;
      height: 25%;
      background-color: grey;
  }
  body
  {
    background-color:white;
  }   
</style>
</head>

<body>
<div id="grey-bg">
<body bgcolor="grey">
</div>
<center><img    src="http://img2.wikia.nocookie.net/__cb20110818145752/prototype/images/thumb/6/64/Prototype_-_Logo.png/660px-Prototype_-_Logo.png alt="Prototype"></center>

我希望这是可以理解的。我对此很陌生,并试图尽可能清楚。 任何帮助将不胜感激!

【问题讨论】:

  • 是的,首先学习基础知识 :) 你现在有两个身体标签等。
  • 我查看了您的个人资料。你应该知道这一点。你知道这个问题的答案吗?! :)
  • 您知道使用 CSS3 您可以在 1 个元素上拥有多个背景。

标签: html css image background


【解决方案1】:

只需将图像元素移动到具有灰色背景的 div 内即可。

<div id="grey-bg">    
  <center><img src="http://img2.wikia.nocookie.net/__cb20110818145752/prototype/images/thumb/6/64/Prototype_-_Logo.png/660px-Prototype_-_Logo.png" alt="Prototype" /></center>
</div>

小提琴:http://jsfiddle.net/LcDTS/

您还应该避免使用 center 标记并改用 CSS。

【讨论】:

  • 没问题。如果有帮助,请接受我的回答:-)
猜你喜欢
  • 1970-01-01
  • 2012-01-01
  • 2012-06-04
  • 1970-01-01
  • 2014-07-22
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多