Achieving the perfect overlay and centered image effect using CSS

I am attempting to design a banner consisting of 3 images, each with dimensions of 900x420, similar to the image shown below. I am looking for advice on how to align these images such that they are horizontally centered. Any suggestions would be greatly appreciated: https://i.stack.imgur.com/5rgg6.jpg

Currently, I have tried using Twitter Bootstrap:

<div class="container-fluid">
    <div class="img-holder">
        <img src="img/rm1.jpg" alt="" />
        <div class="caption">
            <h3 class="title-content">Caption goes here<h3>
        </div>
    </div>
    <div class="img-holder">
        <img src="img/rm2.jpg" alt="" />
        <div class="caption">
            <h3 class="title-content">Caption goes here<h3>
        </div>
    </div>
    <div class="img-holder">
        <img src="img/rm3.jpg" alt="" />
        <div class="caption">
            <h3 class="title-content">Caption goes here<h3>
        </div>
    </div>      
</div>

CSS:

.img-holder {
        float: left;
        position: relative;
        background-color: rgba(2, 85, 165, 0.36);
    }
    .img-holder.caption {
        display: inline-block;
        position: absolute; /* absolute position (so we can position it where we want)*/
        bottom: 0px; /* positioned at the bottom */
        left: 0px;
        right: 0px;
        width: 100%;
        /* styling below */
        background-color: rgba(0, 0, 0, 0.76);
        color: white;
    }

h3.title_content {
    padding: 10px;
    margin: 0px;
}

Answer №1

To achieve the desired effect, it seems like you need to set a width for the container-fluid.

.container-fluid{
  width:1400px; /* Adjusted width based on the dimensions of the images */
  margin: 0 auto;
 }
.img-holder { 
float:left; 
position:relative;
background-color:rgba(2, 85, 165, 0.36);
} 
.img-holder .caption {
display:inline-block;
position:absolute;
bottom:0px;
left:0px;
right: 0px;  
width:100%;  
background-color:rgba(120,120, 120, 0.36);
color:white;
}

h3.title_content{  
padding:10px;  
margin:0px; 
}  
 <div class="container-fluid">
    <div class="img-holder">
        <img src="http://dummyimage.com/450x210/000/f23f1f.png" alt="" />
        <div class="caption">
            <h3 class="title-content">Caption goes here<h3>
        </div>
    </div>
    <div class="img-holder">
        <img src="http://dummyimage.com/450x210/109/acdce2.png" alt="" />
        <div class="caption">
            <h3 class="title-content">Caption goes here<h3>
        </div>
    </div>
    <div class="img-holder">
        <img src="http://dummyimage.com/450x210/036/0a34fe.png" alt="" />
        <div class="caption">
            <h3 class="title-content">Caption goes here<h3>
        </div>
    </div>      
</div>

If this is the solution you were looking for, I hope it helps!

Answer №2

Make sure to include the following code snippet in your CSS:

margin:0 auto 0 auto;

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

Getting rid of unnecessary compiled CSS files in Compass

After making changes to files and running compass compile, the compiled files remain even if they are renamed or deleted. Similarly, compass clean does not remove these old files as it only focuses on cleaning up current files in use. I want to avoid compl ...

Reducing the Size of Sprite Images on Websites

