Adjust the alignment of images and resize them while also removing any unnecessary margins

I am seeking assistance on how to adjust image alignment and eliminate unwanted margins. My goal is to center align the items, however, there appears to be a margin (referred to as the orange zone) that I cannot remove.

.content {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 20px;
  width: 100%;
}

.content__row {
  display: flex;
  width: 100%;
  margin: 5px 0;
}

.content__img {
  display: flex;
  width: 80%;
  height: 90%;
  padding: 0%;
}

.content__a {
  text-decoration: none;
  align-items: center;
}

.content__p {
  align-items: center;
  text-align: center;
  width: 80%;
  font-size: 35px;
  font-weight: 900;
  font-family: 'Ubuntu', sans-serif;
  color: rgb(39, 39, 255);
}
<div class="content">
  <div class="content__row">
    <a class="content__a" href="#">
      <img class="content__img" src="https://via.placeholder.com/300x600" alt="">
      <p class="content__p">COMPILARE
        <br>
        <span class="content__span">730?</span>
      </p>
    </a>
    <a class="content__a" href="#">
      <img class="content__img" src="https://via.placeholder.com/300x600" alt="">
      <p class="content__p">CALCOLARE
        <br>
        <span class="content__span">L'ISEE?</span>
      </p>
    </a>
    <a class="content__a" href="#">
      <img class="content__img" src="https://via.placeholder.com/300x600" alt="">
      <p class="content__p">CALCOLARE
        <br>
        <span class="content__span">L'ISEE?</span>
      </p>
    </a>
  </div>
</div>

Answer №1

Essentially, by setting the width of your <a> elements to 30%, you have leftover space on the right side due to the lack of justify-content property in the .content__row flexbox. To address this, consider adding

justify-content: space-between; (or around)
to your .column__row class.

Here are a few observations:

It's unclear why you're applying the flex property to your images. Transforming your <a> elements into column flexboxes could eliminate the unnecessary space between your image and <p> tags (a common issue).

Explore incorporating the object-fit: cover; attribute to your images for the ability to resize them without concerns about distortion.

Answer №2

Streamlined CSS by removing unnecessary elements and incorporating a few new ones. Refer to the comments in the CSS section for details.

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

.content {
  display: flex;
  padding: 20px;
}

.content__row {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 20px; /* add */
}

.content__a {
  text-decoration: none;
  flex: 1;
}

.content__img {
  height: 200px;     /* add */
  width: 100%;       /* add */
  object-fit: cover; /* add */
}

.content__p {
  text-align: center;
  font: 900 normal 1rem/1.5 Ubuntu, sans-serif;
}
<div class="content">
  <div class="content__row">
    <a class="content__a" href="#">
      <img class="content__img" src="http://placekitten.com/300/300" alt="">
      <p class="content__p">COMPILARE<br><span class="content__span">730?</span></p>
    </a>
    <a class="content__a" href="#">
      <img class="content__img" src="http://placekitten.com/300/300" alt="">
      <p class="content__p">CALCOLARE<br><span class="content__span">L'ISEE?</span></p>
    </a>
    <a class="content__a" href="#">
      <img class="content__img" src="http://placekitten.com/300/300" alt="">
      <p class="content__p">CALCOLARE<br><span class="content__span">L'ISEE?</span></p>
    </a>
  </div>
</div>

Answer №3

There seems to be a CSS issue with the couple.

  • To fix the issue, remove width: 80%; from .content__p as it restricts the width of the paragraph tag.
  • If you need a full-width image, remove width: 80% from .content__img. Alternatively, if you do use width: 80%;, add margin: 0 auto; for equal spacing on both sides of the image.
  • I have taken out height: 90% from .content__img as it may look odd with a restricted height (optional).
  • Delete padding: 20px; from .content to prevent unwanted horizontal scrolling on the page.
  • For .content_a, include
    display: flex; flex-direction: column; flex: 1;
    to eliminate blank space to the right side of the three elements.

Check out the Working Fiddle below:

.content {
  display: flex;
  justify-content: space-around;
  align-items: center;
  /* Removed padding to prevent scroll */
  /* padding: 20px; */
  width: 100%;
}

.content__row {
  display: flex;
  width: 100%;
  margin: 5px 0;
}

.content__img {
  display: flex;
  /* Do not restrict height */
  /* height: 90%; */
  padding: 0%;
  /* Restrict width only when necessary or else comment this out */
  width: 80%;
  /* If setting a width value, apply margin: 0 auto to center-align image */
  margin: 0 auto;
}

.content__a {
  text-decoration: none;
  align-items: center;
  /* Added to eliminate blank space after 3 elements */
  display: flex;
  flex-direction: column;
  flex: 1;
}

.content__p {
  align-items: center;
  text-align: center;
  /* Do not restrict width */
  /* width: 80%; */
  font-size: 35px;
  font-weight: 900;
  font-family: 'Ubuntu', sans-serif;
  color: rgb(39, 39, 255);
}
<div class="content">
<div class="content__row">
  <a class="content__a" href="#">
    <img class="content__img" src="https://via.placeholder.com/400" alt="">
    <p class="content__p">
      COMPILARE
      <br>
      <span class="content__span">730?</span>
    </p>
  </a>
  <a class="content__a" href="#">
    <img class="content__img" src="https://via.placeholder.com/400" alt="">
    <p class="content__p">
      CALCOLARE
      <br>
      <span class="content__span">L'ISEE?</span>
    </p>
  </a>
  <a class="content__a" href="#">
    <img class="content__img" src="https://via.placeholder.com/400" alt="">
    <p class="content__p">
      CALCOLARE
      <br>
      <span class="content__span">L'ISEE?</span>
    </p>
  </ahref>
