The trio of divs positioned centrally on the webpage feature a vertical displacement

Gratitude to everyone for your responses. It turns out that the issue was related to the original image sizes. Being new to StackOverflow, I've learned the importance of using placeholder images. Much appreciated!

While working on a website design project, I encountered a puzzling error that has me stumped. I have 3 <div> elements nested inside <a> tags and centered using text-align center. However, there seems to be a vertical misalignment between the <div> and/or the <a> elements. Any guidance on resolving this would be highly valued.

.iconCardCont {
  text-align: center;
}

.iconCard div {
  background-color: #86b55bff;
  width: 160px;
  height: 200px;
  display: inline-block;
  text-align: center;
  margin-left: 20px;
  margin-right: 20px;
}

.iconCard img {
  margin-top: 20px;
}

.iconCard h2 {
  background-color: white;
  width: 140px;
  margin-left: auto;
  margin-right: auto;
  color: #86b55bff;
}

.iconCard a {
  vertical-align: bottom;
  overflow: hidden;
}
<section class="iconCardCont">
  <a href="" class="iconCard">
    <div><img src="http://via.placeholder.com/98x105">
      <h2>Calendar</h2>
    </div>
  </a>
  <a href="" class="iconCard">
    <div><img src="http://via.placeholder.com/98x105">
      <h2>Signup</h2>
    </div>
  </a>
  <a href="" class="iconCard">
    <div><img src="http://via.placeholder.com/98x105">
      <h2>Info</h2>
    </div>
  </a>
</section>

Answer №1

Upon running the provided snippet, you will notice that all items align perfectly, contrary to what is shown in your screenshot. This issue persists even with intact images (consider using for queries here). It is likely that there is another factor in your code causing the problem.

It's worth mentioning that in your CSS, .iconCard a doesn't have any specific target as your <a> tag already carries that class; it is searching for other <a> tags within it.

I believe you may be looking for the vertical-align property, but this needs to be set on the container itself rather than the items inside it.

.iconCardCont {
  text-align: center;
}

.iconCard div {
  background-color: #86b55bff;
  width: 160px;
  height: 200px;
  display: inline-block;
  text-align: center;
  margin-left: 20px;
  margin-right: 20px;
}

.iconCard img {
  margin-top: 20px;
}

.iconCard h2 {
  background-color: white;
  width: 140px;
  margin-left: auto;
  margin-right: auto;
  color: #86b55bff;
}

.iconCard a {
  vertical-align: bottom;
  overflow: hidden;
}
<section class="iconCardCont">
  <a href="" class="iconCard">
    <div><img src="http://via.placeholder.com/150x100">
      <h2>Calendar</h2>
    </div>
  </a>
  <a href="" class="iconCard">
    <div><img src="http://via.placeholder.com/150x100">
      <h2>Signup</h2>
    </div>
  </a>
  <a href="" class="iconCard">
    <div><img src="http://via.placeholder.com/150x100">
      <h2>Info</h2>
    </div>
  </a>
</section>

Answer №2

Could it be that you are referring to the area marked with dashes?

  • One method is to set the parent's font size to zero and assign a font size to the child element.

.iconCardCont {
  text-align: center;
  font-size: 0;
}

.iconCard div {
  background-color: #86b55bff;
  width: 160px;
  height: 200px;
  display: inline-block;
  text-align: center;
  margin-left: 20px;
  margin-right: 20px;
  font-size: 20px;
}

.iconCard img {
  margin-top: 20px;
}

.iconCard h2 {
  background-color: white;
  width: 140px;
  margin-left: auto;
  margin-right: auto;
  color: #86b55bff;
}

.iconCard a {
  vertical-align: bottom;
  overflow: hidden;
}
<section class="iconCardCont">
  <a href="" class="iconCard">
    <div><img src="CalendarIcon.png">
      <h2>Calendar</h2>
    </div>
  </a>
  <a href="" class="iconCard">
    <div><img src="SignupIcon.png">
      <h2>Signup</h2>
    </div>
  </a>
  <a href="" class="iconCard">
    <div><img src="InfoIcon.png">
      <h2>Info</h2>
    </div>
  </a>
</section>

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

Steps to Display a JavaScript Function Two Times on a Single Page

Hey there! I'm currently working on a project where I need to display the output of my function in two separate divs. However, when I try to simply output the same ID, it messes up the whole code and the output becomes null. Here's the code snipp ...

When a user hovers over the image, a button is revealed

I have a test page on my website: If you'd like to check it out, feel free to visit: I am trying to create a feature where when you hover over an image, a black button with text and links will appear. When you move your mouse away from the image, ...

Is it possible to create a responsive Material UI tab design?

