Unusual contrast in absolute placement behavior of figure and div elements

While practicing CSS rules, I came across a problem with a percentage deviation of an absolute positioned element left:5%. Interestingly, I noticed that this issue occurs when using the figure tag, but not with the div element. To understand the problem, you need to resize or scale back the page. The deviation from the left side of the viewport varies between the two versions. I am looking to comprehend why this happens and how to resolve it in the figure version. I have included the code snippets and links to jsfiddles for both versions below.

<html lang="it">

<head>
 <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
 <!--  <meta name="viewport" content="width=device-width, initial-scale=1.0"> Non si mette perchè non ho istruzioni reponsive precise come media query-->
<meta name="description" content="Sito con intestazione con sfondo. Esercizio si rifa al libro css master, esercizio finisched-example.html del capitolo 5">
<meta charset="UTF-8">
<title>Cat Page</title>;

<style type="text/css">
  body {
    padding: 0;
    margin: 0;
    font-family: "Helvetica Neue", Arial, sans-serif;
  }

  .sfondo-intro {
    position: relative;
    height: 600px;
    background-image: url(https://imagizer.imageshack.com/img923/4457/MeXAJj.jpg);
    background-position: 50% 30%;
    background-size: cover;
  }

  .profile-box {
    width: 160px;
    background-color: #FFF;
    position: absolute;
    left: 5%;
    bottom: -60px;
    -webkit-border-radius: .5em;
    border-radius: .5em;
    padding: .5em;
  }

  .profile-box img {
    max-width: 100%;
    height: auto;
  }

  .didascalia {
    text-align: center;
    font-size: 1.2em;
    color: #555;
    font-weight: 600;
  }

</style>

 </head>



  <body>

<header class="sfondo-intro" role="banner">
  <div class="profile-box">
    <img src="https://imagizer.imageshack.com/img924/606/oMPbxW.jpg" alt="Charles The Cat" />
    <figcaption class="didascalia">@CharlesTheCat</figcaption>
  </div>

  </header>
  </body>

</html>

Code with div

Here is another version where the figure element is used instead of the div element:

  <!DOCTYPE html>

  <html lang="it">

 <head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="description" content="Sito con intestazione con sfondo. Esercizio si rifa al libro css master, esercizio finisched-example.html del capitolo 5">
<meta charset="UTF-8">
<title>Cat Page</title>

    <style type="text/css">
    body {
    padding: 0;
    margin: 0;
    font-family: "Helvetica Neue", Arial, sans-serif;
  }

  .sfondo-intro {
    position: relative;
    height: 600px;
    background-image: url(https://imagizer.imageshack.com/img923/4457/MeXAJj.jpg);
    background-position: 50% 30%;
    background-size: cover;
  }

  .profile-box {
    width: 160px;
    background-color: #FFF;
    position: absolute;
    left: 5%;
    bottom: -60px;
    -webkit-border-radius: .5em;
    border-radius: .5em;
    padding: .5em;
  }

  .profile-box img {
    max-width: 100%;
    height: auto;
  }

  .didascalia {
    text-align: center;
    font-size: 1.2em;
    color: #555;
    font-weight: 600;
  }

   </style>

 </head>



<body>

<header class="sfondo-intro" role="banner">
  <figure class="profile-box">
    <img src="https://imagizer.imageshack.com/img924/606/oMPbxW.jpg" alt="Charles The Cat" />
    <figcaption class="didascalia">@CharlesTheCat</figcaption>
  </figure>

</header>
</body>

</html>

Second version with figure

Answer №1

By default, certain tags come with styling from the user agent, and the figure element may have some margins applied. To troubleshoot issues like this, you can utilize tools such as the Google Developer Console (Ctrl + I on Chrome for Windows or Linux) to inspect which styles are affecting an element. When the same CSS behaves differently with various tags, it is often due to differences in default styling.

To resolve this particular issue, consider adding margin: 0 to your figure element's styling.

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

When the click event is triggered on the modal, the page suddenly jumps to the top while applying the style of hiding the element

After implementing a modal that appears upon clicking an element on my webpage, I encountered an issue when trying to close it. I added an event listener to the 'close' link element in the top right corner of the modal with the following code sni ...

Is the custom cursor feature malfunctioning in IE9?

In my form, I have a web browser control that uses a custom cursor in the CSS code. Everything appears to be working fine in IE8. Css Code cursor: url(AppDirectiry\Classes\QClasses\ClsDesignHtml\Cursors\arrow.ani); However, it s ...

Setting the default value in a Select tag using React

Within this particular Select tag, the goal is to establish an initial value and assign that value to a variable named name. The Select tag itself includes the following: <Field name="data.account" render={({ field: { name, ...restFieldProps } }) = ...

Numerous inline notations in html code

I need help figuring out how to prevent a hyperlink from opening a new tab by commenting out the HTML code. <a href="<!--http://www.google.com=-->" target="_blank" onclick="javascript:alert('Navigation Prevented')">CLICK HERE FOR GOO ...

Gradually reveal each page as it loads while a spinner rotates in anticipation

I am attempting to create a fade-in effect for the entire page once it has finished loading, This is my current code: <script type="text/javascript"> $(window).bind("load", function() { $('#overlay').fadeOut(function() { ...

horizontal menu consolidation

Web Design <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Online Hangout</title> <meta http-equiv="Content-Type" content="text ...

What is the best way to adjust the height of a row in a Material UI table using CSS

I've been attempting to establish a row height of 30px for a table (https://material-ui.com/components/tables/), but it seems that the minimum I can set is 53. Why is this restriction in place? How can I adjust the row height to 30px using CSS based ...

Every time I attempt to visit my website on a mobile device, it seems to appear larger than normal, as

After developing a responsive website and adding media queries to make it mobile-friendly, I encountered an issue. Despite my efforts, the website's width is still larger than the mobile viewport, requiring users to zoom out to view it properly as sho ...

Using "-webkit-overflow-scrolling: touch" can cause issues with the CSS 3D perspective rendering

Looking for a solution specifically for iOS Safari Using -webkit-overflow-scrolling: touch seems to disrupt the 3d perspective on iOS devices. Check out the demonstration on CodePen. HTML <div class="pers"> <div class="scroll"> <di ...

Tips for moving the title to the next line within a card design

I'm currently working on an antd Card and I am trying to figure out how to display the title on two lines if it is too long. For example, instead of showing "This title needs to go to ne...", I would like it to be split into two lines as "This title n ...

Using Tailwind CSS to center a NexJS <Image /> component within a modal

In an effort to style my MapBoxGL popup content, I am working on aligning the text above the image to the left and centering the image below within the popup. As shown in the image below, this is currently proving to be a challenge as I transition from usi ...

Organize icons within a container that spans the entire height

I am looking to organize multiple icons within a container that spans the entire height of the website, rather than just the viewport. Currently, I am only able to achieve the height of the viewport using the following code: .full-container { posit ...

Using the v-for loop to generate radio inputs results in selecting multiple radio buttons with identical values

Having a bit of trouble explaining, I've developed a basic rating system that utilizes input type ="radio" for an array of products. By using v-for="product in products", I iterate through the array and display all the products on the webpage. ...

Setting the z-index of inner links to be greater than the parent container's z-index

I'm curious if something like this could work: <div class="arrow-left" style="z-index:2; position: fixed; height: 100%; width: 100%;"></div> <div class="meta" style="z-index:1; position: relative;"> <div class="description"&g ...

The secrets of enchanting jQuery CSS effects

https://css-tricks.com/examples/MagicLine/ That's the URL I am currently using. However, it relies on <script src='//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js'></script> There are other scripts that need <script ...

The Reason Behind Angular Error when Using CSS Custom Tags

I have the following SCSS code: main{ width: 100%; height: 840px; /*background: red;*/ margin: 10px auto; position: relative; padding: 5px 0; } section{ width: 98%; height: 600px; margin: auto; display: flex; ...

"Discover the step-by-step process of transforming an input field value into a checkbox with

I've been experimenting with creating a To-Do list using HTML, CSS, and Javascript. I've managed to capture the input field value in a fieldset so far. However, my goal is to find a way to transform the input field value from the textfield into a ...

Exploring IndexedDB with Multi-dimensional Relationships

How do you manage many-to-many relationships in IndexedDB systems? For instance, let's consider a scenario where there is a Blog object to represent a blog post and a Tag object for tagging the posts. A single Blog can have multiple tags, and each ta ...

Adding a Class with jQuery On Click Event

Trying to troubleshoot why this code isn't functioning: https://jsfiddle.net/bv6ort3g/ HTML: <div class="all-btn">All Button</div> <div class="item all"> item 1 </div> <div class="item all"> item 2 </div> <di ...

How to Fix Items Being Pushed Down by 'Particleground' Jquery Plugin Due to Z-Index and Positioning

I'm grappling with understanding z-index and positioning, despite reading various questions and articles on the topic. Currently, I'm attempting to incorporate a Jquery Plugin called 'Particleground': https://github.com/jnicol/particle ...