I am working on a web page that contains an image file called sprites.png. This file holds multiple images within it. Specifically, there is one image in the file that is 48px x 48px. In my CSS, I am referencing this image like so: .cell-back { height:3 ...

Collapse in Bootstrap without any Animation

How can I add animation to the Bootstrap Collapse feature on my website? I am using an icon from the Font Awesome library to trigger the collapse effect, but currently, it just pops up without any animation. What could be causing this issue? You can view ...

I have expanded the CSSStyleDeclaration prototype, how do I access the 'parent' property?

I have developed some custom methods for CSSStyleDeclaration and implement them like this: A_OBJECT.style.method() ; The code structure is quite simple: CSSStyleDeclaration.prototype.method = function () { x = this.left; ..... etc } Here's my que ...

What is the secret to the lightning speed at which this tag is being appended to the DOM?

Have a look at this concise sandbox that mirrors the code provided below: import React, { useState, useEffect } from "react"; import "./styles.css"; export default function App() { let [tag, setTag] = useState(null); function chan ...

Positioning the HTML form in the middle of the page

The given HTML code generates a form within a table, but despite aligning the table to the center, it remains on the left side of the webpage. <!DOCTYPE html> <html> <head> <style>input.textfill { float: right; }&l ...

Firefox experiencing issues with the onchange event

Here in this block of code, I have two dropdown lists: one for department and the other for section name. Based on the selected department, I dynamically change the options available for the section name dropdown list and then populate the values from both ...

When multiple input fields with an iterative design are using the same onChange() function, the specific event.target.values for each input

I'm in the process of developing a dynamic select button that adjusts based on the information entered into the iterative input fields I've set up. These input fields all utilize the same onChange() function. for (let i = 0; i < selectCount; i ...

Retrieving data from an API after the onClick event is activated

I'm facing a bit of a challenge with an HTML & JavaScript issue, which I believe should be straightforward to resolve. Since frontend development is not really my forte, I am hoping to find some assistance here. Task: A friend who owns a website buil ...

Tips for accessing the @keyframes selector and extracting the value from it

In my CSS code, I have a shape element with an animation that spins infinitely for 50 seconds. #shape { -webkit-animation: spin 50s infinite linear; } @-webkit-keyframes spin { 0% { transform: rotateY(0); } 100% { transform: rotateY(-360deg ...

What is the best way to make the block rotate each time the button is clicked?

Specifically, I am having trouble getting the block to rotate properly. Currently, the block only rotates once when clicked, but I want it to rotate each time I click in both directions. Any suggestions on how to achieve this? var now = 10; $('. ...

Sticky positioning with varying column widths

How can I create HTML and CSS columns that stick together without manually specifying the "left:" parameter every time? The current example in the fiddle achieves what I want, but requires manual setting of the "left:" value. Is there a way to make this m ...

Deactivate interactive functions on the mat-slider while preserving the CSS styling

I'm attempting to create a mat-slider with a thumb label that remains visible at all times. Below is my mat-slider component: <mat-slider class="example-margin" [disabled]="false" [thumbLabel]="true" [tickInterval]="tickInterval" ...

Accessing getUserMedia within Internet Explorer 11 or utilizing MediaStream on IE 11

I am attempting to utilize the getUserMedia function in IE 11 with the help of the temasys plugin. However, IE does not support the MediaStream instance returned by getUserMedia. Below is a snippet of my code: import React from 'react' import { ...

Utilizing jQuery to apply a class to a targeted element when clicked

I'm currently working on animating a menu item where it expands to the left when hovered over, and contracts back when the mouse moves out. This part is functioning as expected. Additionally, I am trying to apply a specific color to the button by add ...

PHP and MySQL combination for efficient removal of multiple dropdown choices

I'm struggling to figure this out. Essentially, it's a form with multiple dropdown menus where users can select one or more items to filter MySQL data results. I want to dynamically update the other dropdown menus as the user makes selections. Fo ...

Stop the form submission until validation is complete

I'm currently working on a form and encountering some validation issues. HTML: <form id="regForm" class="form-group" method="POST" action="signup.php"> <div class="col-md-12"> <h2>Job Pocket</h2> </div> <di ...

The radio button is not providing the necessary notification

I currently have the following elements on my webpage: Table rows that contain radio buttons A link labeled "Issue" that triggers a popup with one submit button A submit button labeled "details" that also triggers a popup The issue I am facing is as fol ...

A tutorial on how to create the appearance of disabled buttons that look the same as enabled buttons through the use

My button includes a text field that is constantly disabled. I would like for the text field to appear as bright as it does when the button is enabled. After disabling the button, they both appear dimmer compared to others and the text field follows suit ...

Understanding the concept of for loops in JavaScript and incorporating them in CSS styling

Hello there! I initially used this code to draw 12 lines, but now I am looking to incorporate a for loop and implement it in CSS. Can someone please guide me on how to proceed? <!DOCTYPE html> <html> <head> <style> #straigh ...