Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
143 views
in Technique[技术] by (71.8m points)

html - How to provide background color to half of two div?

.bg {
  background-color: gray;
  height: 200px;
}
<div class="bg">
  <div>
    <img src="https://s3.amazonaws.com/images.seroundtable.com/google-rainbow-texture-1491566442.jpg" style="width:200px">
  </div>
  <div>
    <img src="https://www.w3schools.com/w3css/img_lights.jpg" style="width:200px">
  </div>
</div>
question from:https://stackoverflow.com/questions/65915229/how-to-provide-background-color-to-half-of-two-div

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can make use of linear-gradient for background.

.bg {
  background: linear-gradient(to bottom, #ddd 50%, #9A8D6D 50%); /* Go towards the bottom, Cover #ddd for 50%, Cover #9a8d60 for the other half */
  height: 200px;
}
<div class="bg">
  <div>
    <img src="https://s3.amazonaws.com/images.seroundtable.com/google-rainbow-texture-1491566442.jpg" style="width:200px">
  </div>
  <div>
    <img src="https://www.w3schools.com/w3css/img_lights.jpg" style="width:200px">
  </div>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...