我如何用css制作这个盒子?分析页面的代码我注意到有一个div又由另外两个div组成,即图像和文本的div
示例1:https://i.stack.imgur.com/wFSGX.png
示例2:https://i.stack.imgur.com/AXISy.png
答案 0 :(得分:0)
.outer{
width: 300px;
height: 300px;
position: relative;
}
.outer > .inner{
background: rgba(0,0,0,0.9);
color: #fff;
position: absolute;
padding: 10px;
right: 0;
bottom: 0;
left: 0;
z-index:1;
}
<div class="outer" style="background:url(http://lorempixel.com/600/300/)center center no-repeat;background-size:cover"> <div class="inner">Some text here</div></div>
答案 1 :(得分:0)
我认为您想要做的是在图像上叠加透明div。我为此编写了html和css,并在此为您创建了一个plunk:http://embed.plnkr.co/7Qeh2C/。代码如下:
HTML:
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<h1>Hello Hardar!</h1>
<div class="container">
<img style="width:400px" src="http://www.davemphotographics.com/wp-content/uploads/2016/02/CSP-Headshots-533-Edit.jpg"></img>
<div class="overlay"><p>Test</p></div>
</div>
</body>
</html>
CSS:
.container {
position:relative;
width: 400px;
}
.overlay {
position: absolute;
height:60px;
bottom: 0;
width:400px;
background-color:#444;
opacity: .8;
}
.overlay p {
color: #FFF;
text-align: center;
}