.testcontainer {
width: 200px;
display: inline-block;
border: 1px solid gray;
height: 120px;
}
.header {
height: 20px;
background-color: cornflowerblue;
color: white;
-webkit-box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2);
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2);
}
.content {
height: 100px;
}
#hasbgimage {
background-image: url("https://via.placeholder.com/200x100");
background-size: cover;
}
<div class="testcontainer">
<div class="header">test with no image</div>
<div class="content"></div>
</div>
<div class="testcontainer">
<div class="header">test with image</div>
<div class="content" id="hasbgimage"></div>
</div>
我是一名优秀的程序员,十分优秀!