Empty gap separating two side by side photos

Could someone assist me with removing the excessive white space between these two images? Each image is contained within its own respective div, with layer effects applied when hovered over. I've attempted changing the display to inline-block and setting the font-size to 0, but so far, nothing has been successful in reducing the space. Additionally, I would like both images to be centered once adjusted. It's possible that I may have incorrectly applied these modifications to various classes or divs throughout the process, but I'm unsure where exactly I went wrong.

I've included the HTML and CSS files, along with a screenshot demonstrating how it appears on my local server. I hope these attachments prove helpful. Thank you for any assistance you can provide.

https://i.stack.imgur.com/Ei366.png

*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.campus-col{
    flex-basis: 32%;
    border-radius: 10px;
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
}
.campus-col img{
    width: 100%;
    display: block; 
}
.layer{
    background: transparent;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transition: 0.5s;
}
.layer:hover{
    background: rgba(226,0,0,0.7);
}
.layer h3{
    width: 100%;
    font-weight: 500;
    color: #fff;
    font-size: 26px;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    position: absolute;
    opacity: 0;
    transition: 0.5s;
}
.layer:hover h3{
    bottom: 49%;
    opacity: 1;
 <div class="row">
        <div class="campus-col">
            <img src="#">
            <div class="layer">
                <a href="#"><h3>TEXT</h3></a>
            </div>
        </div>
       
        <div class="campus-col">
            <img src="#">
            <div class="layer">
                <a href="#"><h3>MESSENGER</h3></a>
            </div>
        </div>
        
    </div>

Answer №1

Do you want it styled like this?

If yes, simply apply display: flex and align-items: flex-start

*{
padding: 0;
margin: 0;
box-sizing: border-box;
}


.row {
  display: flex;
  align-items: flex-start
}

.campus-col{
    flex-basis: 32%;
    border-radius: 10px;
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
}
.campus-col img{
    width: 100%;
    display: block; 
}
.layer{
    background: transparent;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    transition: 0.5s;
}
.layer:hover{
    background: rgba(226,0,0,0.7);
}
.layer h3{
    width: 100%;
    font-weight: 500;
    color: #fff;
    font-size: 26px;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    position: absolute;
    opacity: 0;
    transition: 0.5s;
    text-align: center;
}
.layer:hover h3{
    bottom: 49%;
    opacity: 1;
<div class="row">
        <div class="campus-col">
            <img src="https://via.placeholder.com/150">
            <div class="layer">
                <a href="#"><h3>TEXT</h3></a>
            </div>
        </div>
       
        <div class="campus-col">
            <img src="https://via.placeholder.com/150">
            <div class="layer">
                <a href="#"><h3>MESSENGER</h3></a>
            </div>
        </div>
        
    </div>

Answer №2

Here is a CSS snippet to create a row flex container with centered content and space between images:

*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.row {
  display: flex;
  justify-content: center;
  gap: 1em;
}
.campus-col{
    flex-basis: 32%;
    border-radius: 10px;
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
}
.campus-col img{
    width: 100%;
    display: block; 
}
.layer{
    background: transparent;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transition: 0.5s;
}
.layer:hover{
    background: rgba(226,0,0,0.7);
}
.layer h3{
    width: 100%;
    font-weight: 500;
    color: #fff;
    font-size: 26px;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    position: absolute;
    opacity: 0;
    transition: 0.5s;
}
.layer:hover h3{
    bottom: 49%;
    opacity: 1;
<div class="row">
        <div class="campus-col">
            <img src="https://picsum.photos/200">
            <div class="layer">
                <a href="#"><h3>TEXT</h3></a>
            </div>
        </div>
       
        <div class="campus-col">
            <img src="https://picsum.photos/200">
            <div class="layer">
                <a href="#"><h3>MESSENGER</h3></a>
            </div>
        </div>
        
    </div>

Answer №3

To adjust the width of elements, consider using the bootstrap class .campus-col or defining a custom width.

Answer №4

You can use (justify-content: center) to align the elements in the flexbox, specifically, you can center the .img within the .row.

Another option is to use (justify-content: space-between) and define the width of the parent element (.row), which will align each .img to the edge according to their position (left or right).

For more detailed information, refer to: A Complete Guide to Flexbox

The Code:

.row {
  display: flex;
  justify-content: center;
}

.img {
  width: 200px;
  height: 300px;
  border: 1px solid;
  border-radius: 6px;
}

.img {
  margin: 0 20px;
}
<div class="row">
  <div class="img img1"></div>
  <div class="img img2"></div>
</div>

Solution based on your code:

Edited:

.row {
  display: flex;
  justify-content: center;
}

.campus-col{
    height: 200px; /* delete later, added to see the changes */
    border: 1px solid #ddd; /* delete later, added to see the changes */
    margin: 0 10px; /* add/remove spaces (left right of each one) */
}

The Code:

*{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

.row {
  display: flex;
  justify-content: center;
}

.campus-col{
    flex-basis: 32%;
    border-radius: 10px;
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
    height: 200px;
    border: 1px solid #ddd;
    margin: 0 10px;
}

.campus-col img{
    width: 100%;
    display: block; 
}

.layer{
    background: transparent;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transition: 0.5s;
}

.layer:hover{
    background: rgba(226,0,0,0.7);
}

.layer h3{
    width: 100%;
    font-weight: 500;
    color: #fff;
    font-size: 26px;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    position: absolute;
    opacity: 0;
    transition: 0.5s;
}

.layer:hover h3{
    bottom: 49%;
    opacity: 1;
}
<div class="row">
    <div class="campus-col">
        <img src="#">
        <div class="layer">
            <a href="#"><h3>TEXT</h3></a>
        </div>
    </div>

    <div class="campus-col">
        <img src="#">
        <div class="layer">
            <a href="#"><h3>MESSENGER</h3></a>
        </div>
    </div>
</div>

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

jquery slider for inputting phone number on a mobile device

I am currently working on enhancing the user interface by implementing a feature where users can select a mobile number using a slider. The idea is that the user will choose a digit between 0 and 9 using the slider, then confirm their selection by pressing ...

Troubleshooting Problem with Button Image Display in CSS

I have created a custom CSS for a PayPal sprite that I made. Below is an image comparison showing how it appears in Internet Explorer and Firefox. Here is the code to display the sprite: .ppsprite { background: url('/images/paypal_sprite.png') ...

My initial junior UI/UX assignment: Can you confirm whether this form modal dialog is pixel-perfect, and offer any suggestions for improvements

Currently diving into my first project as a Junior UX/UI Designer. Coming from a background in software engineering, I decided to challenge myself by focusing on design. I'm seeking feedback on the pixel perfection of this modal window, which my seni ...

Newbie Question: What is the process to upload a website that consists of only HTML files to a web hosting provider

I'm embarking on creating a basic four-page website using HTML, CSS, and images. It's my maiden voyage into web design. When I finish developing the HTML files, what steps should I take to upload them and launch the website? ...

Choose all of the IDs from various sections using Jquery

I am facing an issue with having 2 identical IDs inside 2 separate sections. When the button is clicked, I want it to select the ID within this section and apply a style, then also select the ID in the other section and apply that same style. The code sni ...

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

Learn how to hide a bar after clicking the "I agree" button with the help of Bootstrap

click here to see imageIs there a way to make that bar disappear once the user clicks "I agree"? I've searched through Bootstrap documentation but couldn't find a solution. Please assist. Below is the code snippet: <div id="cookie-message" cl ...

The styled horizontal list item has a background color that is not covering the entire

After setting up my CSS, I noticed a discrepancy in how the background color behaves when hovering over links in the navigation versus links in the footer. While the entire "button" area is filled with the background color in the nav, only the space behind ...

Limit Use of Special Characters in HTML and AngularJS

` ~ ! @ # $ % ^ & * ( ) _ + = { } | [ ] \ : ' ; " < > ? , . / I need to limit the use of special characters and numbers in the input field. To achieve this, I have employed the following pattern: ng-pattern="/^[a-zA-Z ]*$/" This patt ...

The container stays vacant as the bootstrap modal gracefully appears with a fading effect

I am trying to implement a basic bootstrap modal into my project, but I am encountering some issues with the code. When I click the "Launch demo" button, the modal fades in as expected, yet the container supposed to contain the ".modal-header", ".modal-bo ...

The case of the elusive Firefox overflow: hidden glitch

Recently, I integrated an image slider into my web design and it displayed perfectly on Internet Explorer and Chrome. However, when viewed on Firefox, I encountered a strange problem where the images in the slider were being pushed towards the right side o ...

Can the content inside HTML tags be susceptible to XSS attacks?

While working with Codeigniter, I have noticed that the xss_clean() function is replacing tab characters with a single space character. This behavior ends up causing issues when the content is later displayed within <pre><code></code>< ...

Is there a way to reference a different CSS class within another class?

Currently, I am working on creating a navbar using React. In this navbar, I have three components for the menu bar: text, logo, and buttons. The background color of the navbar is set to transparent, while the components are black by default. However, whe ...

Techniques for preventing background layering using CSS

I have implemented a background image on the <input type="submit"> element to give it the appearance of a button. My CSS code looks like this: input.button { background-image:url(/path/to/image.png); } Furthermore, I would like to display a dif ...

Mastering image focus with javascript: A comprehensive guide

On my HTML page, I have two images and a textbox. I want the focus to shift between the images based on the first character entered in the textbox. For example, when the user types '3', the first image should be focused, and for '4', th ...

Please request user input in order to generate a multiplication chart

Is there a way to ensure that the program works properly so that when the user inputs a value, it is included in the multiplication table? <html> <head> <title> Multiplication Table </title> <style> body{ font-family: aria ...

Bokeh is having trouble loading from the CDN

I am currently attempting to embed a plot along with its data by utilizing autoload_static within a straightforward html page that I wish to view locally on my computer. According to the documentation, all I need to do is place the .js file in the specifie ...

Adjust the color of the navbar only after a user scrolls, with a slight delay rather than

My code changes the navbar colors when I scroll (200ms). However, I would like the changes to occur when I am slightly above the next section, not immediately. In other words, what adjustments should I make to change the color in the next section and not ...

Incorporate a vertical scrollbar in the tbody while keeping the thead fixed for smooth vertical scrolling

I'm seeking a solution to implement horizontal and vertical scroll for my table. Currently, the horizontal scroll is working fine, but when trying to add vertical scroll, the table header also moves along with it. Is there a way to keep the table hea ...

Combine various input data and store it in a variable

I am looking for a way to add multiple input text values together and store the sum in a variable. Currently, I can add the values and display it in an id, but I want to assign it to a variable instead. The condition for this variable is described below af ...