如何使div透明并将其浮动在图像上?

时间:2017-01-10 11:08:35

标签: html css

我想让div透明并将其移到图像上。这是html和css的示例代码:

<html>
<head>
    <title></title>
    <style type="text/css">
        body {
            width: 500px;
            margin: 0 auto;
        }
        .head {
            border: 2px solid black;
            width: 346px;
            height: 50px;
        }
        h2 {
            padding: 0px;
            margin: 10px;
        }
    </style>
</head>
<body>

    <div class="wrapper">
        <div class="head">
            <h2>Logo</h2>
        </div>
        <div class="slider">
            <img src="http://placehold.it/350x150">
        </div>
    </div>

</body>
</html>

输出结果: enter image description here

但我想这样: enter image description here

任何人都可以帮助我吗?在此先感谢:)

1 个答案:

答案 0 :(得分:1)

position: absolute

提供.head

所以你的代码变成了:

&#13;
&#13;
body {
  width: 500px;
  margin: 0 auto;
}
.head {
  border: 2px solid black;
  width: 346px;
  height: 50px;
  position: absolute;
}
h2 {
  padding: 0px;
  margin: 10px;
}
&#13;
<div class="wrapper">
  <div class="head">
    <h2>Logo</h2>
  </div>
  <div class="slider">
    <img src="http://placehold.it/350x150">
  </div>
</div>
&#13;
&#13;
&#13;