skip to Main Content

Is there a way to use a blue bar behind the image like this?

enter image description here

This is what I’m doing:

.line-divider{
    height: 125px;
    background-color: #29334B;
}
<div>
    <div style="background-color: green; width: auto; height: auto;">
        <div class="line-divider" style="background-color: red;">           
            <img 
                src="https://dfstudio-d420.kxcdn.com/wordpress/wp-content/uploads/2019/06/digital_camera_photo-1080x675.jpg"
                contain
                height="300px" 
            >
        </div>                   
    </div> 
</div>

2

Answers


  1. Here’s how I would tackle this, apologise but I had to change the HTML and CSS.

    body {
        margin: 0;
        font-family: Arial, sans-serif;
        display: flex;
        justify-content: center; 
        align-items: center;     
        height: 100vh;
        background-color: #f4f4f4;
    }
    
    .container {
        width: 100vw; 
        display: flex;
        justify-content: center; 
        background-color: green; 
        position: relative;
    }
    
    .line-divider {
        height: 200px;
        display: flex;
        align-items: center;
        position: relative;
    }
    
    .line {
        position: absolute;
        top: 50%;
        left: 0;
        width: 100%;
        height: 5px;
        background-color: red;
        z-index: -1;
        transform: translateY(-50%);
    }
    
    .line-divider img {
        height: 300px;
        box-shadow: 0 10px 15px rgba(0, 0, 0, 0.3);
        border-radius: 10px;
    }
    <div class="container">
        <div class="line-divider"> 
            <div class="line"></div>          
            <img 
                src="https://dfstudio-d420.kxcdn.com/wordpress/wp-content/uploads/2019/06/digital_camera_photo-1080x675.jpg"
            >
        </div>
    </div>
    Login or Signup to reply.
  2. Here’s a simple way to do it with Grid layout:

    article {
      display: grid;
      grid-template-columns: 1fr 50% 1fr;
      grid-template-rows: 1fr 50% 1fr; 
    }
    
    div {
      background: #30353b;
      grid-area: 2 / 1 / 3 / 4;
    }
    
    img {
      grid-area: 1 / 2 / 4 / 3;
      width: 100%;
    }
    <article>
      <div></div>
      <img src="https://dfstudio-d420.kxcdn.com/wordpress/wp-content/uploads/2019/06/digital_camera_photo-1080x675.jpg">
    </article>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search