Picture featuring a div element serving as a partial background

How can I achieve a blue bar background behind this image?

https://i.sstatic.net/RLysr.png

This is my current approach:

.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>

Answer №1

To improve your code, I suggest focusing solely on the image tag:

img {
  display: block;
  margin: auto;
  border-image: linear-gradient(#0000 25%,#29334B 0 75%,#0000 0) fill 0//0 100vw;
}
<img src="https://dfstudio-d420.kxcdn.com/wordpress/wp-content/uploads/2019/06/digital_camera_photo-1080x675.jpg" height="300px">

Answer №2

If I were to address this situation, my approach would involve making adjustments to the HTML and CSS code.

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>

Answer №3

Here is a straightforward method using Grid layout:

section {
  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%;
}
<section>
  <div></div>
  <img src="https://dfstudio-d420.kxcdn.com/wordpress/wp-content/uploads/2019/06/digital_camera_photo-1080x675.jpg">
</section>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Artwork expanding incorrectly on HTML canvas

I'm encountering an issue while attempting to draw on an HTML canvas. I've specified 50 circles and multiple lines within a canvas of size 1000x1000 px, but not all circles are appearing as expected. My assumption is that the elements are being ...

Add a fading transition feature to images that are loaded at a later time

I used a clever technique to create a blur effect by loading a small, lightweight image first. Once the main background image is loaded, it swaps out the 'data-src' with the actual image. However, I am facing an issue with the abrupt transition, ...

Revealing and concealing adjacent elements within a specified class

In an attempt to create a carousel that functions by hiding and showing images when the next and previous buttons are clicked, I have organized my images in a table and assigned the li elements a class of 'li'. There are four images in total, wit ...

Vue.js: Bringing dynamic HTML rendering to life within child components' slots

When working on my vue.js application, I encountered an issue while trying to dynamically render HTML content in a child component's slot. It worked fine when inserting text only. This is the code snippet: ChildComponent.vue <template> < ...

PHP data insertion using filters and validation

I have created a database and implemented a validation system to ensure that fields are not left empty. If the fields are filled and pass through the sanitization function, I then proceed to save the data in the database. <?php // Define variables as ...

Is it possible to adjust table rows to match the height of the tallest row in the table?

I've been attempting to ensure that all table rows have the same height as the tallest element, without using a fixed value. Setting the height to auto results in each row having different heights, and specifying a fixed value is not ideal because the ...

Break down the string and iterate through using AngularJS

When looking at a string in the format "Something for example $takeThis $takeThisAlso", I need to parse it and extract all substrings that are enclosed within $ ($xxx). This means I want to achieve something like this: foreach($xxx in list) { var field ...

Has the HTML attribute 'step' stopped functioning properly?

I'm currently working on an Angularjs project that primarily uses material design. I am trying to set up a timepicker using the input control with the type=time attribute. However, I want to restrict the user to select times only within a 30-minute ra ...

The hyperlink tag within the overlay div is unresponsive

I'm facing an issue with my overlay div (rb-overlay) that pops up when users click on a page option. The overlay takes up the entire page and includes a close button in the top right corner. However, I've noticed that the link at the end of the t ...

An easy method for modifying data on a webpage hosted by an ESP8266 device

In my web page, I have a form to input times. The page is saved in flash memory and I want to update the times with previously stored values in EEPROM without loading the page into RAM. I prefer not to use websockets or AJAX for this purpose. I am looking ...

OptinMonster's innovative feature - the Pardot form with an inline button

Having trouble integrating an HTML Pardot form into OptinMonster's floating footer option. I'm looking to align all three fields inline, along with the button. Can anyone assist me in placing the button inline with the fields? HTML: <fo ...

What is the best way to ensure that my website's elements adjust automatically to different screen sizes?

Recently, I encountered a small snippet of HTML code with the main focus being an h2 element. #top-warning{ justify-content: center !important; display: flex; width: 100%; margin-top: 5vw; letter-spacing: 3px; font-family: "Penguin Regular ...

Box-sizing:border-box causing CSS padding problem in Firefox

Something strange is happening in Firefox, it seems like the debug console is not telling the truth or there's something I'm not seeing. Here's the CSS for the body tag: html, body { width: 100%; } body { padding: 5% 10% 0 10%; ...

Implement vertical navigation arrows in a Bootstrap accordion using JavaScript

Snippet of my HTML code: <div class="panel" style="margin-left: -15px;"> <div class="panel-heading"> <div class="vgroupholder panel-title" data-parent="#accordion" data-toggle="collapse" href=".titlePhysi ...

Tips for ensuring a functioning dropdown menu while maintaining a fixed navigation bar position

I am facing an issue with my navigation bar. I have set the position to fixed to keep it at the top, but this is causing the drop-down functionality to stop working. Please advise on where I should move the position fixed property so that my nav bar remai ...

Error CS0115: there is no appropriate method available to override for 'ASP.default_aspx.GetTypeHashCode()'

I'm a newcomer to the world of .Net and I'm looking to create a button that will redirect from one page to another. Here's the C# code I'm working with: using System; using System.Collections.Generic; using System.Linq; using System.We ...

What is the best way to horizontally center a child div within its parent container while keeping it fixed at the top?

I am struggling to center a child div horizontally within its parent div while also fixing it to the top of the parent. I have tried various approaches in CSS, but so far I haven't been successful :-( I can either center it or fix it to the top, but w ...

Did the menu get shifted downwards on the mobile version by using bootstrap?

Here is the desktop version of a navigation bar. https://i.sstatic.net/e595L.png This image shows the mobile version after clicking on the hamburger button. https://i.sstatic.net/ng1tK.png I would like the menu to open when I click on the hamburger, bu ...

Incorporating dynamic HTML templates onto a webpage using JavaScript/jQuery for seamless

Looking for a solution to a coding issue I'm facing. Here's the situation: <template id="photo-template"> <div class="template-border"> <p class="name"></p> </div> </template> I need to displa ...

Utilize alternate SCSS file depending on the direction of the text property

I have a dilemma with two SCSS files in my project - one named app.scss and the other app-rtl.scss. The main distinction between them is that the latter includes SCSS files for handling right-to-left layouts. My goal is to switch to the app-rtl.scss file ...