Finding it difficult to grasp the space constraints associated with the figure tag in HTML5

I'm currently building a webpage using HTML5 that requires the use of 4 figure tags positioned next to each other in a horizontal line. Each figure tag consists of an image with an icon sized at 80X80px, along with a caption below it.

Here's an example of what I'm trying to achieve:

Issue: When I inspect the figure tag using developer tools, the dimensions show as 80px x 120 px, which makes sense considering the icon and caption combination. However, during rendering, it seems to be taking up more space than intended (even though the width is specified as 80px), causing the adjacent figure to shift further right than necessary. The code snippet appears like this:

<div id="figureIcons">
    <a href="" class="extLinks" target="_blank">
        <figure class="icons">
            <img class="linksIcons" src="icons/chrome_link.png" title="Website">
            <figcaption><b>HomePage</b><br />(Website)</figcaption>
        </figure>
    </a>

    <a href="" class="extLinks" target="_blank">
        <figure class="icons">
            <img class="linksIcons" src="icons/linkedin_link.png" title="LinkedIn Profile">
            <figcaption><b>Profile</b><br />(LinkedIn)</figcaption>
        </figure>
    </a>
</div>

The only CSS applied for this layout is:

figure.icons
{
    position:relative; 
    float:left;
    margin-top: 5px;
    margin-left: 1px;
}

This is the relevant CSS for the issue. Other assigned classes/IDs have not been utilized in the stylesheet yet.

What am I missing here? How can I correct this issue? I need to align 4 figures next to each other. Any help would be appreciated. Thank you!

Answer №1

To remove the default margins of a <figure>, you need to explicitly set its right and bottom margin values to 0 in the stylesheet.

In simpler terms, replace

margin-top: 5px;
margin-left: 1px;

with

margin:5px 0 0 1px;

Check out this example on fiddle.

The reason why the Inspector doesn't include the margins in the width calculation is that technically, margins are not considered part of the element itself; they are external to it. (Padding, on the other hand, would be included in the width calculation.)

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

What could be the reason behind the disappearance of text from the previously highlighted button in my calculator's "button grid" when I change the highlighted button?

Currently, I am in the midst of creating a tip calculator with a grid consisting of various percentage buttons. My main objective is to change the font and background color when any tip button is selected. Nevertheless, an issue has surfaced - whenever I h ...

inject the parameter into the embedded href using the following code: `javascript:function(" + param + ");`

I'm attempting to incorporate a call to a JavaScript function within a Leaflet popup. The objective is to link the showPopup() function to each feature added to the map. When the user clicks on a feature, there should be an "More info..." hyperlink th ...

Displaying Bootstrap Alert for a single occurrence

One issue I'm facing involves setting up alerts with Bootstrap. Initially, these alerts are hidden from view. However, when a rating is submitted using raty, an Ajax request is triggered. Upon successful completion of the request, an alert is displaye ...

Creating an Interactive Menu System with Nested Options in Angular 2

I have a JSON structure that I need to transform into a menu with sub-menus based on the value of the sub-menu_location field. Here's an example: { "data": [ { "menu_name": "Primary Operations", "enabled": true, "sub-menu_lo ...

Ways to transmit variable values through a URL?

I have an issue where I need to construct a URL using variable data. { this.state.countries.map((country, key) => { return <a key={country.iso2}> <img src="https://www.countryflags.io/{country.iso2}/shiny/24.png" /> </a& ...

What is the best way to align a table (datatable) to the left?

How can I align the table to the left without using float:left in the following code? Applying text-align: left to the parent element of the table doesn't seem to work as expected. http://jsfiddle.net/william/B4qJG/1 HTML: <div class="valueList" ...

Achieving consistent spacing between elements within a column in Bootstrap 5

Picture a bootstrap column filled with various elements such as divs, paragraphs, and links. How can I evenly space these elements inside the column without using margins or padding? I am looking for an automatic way for the elements to be spaced equally a ...

Struggles between ajax asp.net and jquery colliding

Within my project, I have incorporated numerous jquery files. After researching this issue yesterday, I came across a solution. I made the following adjustment: $(document).ready(function () { and substituted it with: function pageLoad() { An issue has ...

Updating the text box's font color to its original black shade

I have a form that includes dynamic text boxes fetching data from the backend. When a user clicks on a text box, the color of the text changes. Upon form submission, a confirmation message is displayed and I want the text box color to revert back to black. ...

Connecting an image to its corresponding content through hover effect

Can someone please assist me? I am trying to create a hover effect on an image with an "add to cart" link similar to what is shown here: I seem to be having trouble with the code, could you provide some guidance? .hunderter { background: url(http ...

What is the reason behind the success of this location?

Curious about the functionality of this particular JavaScript code with its corresponding HTML structure: function getCityChoice() { const location = document.querySelector("form").location.value; console.log(location) } <form name="reserve" a ...

Top strategies for creating a fully responsive HTML design

Currently, I am exploring the concept of responsiveness in my small projects for educational purposes. I have been researching websites such as: w3schools-mediaquery While I have come across some interesting insights, I am curious about how to effectivel ...

In IE11, the letter type list with the style of lower-alpha no longer displays proper indentation

When viewing on IE11, the list in lower-alpha style (list-style-type: lower-alpha) is missing indentation. However, the indentation remains intact when viewed on Chrome, Edge, and Firefox browsers. The code snippet below showcases some of the CSS styles be ...

Utilizing Bootstrap 4 to arrange each card in its own row

On small screens, I want Bootstrap to display 1 card per row, 2 cards per row on medium screens, and 3 cards per row on large screens. I'm using <div class="col-sm-12 col-md-6 col-lg-4"> and it's working for medium and large screens, but o ...

The java servlet for multi-input form validation using ajax is malfunctioning as it fails to display any error messages

My Ajax form validation is not functioning properly. Despite the code provided below, errors are not being displayed when the text fields are left empty. <form id="postMveForm" action="movieDetails"> <input type="text" name="mvetitle" id="mveTit ...

There seems to be an issue with the HTML link not redirecting properly, as it is directing to www.oldpage.com/http://www

Has anyone experienced a similar issue before? I can't figure out why this is happening. Here's the HTML code I'm using: <a href="www.google.com">www.google.com</a> Despite it appearing correct, when I click on the li ...

Is it possible to scroll the grid horizontally?

I have a grid that scrolls vertically, with columns adjusting their width automatically. .grid { display: grid; overflow-y: auto; grid-template-columns: repeat(auto-fit, minmax($min-column-width, 1fr)); } Now, I'm attempting to create a horizon ...

The functionality for selecting text in multiple dropdown menus using the .on method is currently limited to the first dropdown

Having trouble selecting an li element from a Bootstrap dropdown and displaying it in the dropdown box? I'm facing an issue where only the text from the first dropdown changes and the event for the second dropdown doesn't work. <div class="dr ...

Showing database information from MySQL in a concealed div using PHP

My HTML code for the div is as follows: <div id="ticketupdates" style="display:none;"> </div> It then contains PHP code like this: <?php $sql2=" SELECT ticket_seq, CONCAT(CONCAT(notes),'<br><br><a hr ...

Navigating to a Fresh Angular App Post Successful Login and Subscription

Hello everyone, I am currently working on a personal Angular project that involves two separate Angular applications. The first is the main application, and the second application is meant to be redirected to after login and subscription validation. Howev ...