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

The CSS layout is not positioning elements correctly

Here is a preview of how I want my final design to appear: I am facing difficulty in properly aligning the two columns using my CSS code. Whenever I apply the float: left; property, the columns end up stacking on top of each other. /*------ Code st ...

Could the problem with inset box-shadow and large border-radius on one side be related to Chrome?

Have you noticed a discrepancy in the inset box-shadow behavior with large border-radius on one side, particularly in Chrome? I'm curious about which browser is showing accurate results. Here's how it appears in Chrome: https://i.stack.imgur. ...

Manipulating values in JavaScript using an onclick event in PHP

I am looking to remove the "http" from the URL part of an input link before sending the data. This is my input code that looks like this when clicked: <input style="outline: none;" type="button" onclick="formatText ('link:url');" class="btn ...

Footer Section (navigation) bounces up when scrolling to the beginning of the page

I am currently developing a fully web-based app-style layout. One issue I'm facing is that the navigation menu jumps slightly when I use my S3 to auto-scroll to the top by dragging. However, if I scroll up manually without lifting my finger, this pro ...

Generating values in a loop - mastering the art of creating data points

My goal is to create a variable within a loop: box-shadow: 835px 1456px #FFF, 1272px 796px #FFF, 574px 1357px #FFFand so on... The concept is simple: box-shadow: x1 y1 #fff, x2 y2 #fff, x3 y3 #fff, x4 y4 #fff ... xn yn #fff. I attempted to achieve this ...

Arranging content within columns according to their column position

As I design a grid with three columns, each grid box contains a div with a maximum width of 280px. Sometimes the grid columns exceed this width. To achieve my desired layout, I aim to align the content in the grid boxes so that the left column aligns to th ...

Acquire HTML table information in array format using JavaScript

I am searching for a script that can extract the 2D array of rows and columns from an HTML table within a div element. The desired array output should be: [ ["Company", "Contact", "Country"], ["Alfreds Futterkiste", "Maria Anders", "Germany"], ...

Increase the gap between columns in Bootstrap for a better layout

I have implemented a web layout using bootstrap 3. You can view the JSFiddle here. In order to make the layout responsive, I had to structure it in a slightly unconventional way. The final output on small screens includes three information boxes within an ...

Restricting the type of user input in HTML forms

Requirements: Input must be a whole number between 2 and 99, inclusive. Current Solution: <input required type="number" min="2" max="99" oninput="this.value = Math.abs(this.value)" maxLength="2" matInp ...

Reveal unseen information on the webpage upon clicking a link

I have successfully implemented a fixed header and footer on my webpage. The goal is to make it so that when a user clicks on a link in either the header or footer, the content of that page should appear dynamically. While I have explored various styles, ...

Using CSS to style the last element in a set of dynamic content

I am currently working on targeting the last element in a dynamically generated content set. For instance, here is an example of how the generated content appears: <div class="block"> <div class="block-inner"> <div class="box"> ...

Can you explain the significance of the "row" class in Bootstrap, how it differs from containers, and how it interacts with col-***-*?

I've been browsing through the guide found at http://getbootstrap.com/css/ and I'm having trouble grasping the purpose of the "row" class. I experimented with some examples provided in the guide like: <div class="row"> <div class="c ...

Placing a div directly beneath an anchor tag

I'm trying to create a dropdown menu that appears directly under the URL that triggers it. I have successfully made the menu appear, but I am struggling with positioning it correctly. Here is my HTML code: <div id="container"> Content here ...

Struggling with aligning an image and text side by side in CSS

Struggling to get my text and image perfectly aligned horizontally? Despite being aligned, the image makes it seem otherwise. https://i.stack.imgur.com/u1QOh.png CSS Code: /* Copyright © 2016 Dynavio Cooperative */ .navbar { width: 100%; border ...

I desire to incorporate a subtle fading effect into the script

I have written the script code and now I am looking to add a fade effect to it. Can anyone guide me on how to achieve this? Your help is much appreciated! ※I used an online translator as English is not my native language. Please bear with any awkward ph ...

When a mobile device is rotated, the screen on a jQuery application will automatically shrink

Having trouble with JQM and device rotation on iOS devices. The screen doesn't resize properly when rotated. I have this line in the header to handle display size: <meta name="viewport" content="height=device-height,width=device-width,initial-scal ...

Avoid creating a line break directly after the header, however allow for a line break

I find myself in a scenario where I require a paragraph that has a specific format: An Emphasized Title Some relevant information regarding the subject... I am looking to insert a new line before the title, ensuring it seamlessly integrates with the re ...

Issue with Laravel: CKEditor text not loading HTML tags

Could you assist me with this? click here for the image description image description available here ...

The table toggle feature seems to be malfunctioning in Safari, whereas it works perfectly in Chrome

My table includes a td element that serves as a toggle switch, transitioning between 3 states flawlessly in Chrome. However, I am facing issues with its functionality in Safari and seek assistance in rectifying the issue to ensure cross-browser compatibili ...

The previously set display value remains unchanged when switching CSS files

I'm working on a project where I need to display three separate articles based on the screen size. Article 1 should only be visible when the screen width is less than 600 pixels Article 2 should be visible between 600 and 900 pixels Article 3 shoul ...