How can I make the Material UI tab react component responsive? Check out the documentation for MATERIAL UI TAB here If I have multiple tab items with a search bar like shown below, how can I ensure that the input component stretches the whole width of th ...

Steps to make a sliding tab

I am currently faced with the challenge of coding the support tab on the right side of this page - . The tab currently slides out when clicked. I found the current tab slide-out effect here: My goal is to have both the main tab and the side tab appear wh ...

Tips for designing a masonry grid with Bootstrap 4

I'm attempting to achieve a specific layout using Bootstrap 4, JavaScript, CSS, and HTML. I have not been able to find something similar on Stack Overflow, but I did come across the Bootstrap 4 Cards documentation. However, I am unsure if this is the ...

What are some tips for leveraging aframe in order to achieve a captivating 360 video effect?

SCENARIO Inspired by the immersive effect showcased here, we aim to utilize a 360 video as the central feature of an extended webpage layout. ISSUE Exploring options, I experimented with Mozilla's aframe, demonstrated here. Yet, integrating an < ...

CSS Hover Effects on Navigation Bar Not Displaying as Expected

I was aiming to make one of my Navbar tabs stand out by having a different appearance compared to the others. However, there seems to be an issue with the text color for this particular tab in the hover state - it works inconsistently across different brow ...

Choosing Between EMs and Pixels for Font Sizes: A 2011 Perspective

In the past, EMs were favored over pixels for font size because they could scale with IE6 while pixels could not. Nowadays, modern browsers can handle pixel-sized font scaling correctly. Another advantage of EMs is that they cascade, unlike pixels. But if ...

Leveraging @font-face for various styles and designs

Google web fonts presents the Droid Serif font in these styles: DroidSerif.ttf DroidSerif-Bold.ttf DroidSerif-BoldItalic.ttf DroidSerif-Italic.ttf I am interested in using the @font-face CSS rule to import all of these variations with the "Droid Serif" f ...

Adjust the positioning of an element to the right within another element

Having some difficulties with my calendar app as I am unable to position the date square to the top right. I have tried using float:right and align-text: right but it has not worked. Here's a jsfiddle link along with the code: Styling (CSS) table.ca ...

Don't forget to preserve the hover state of divs even after refreshing

I recently added a navigation bar that expands in width upon hovering over it. For an illustration, check out this example: http://jsfiddle.net/Gsj27/822/ However, I encountered an issue when clicking on a button within the hover effect area. After load ...

Add class or id dynamically when clicked

How can I dynamically change the CSS color of a roller-banner div based on user input? I have a codepen setup where I want to capture the class of the clicked element (e.g. colour3), and then apply that as an ID or class to the roller-banner div. Codepen ...

Having difficulty in getting the heading to align with the left side

Looking for some guidance on creating a dynamic page similar to this DemoPage. The goal is to have the content editable and pulling data from the backend. However, I am facing challenges in achieving the desired layout as shown in the sample page CreatedPa ...

Bug in canvas rendering for Chrome versions 94 and 95

The Canvas drawing functionality in the Chrome browser seems to have some visible bugs. Here's an example of code that demonstrates this issue: const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d&apo ...

Definition list with alternating left and right alignments

Here is a definition list with a specific styling: dl { margin: 0; } dl.interview dt { color: #A8A67A; } dl.interview dd { margin-left: 0; } .interview dt:before { content: 'Q. '; } .interview dd:before { content: 'A. ...

What is the best method to retrieve duplicate fields from a database in HTML5?

this.db.transaction(function (tx) { tx.executeSql('SELECT tsk.*, cont.firstName, cont.lastName ,cont1.firstName, cont1.lastName, list.listId FROM tbl_tasks tsk, tbl_contacts cont,tbl_contactequests cont1, tbl_lists list WHE ...

Customization disrupts the uniformity of button dimensions

When localizing a web application, we encountered an issue with browsers using different fonts for different languages. This led to the height of certain HTML objects changing, especially noticeable with input buttons. While this behavior is expected, how ...

hover over the picture with your cursor

Struggling with jquery and css, could use some assistance :) Check out my html code below: <html> <head> //myscripts <script> $(document).ready(function(){ $(".cover").hover(function(){ //the function i need to write } ...

Ways to style a div element in CSS to achieve a unique shape

Hello there! I'm looking to achieve a tilted background div effect. Anyone have any tips or ideas on how I can do this? I'm new to web development and would appreciate the guidance. https://i.stack.imgur.com/wyj1X.png ...

At times, the CSS fails to load at first and does not refresh correctly when using F5 or CTRL F5, yet it occasionally loads when clicking on links

After dedicating a full day to trying to solve this issue, I am reaching out for some assistance. As a newcomer here, I apologize if this question has been asked before (I did search extensively and found nothing). The website I'm constructing for my ...