What is causing the space between the images in my flex column?

I am trying to create a layout with two columns and two rows. The first row should have text in the first column and an image in the second column, while the second row should have an image in the first column and text in the second.

My goal is to make the corners of the images touch to form a perfect grid. Despite my efforts, I can't seem to get them to align properly no matter what adjustments I make.

If you want to take a look at the code: https://jsfiddle.net/zbqewcrx/

<body>
 
 <div>        
<div class="block reverse">
  <div class="block-info left">
    <div class="block-info-content">
      <div class="block-title">
        <h2>Title 1</h2>
      </div>
      <div class="block-text">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quis tempus nibh. Sed eget lacinia lorem. Integer imperdiet sodales bibendum. Donec fermentum viverra orci, at scelerisque erat commodo sit amet. Nullam et blandit massa. Quisque gravida consectetur tristique. Sed eget tempor ante. Aliquam aliquet dolor porta suscipit elementum. Ut vel fringilla lacus.</p>
      </div>
    </div>
  </div>
  <div class="block-photo">
    <div class="block-img first">
      <img src="https://images.unsplash.com/photo-1607028227034-f0378aa1bd2c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=735&q=80">
    </div>
  </div>
</div>
<div class="block">
  <div class="block-photo">
    <div class="block-img">
      <img src="https://images.unsplash.com/photo-1607028227034-f0378aa1bd2c?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=735&q=80">
    </div>
  </div>
   <div class="block-info right">
    <div class="block-info-content">
      <div class="block-title">
        <h2>Title 2</h2>
      </div>
      <div class="block-text">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quis tempus nibh. Sed eget lacinia lorem. Integer imperdiet sodales bibendum. Donec fermentum viverra orci, at scelerisque erat commodo sit amet. Nullam et blandit massa. Quisque gravida consectetur tristique. Sed eget tempor ante. Aliquam aliquet dolor porta suscipit elementum. Ut vel fringilla lacus.</p>
    </div>
    </div>
  </div>
</div>
  </div>
  
</body>

<style>
body {
  margin: 0 20em;

}

h2, h3, h1, h4, p {
  margin: 10px 0;
  padding: 0;
}

.block {
  line-height: 24px;
  display: flex;
  flex-direction: row;
  align-items: center;
  text-align: left;
}

.block-info, .block-photo {
  width: 50%;

}


.block-img img {
  width: 100%;
  height: 600px;
  object-fit: cover;
  
}
  
.block-info-content {
  text-align: left;
  padding: 2em;
}

.block-text {
  padding-top: 2em;
}
</style>

screenshot showing how the corners of the images are not aligned

