Resizable icon next to inline element caused width adjustment

I have a group of individuals listed, each with two elements side by side: a "contact me" button (an 'a' element with a fontawesome icon) and a tag displaying the user type (span element). Some users do not have a tag, and when there is one present, the width of the icon in the 'a' element appears to be wider than necessary. Here is an example of how it appears:

https://i.sstatic.net/iKHja.png

As shown, the bottom user fits correctly while the top user has excess blue space on the right. Both users share the same classes and attributes since they are generated from the same loop.

This is the HTML code for the link+span:

.item-title {
  margin-bottom: 10px;
}

.item-btn-contact {
    margin-left: 10px;
    padding: 3px 10px;
    border-radius: 5px;
    background-color: #1b95e0;
    font-size: 80%;
    color: #fff;
    text-decoration: none;
}

.item-type-tag {
    margin-left: 10px;
    padding: 3px 5px;
    border-radius: 5px;
    background-color: #dedede;
    font-weight: bold;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet"/>
<div class="item-title">

  <a href="">xxxx</a>
  
  <a href="" class="item-btn-contact" title="Contattami">
    <i class="fas fa-envelope"></i>
  </a>

  <span class="item-type-tag">Allenatore</span>

</div>
<div class="item-title">

  <a href="">xxxx</a>
  
  <a href="" class="item-btn-contact" title="Contattami">
    <i class="fas fa-envelope"></i>
  </a>

</div>

I attempted to inspect if there were any variations in the computed styles of the two elements using javascript (considering the possibility of a ":last-child" selector), but both elements had identical maps (verified with getComputedStyle on both).

Whenever I modified the display property of the span element to block, flex, or other non-inline options, the other element resized correctly.

The only temporary solution I found was decreasing the icon width to .8em (currently set at 1em) and then implementing a last-child selector to resize it back to 1em when no span is present on the right. However, this isn't an ideal fix...

Could someone assist in identifying the cause or providing guidance on how to rectify this issue?

Answer №1

Modify the display property of item-btn-contact to be inline-block. It appears that the default display setting for a (which is inline) is causing issues with the size.

.item-title {
  margin-bottom: 10px;
}

.item-btn-contact {
    margin-left: 10px;
    padding: 3px 10px;
    border-radius: 5px;
    background-color: #1b95e0;
    font-size: 80%;
    color: #fff;
    text-decoration: none;
    display: inline-block;
}

.item-type-tag {
    margin-left: 10px;
    padding: 3px 5px;
    border-radius: 5px;
    background-color: #dedede;
    font-weight: bold;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet"/>
<div class="item-title">

  <a href="">xxxx</a>
  
  <a href="" class="item-btn-contact" title="Contattami">
    <i class="fas fa-envelope"></i>
  </a>

  <span class="item-type-tag">Allenatore</span>

</div>
<div class="item-title">

  <a href="">xxxx</a>
  
  <a href="" class="item-btn-contact" title="Contattami">
    <i class="fas fa-envelope"></i>
  </a>

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

Having trouble installing css-sprite on Windows 8.1 using NPM

Having trouble installing css-sprite on my Windows 8.1 system. Here's what I have installed so far: Windows 8.1 (x64) Node.js 0.12 (x86) NPM 2.5.1 (x86) Python 2.7.9 (x86) Visual Studio 2013 Express (x86) I tried to install using the command: npm ...

Combining the jquery-UI slider functionality with the canvas rotate() method

Is there a way to rotate an image using html2canvas plugin and jQuery UI slider? I am new to programming and need some guidance on how to achieve this feature. Here is my current progress: http://jsfiddle.net/davadi/3d3wbpt7/3/ ` $("#slider").slider({ ...

Guide on attaching an event to every dynamically created element in JavaScript

I'm currently generating 'li' elements dynamically using a loop and running into issues when it comes to assigning events to each generated element. My goal is to assign an onclick event to every li element that is created. Check out the co ...

Converting Data from MySQL and PHP to Excel

Is there a way to export human resource applications stored in my MySQL table as an Excel file? function exportExcel($filename='ExportExcel',$columns=array(),$data=array(),$replaceDotCol=array()){ global $connect; header('Content-Enc ...

Unable to load XML in Chrome using JQuery

Can anyone explain why the code below works in Firefox but not Chrome? I'm currently testing it on my local machine. Thanks for any insights you can provide! <html> <head> <script type="text/javascript" src="jquery.js"> ...

The default value is not displayed in the Angular dropdown menu

When using regular html select menus, if you create an option element with selected and disabled attributes and provide text for that option, the text will be displayed by default in the select menu. Below is a basic example of HTML code: <select name= ...

Trouble with Loading Google Place Autocomplete API in HTML

I utilized the Google MAP Place Autocomplete API for a web project. Click here to view the code and output. <form> <input id="origin-input" type="text" class="form-control" placeholder="From"/> <br/> <input id="de ...

Is there a glitch in Safari's CSS involving max-height?

Currently, I am in the process of developing a popup for a registration form. The CSS rules have been configured accordingly and after testing on various browsers, it has come to my attention that Safari is displaying an additional white space between elem ...

Setting a specific time for a div element with opacity: A step-by-step guide

Is there a way to adjust the timing for the appearance of the add-to-cart when hovering over the product-list-item? Currently, it appears when I hover over the item and disappears when I move my mouse away. .product-list-item { position: relative; w ...

Javascript auto submission fails to execute following the completion of the printer script

As someone new to javascript, I have a question. I have a function called sendToQuickPrinter() that prints correctly, but after it finishes executing, I need to automatically submit a form to return to my "cart.php" page. I feel like I'm almost there, ...

"Troubleshooting: Why isn't my Tailwindcss box shadow

I'm currently incorporating Tailwindcss into a React project to recreate the Star Wars website mobile menu. However, I am facing an issue where the box shadow added to the hamburger icon segments is not visible when the navigation drawer is opened. A ...

Developing my React application with Material UI. The fonts I've implemented don't appear consistent on Mac operating systems

Why does the font change in Mac and iOS platforms, and how can I ensure consistency across all devices? Here is an excerpt from my index.css file: body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto&apos ...

What is the purpose of utilizing jQuery for retrieving CSS resources?

Upon reviewing the Chrome Dev Tools screenshot, I am puzzled by the fact that my CSS assets are being fetched by jQuery. The CSS sheet is included in the normal way, using a <link rel="stylesheet"> tag in the <head> section, while jQu ...

The execution of a link in Firefox is blocked only when an active div is shown

The code includes an <a href> element that wraps around two div elements. One of the divs is only displayed when the link is clicked, and it appears above the other div. This setup serves as a visual feedback mechanism for user interaction. To see a ...

What is the best way to adjust the size of a Div slideshow using

I need help with creating a slideshow that covers my webpage width 100% and height 500px. The image resolution is 1200*575. Can someone assist me with this? CSS #slide{ width : 100%; height: 500px; } HTML <!DOCTYPE html> <html> ...

HTML video audio playing, but screen remains empty

I am facing an issue while trying to watch a video using HTML. The audio plays, but the video remains blank. The video is in MP4 format and can be found at this link. Interestingly, it works when downloaded and viewed, as my friend created it. I even tried ...

Tips for altering the design of a registration page

I'm struggling to modify my registration page layout so that the avatar is positioned on the left while the username, password input boxes are on the right. I attempted to use split divs without success and also tried adjusting the positioning of the ...

A guide to changing the height of a column in Bootstrap

I've utilized Bootstrap to create features in the HTML, and I'm attempting to make each box's height consistent. Check out a screenshot of the boxes here #hr-1 { width: 100px; margin-left: 20%; } #features { background-color: #f0 ...

Perform an action when the timer reaches zero

I am working with a database entry that contains the following information: { _id:"fdjshbjds564564sfsdf", shipmentCreationTime:"12:17 AM" shipmentExpiryTime:"12:32 AM" } My goal is to create a timer in the front end ...