What causes the size of an image to decrease when placed within an anchor tag?

Trying to add clickable social media icons, but when wrapped in an anchor tag the images shrink significantly.

<span class="iconspan">
                    <a href="https://www.instagram.com/lil_ijoez/" target="_blank"><img src="assets/icons/instagram.png" alt="instagram icon" class="icons"></a>
                    <img src="assets/icons/apple.png" alt="apple music icon" class="icons">
                    <img src="assets/icons/youtube.png" alt="youtube logo" class="icons">
                    <img src="assets/icons/soundcloud.png" alt="soundcloud logo" class="icons">
                    <img src="assets/icons/amazon.png" alt="amazon logo" class="icons">
                    <img src="assets/icons/spotify.png" alt="spotify logo" class="icons">
                </span>
.icons {
    width: 10%;
    padding: 2em 1em;
    -webkit-transform: scale(1);
    transform: scale(1);
    -webkit-transition: .3s ease-in-out;
    transition: .3s ease-in-out;
}

.icons:hover {
    -webkit-transform: scale(1.1);
    transform: scale(1.1);
}

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

view image description here

Answer №1

The width of the elements has been defined as a percentage, making them relative to the parent element rather than the span itself. This means that their size is now determined by a percentage of the anchor's width.

Answer №2

Because the presence of

<span class="iconspan">
turns it into a flex container, only its direct children will be treated as flex-items.

This means that .iconspan > a will be considered a flex-item, but .iconspan > a > img will not.

To resolve this, you can apply display: contents; to the a element. This property essentially ensures that all immediate children of a are treated as if they were immediate children of a's parent, thus rendering the img as a flex-item once again.

.iconspan > a {
    display: contents;
}

As a result, you can streamline your styles with the following adjustments:

span.iconspan { /* You may want to remove the word "span" from "iconspan". */
    display: flex;
    justify-content: center;
}

    span.iconspan > * {
        flex-basis: 10%;
        padding: 2em 1em;
        transition: transform 0.3s ease-in-out;

        /* Avoid specifying `-webkit-transform` unnecessarily. */
        /* Do not set `transform: scale(1)` in the default state as it creates a new stacking-context and impacts performance. */
    }
    span.iconspan > *:hover {
        transform: scale(1.1);
    }

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

Is it a mistake in the Jquery logic or a syntax error?

Is there a logic or syntax error causing one of the options when clicking the radio to not display the corresponding tables with the same number of option dates? <style> #ch2 ,#ch3 ,#ch4 ,#ch5 ,#ch6 ,#ch7 ,#ch8 ,#ch9 ,#ch10 ,#c ...

Positioning HTML elements using Python

Currently, I am utilizing lxml.html for some html parsing in Python. My goal is to roughly estimate the position of elements on a page as it would appear when rendered by a web browser. While precision is not necessary, overall correctness is desired. To ...

Display a jQuery loading window

Need help with displaying a loading div when making an ajax post request. I've tried the following code but it's not working. Can someone please assist in resolving this issue? $(document).ready(function() { $('a.pagerlink').click( ...

Extracting data from an HTML table on a website

I need assistance in generating a Python dictionary mapping color names to background colors from this color palette. What is the most effective method to extract the color name strings and corresponding background color hex values? The objective is to cr ...

Guide on setting up p-menubar in PrimeNG to expand in the opposite direction, from left to right, for the responsive

How can I modify the CSS styles or configure the p-menubar from PrimeNg to have it expand from right to left in the responsive version? Currently, when using the classes align-items-center flex justify-content-between, the menu remains stuck to the right e ...

Enhance Your jQuery Skills: Dynamically Apply Classes Based on URL Like a Pro!

Here is an example of HTML code for a progress meter: <div class="col-md-3" style="margin-left: -20px;"> <div class="progress-pos active" id="progess-1"> <div class="progress-pos-inner"> Login </div> </di ...

Switching between filters using AngularJS toggle buttons

Currently, we are in the process of converting a jQuery application into an Angular application using JavaScript. The existing jQuery app functions, but we aim to transform it into a full-fledged app utilizing the Angular framework. The main concept behin ...

CSS code that fixes a textarea at the bottom of a div

I need help placing a textarea at the bottom of a fixed div: <div id=msg> <div id=content> aaaaaaaannnnnnnnnn<br> aaaaaaaannnnnnnnnn<br> aaaaaaaannnnnnnnnn<br> </div> <div id=text> <textar ...

The issue with the class attribute being disregarded by Internet Explorer

Having trouble with a complex web page (JavaScript application) where an included style sheet has the following rule: .floatleft { float: left; margin-right: 10px; } There is a DIV element within that layout: <div class="floatleft" width="25%"> ...

Looking for assistance in creating a stunning portfolio showcase?

As I work on building my portfolio webpage, I've realized that with my limited knowledge of HTML/CSS, creating a great gallery might be challenging. In search of an efficient solution, I ventured across the web but couldn't find anything that ful ...

Top way to include an HTML and javascript file in an Ext.Panel within Sencha Touch

My main goal is to efficiently include external HTML files and display them on an Ext.Panel in Sencha touch 2.3 by creating a wrapper module for the HTML file that can be instantiated using xtype, with an external Javascript file for event handling. Updat ...

Perform an AJAX request to an encrypted URL with an unverified certificate

I'm experiencing an issue with my site that makes AJAX JSONP calls to a secured (SSL) web server. Everything works smoothly when using an unsecured (HTTP) web server, but once I switch to the SSL version, the call never returns. After checking with Fi ...

Issue encountered when toggling flip switch in Jquery Mobile

I am trying to create a calculator for my app using Jquery Mobile, but I am facing an issue with the flip toggle switch. Here is my script: <script type="text/javascript"> function dosis() { $peso = $('#peso').get(0).value $dosis = ...

How to Incorporate LessCSS into the Blueprint Framework?

Can LessCSS be integrated with Blueprint framework? What are the prerequisites for starting? ...

Using jQuery to reveal and conceal elements upon hover interaction

I have implemented a basic jquery function to display and hide a div when hovering over an anchor. However, the issue I am facing is that the div disappears when I move my cursor away from the anchor tag. I want to be able to interact with the div without ...

The HTML code does not seem to be acknowledging the CakePHP link

When using Cakephp to generate a link with Html->link, the code looks like this: echo $this->Html->link('Download',array( 'plugin'=> 'galleries', 'controller'=> 'galleries', 'a ...

Create a bokeh plot and save it as an HTML file without displaying it

Currently, I am utilizing Bokeh to generate HTML code that contains figures by employing the show method. However, this method automatically opens the default browser with the HTML displayed in it. My goal now is to save the HTML code without displaying i ...

Tips for creating several radio buttons with separate functionality using Bootstrap 5

Is there a way to create separation between these two groups of radio buttons? Whenever I select an option in one group, it automatically deselects the option in the other group. <!DOCTYPE html> <html lang="en"> <head> ...

Struggling to make align-content function properly in a CSS flexbox layout grid

Utilizing CSS flexbox for designing a grid of items that wrap on resizing the page. Wanting to achieve a horizontally centered grid, successfully done with justify-content: center;. However, facing an issue where the last box in some cases is centered inst ...

What is the best way for Selenium in C# to identify and locate a specific span element by its value

I've been experimenting with different locators, but I'm struggling to find a straightforward solution for identifying the dynamic number within this span using C# Selenium. Initially, my focus is just on locating the span itself. <span inven ...