No matter what I try, the corners of the images never align perfectly on my website. It's frustrating because they're always just slightly off :(

I attempted to remove padding (in classes .left, .right) which improved the alignment slightly, but it's still not meeting my expectations.

Answer №1

It appears that the issue with the slight margin is due to the line-height property. A simple solution would be to relocate this property to the text-containing class.

.content-block {
  line-height: 0;
}

.block-details {
  line-height: 24px;
}

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

Locate elements using Class with Simple Selenium

I'm facing a challenge filling out a phone number on a web portal using Selenium with VBA. Despite the element being loaded, Selenium seems to be unable to locate the text box. This is my code: Dim ch As Selenium.ChromeDriver Sub FillPhoneNumbers() ...

What is the process for embedding images in Angular that are stored in a directory other than assets?

I am working on an Angular Application with a particular structure outlined below: Structure Within the structure, there is a directory labeled backend (highlighted in yellow) containing other directories. An example of a valid path within this structure ...

Certain JavaScript code might fail to load on WordPress

I've been struggling to troubleshoot an issue with a JavaScript accordion menu on my WordPress site. When I try to click the accordion button, it doesn't reveal the hidden content beneath it. I've attempted various solutions, but none have s ...

Creating dynamic form fields using AngularJS

I have a form that includes an input field, a checkbox, and two buttons - one for adding a new field and one for deleting a field. I want to remove the add button and instead show the next field when the checkbox is checked. How can I achieve this? angu ...

Issue with selectpicker version 1.13 in Bootstrap 4: selected option's content not properly displayed

The issue at hand is purely aesthetic: the select element does not align properly with the selected option. It appears too low and extends beyond the container. Additionally, the caret is displayed in the top right corner instead of the middle right where ...

Struggles encountered while developing a JavaScript calendar

Hey guys, I'm encountering an issue with Uncaught TypeError: document.getElementById(...) is null. I believe the problem lies in the way types are being parsed for document.getElementById(dayOfWeek).appendChild(dayPTag);. This code is meant to display ...

Top method for referencing HTML layout across various pages

Is there an optimal method for consistently calling an HTML structure from various pages? In my webapp, I have the same type of structure that needs to be called from different pages. For instance, I have a media management page displaying uploaded media ...

Having trouble with displaying Bootstrap 5 columns inline?

My HTML layout for a music player using Bootstrap 5 is coming along nicely. One part of the player I'm working on involves displaying information about the current pattern in a song. Here's what I have in mind. I want to create a layout with two ...

Would the addition of custom fonts to a CSS document through @font-face result in slower rendering speeds?

After downloading a font from dafont.com, I incorporated it into the stylesheet of an HTML file that resides solely on my computer. Modifying most of the buttons to utilize this new font has resulted in slower loading times (previously rendering almost i ...

What sets apart the "+" and "~" selectors in CSS?

I've tried using both of these selectors, but I'm having trouble distinguishing between them. It appears that they are functioning in the same way. There must be a difference that I'm overlooking. ...

Component that dynamically changes background images in Vue

I'm currently working on a Vue banner that requires a dynamic background, but for some reason, it's not functioning as expected. I've experimented with different methods, and using an image tag like this works: <img :src="require(`@/asse ...

Utilizing Nginx with Angular2 for a seamless PathLocationStrategy implementation in html5

Angular2 is a single-page site, so all URL requests need to be redirected to index.html using Nginx. Below is the Nginx server block configuration: server { listen 8901; server_name my_server_ip; root /projects/my_site/dist; location /.+& ...

Customizing the field_error_proc in Rails is causing issues with the HTML layout

Within a rails application, I have customized the field_error_proc to enable inline error displays as shown below: https://i.sstatic.net/DjmdN.png The code snippet for achieving this functionality is outlined here: ActionView::Base.field_error_proc = pr ...

Set the height of the vertical scroll at a fixed 100% floatValue

Check out my creation at http://jsfiddle.net/ZygnV/ html, body { margin: 0; padding: 0; height: 100%; } .main-content-wrapper { height: 100%; overflow-y: hidden; white-space: nowrap; } .main-sidebar { display: inline-block; height: 1 ...

Add the bannercode snippet found on a webpage

I am currently facing an issue with appending a banner code to the end of a URL. The scenario is as follows: An individual receives an email with a link to a website (SITE1), where the URL includes a banner code, such as www.site1.com?banner=helloworld O ...

Aligning the navigation bar with 'float: left;' and 'float: right;' properties

I'm struggling with aligning the navigation buttons on my nav bar to the left and the signup/login links to the right. I attempted to create separate navbars for each, but it's causing issues in my code. I tried using ':last-child' but ...

Displaying a specific section of HTML only if a certain resource bundle key is present

Working with JSF and needing to load a bundle named Extra, I have encountered an issue. <f:loadBundle basename="com.ni.lib.extra.delivery.ExtraBundle" var="extra" /> Within the variable "extra", there exists a value known as downtime_notice. To imp ...

What is the best way to create a "select all" check box in HTML and display the selected values in a div?

$(function () { //This function selects all checkboxes and unchecks selectall if any checkbox is not checked. var checkall = $('#checkall'); var boxes = $('input[type="checkbox"]').not(checkall); checkall.click(function ...

Div flexes and compresses smaller than its content dimensions

Here's a link to the fiddle: check it out Take a look at a normal card below: https://i.sstatic.net/7Yqqv.png But when the browser window is resized, it shrinks to this: https://i.sstatic.net/1aexK.png This is the HTML structure: #product-list ...

What is the best way to smoothly transition an element into view, then make it disappear seamlessly by fading it

Issue My current code features a <button> that, upon a single click, updates the class of a <div> element to "fade-in" and inserts it into the DOM. This action causes the <div> to visually fade in once it's in the DOM. However, if I ...