</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

Creating a mat-grid-list using Angular Material involves adding the necessary dependencies and components

I am encountering an issue while attempting to set up a mat-grid-list with Angular Material. Unfortunately, nothing is displaying on my page. Here is the component info-section : <div class="mat-grid-list" cols="4" rowHeight="1 ...

Obtaining Beverage Overall with Loop

I am currently using a function to calculate the total of each drink, with a total of 5 drinks: var totalEstimate = 0; var locoCost = 0; var blackCost = 0; function calcLoco() { totalEstimate -= locoCost; locoCost = docume ...

Challenges faced when creating a dynamic HTML and CSS slider

I recently added some code from a CodePen to my website. While the code is functioning correctly, it seems to be causing issues with other content on my page such as links and images. Any idea why this might be happening and how can I fix it? :) HTML &l ...

The hover effect on sibling elements is not functioning for the <img> tag

When you hover over the image displayed within the <div class="like absolute">, the image within the <div class="balloons absolute"> doesn't appear. <div id="container" class="relative"> <div class="like absolute"> ...

A guide on iterating and accessing Vue data in a loop

I am looking to iterate through my code in order to extract the value of each form input. This is to ultimately display a total score and severity score based on the user's inputs. The total score will count the number of symptoms present (0-3), while ...

Adding a div element with a background behind a text element using Jquery

Is there a way to position an absolute div behind text or images while staying in front of background images? I have content with background images behind the text, so setting the z-index of the absolute div to -1 won't work. Any suggestions on how to ...

How to display only a portion of content using UI Bootstrap collapse feature

In my Angular.js application, I currently have a row of buttons that open up new routes to display partial views. Now, I need to modify some of these buttons to trigger a ui.bootstrap Collapse feature with the view inside it. The template code from the ui. ...

Unlock the Power of Vue Draggable in Vue.js 3 with These Simple Steps

When attempting to implement Draggable in Vue.js 3, I encountered an error message: VueCompilerError: v-slot can only be used on components or <template> tags. Below is a snippet of my code: <draggable tag="transiton-group" name="s ...

Issue: Troubile in fetching CSS file from CDN and using local copy as fallback, What is the solution?

I previously inquired about this issue, however, I did not receive a satisfactory solution. Therefore, here I am asking again for your assistance. I am attempting to retrieve my CSS from an external CDN service, such as http://cdn.example.com/. This scrip ...

Is there a way to create an attribute for a label that is connected to two text field inputs in HTML?

We are using IBM Rational Policy Test to scan our codes and it has identified a defect with the username and password fields, requesting a label with the "for" attribute. Is there a way to add a label with the "for" attribute that will not be displayed on ...

Text and Image Coordination

I'm encountering some challenges with a specific section. My goal is for it to resemble this. However, I am currently achieving something different, like this. .timeline { text-align: center; } #about-us { ul { &:before { ...

Whenever I minimize the screen, certain column text is unable to be seen within the Td element

I have incorporated an HTML table inside a responsive-table div tag. In the numeric column of the table, there are decimal numbers. However, when I reduce the page size to fit smaller screens, some parts of the numeric values become invisible. The visibili ...

I'm having trouble getting the Bootstrap 5 Carousel to work, even though I directly copied the code from the official website

Currently, I am designing a webpage utilizing Bootstrap 5 and incorporating the CDN for functionality. Although, when attempting to implement their carousel feature, it does not seem to be functioning as expected. The only modification I have made to their ...

jQuery registers the enter event, but does not proceed to trigger the enter action

Hey there, I've been experimenting with jQuery to capture the enter event. Something peculiar is happening though - after pressing enter in the text area, an alert pops up but the text gets entered only after that. Despite trying various solutions, I ...

Ensure the HTML table's <td> cell width automatically adjusts to accommodate the image, regardless of its dimensions

Has anyone encountered a strange issue while building an HTML table for an HTML email? Whenever I insert an image into a <td>, it causes the cell to expand to its maximum width, affecting all the columns to the right by resizing them to their minimum ...

The columns in CSS grid-template are refusing to change despite the media query code being applied and active

Currently, I am facing an issue while working on a site plugin and trying to utilize CSS grid to showcase posts. Despite the media query being active according to the inspector, the modification in the template columns is not reflecting as expected. Check ...

Maintain the aspect ratio of an image using CSS and flexbox styling

I have a gallery of images that looks great on a full-size PC screen. However, when I resize it for viewing on a phone, the aspect ratio is not maintained and the images only stretch in width. Currently, this is how it appears: https://gyazo.com/a1f605bb4 ...

Abstract forms on the canvas are dancing in a strange and unusual rhythm

As a beginner in web design, I've made progress but still have questions. Can someone help explain this to me? Here is how a specific section on my website is set up: https://i.sstatic.net/8ntpR.png I'm working on splitting the screen with 40% ...

The TTF font is not showing up on the webpage when applying the @font-family property

I have been attempting to incorporate a custom font into a website that I am developing using @Font-Face, but unfortunately it is not functioning as expected. Even though I followed the instructions provided in the link above, the font does not seem to be ...

Creating a Django template with an HTML button that points to a foreign key reference

I am fairly new to working with Django and I am having trouble understanding how foreign keys work in my specific case. I have gone through numerous tutorials and discussions, but haven't been able to find a clear answer. Let me provide some context: ...