When a CSS inline element encapsulates another inline replaced element

<div class="box">
  <span>
    <img src="https://picsum.photos/id/127/300/200" alt="" />
  </span>
</div>

The image has a width of 300px and height of 200px.

Although the image is a child element of the span, the height of the span is only 21px, not 200px or greater than 200px.


I believe I have found the explanation, thank you everybody!

Read more about it here

10.6.1 Inline, non-replaced elements

The height of the content area should be based on the font

Answer №1

To ensure proper display, be sure to specify the height and width of your images and consider using a span element with inline-block.

span {
  display: inline-block;
 }
 
 img {
  width: auto;
  height: auto;
 }
<div class="box">
  <span>
    <img src="https://picsum.photos/id/127/300/200" alt="" />
  <span/>
</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

Personalized element IDs and unique CSS styles

After editing the code snippet below... <div id="rt-utility"><div class="rt-block fp-roksprocket-grids-utility title5 jmoddiv"> I applied the changes in my custom.css file like this: #rt-utility .rt-block {CODE HERE} However, when attemptin ...

What sets srcset apart from media queries?

Can you explain the contrast between srcset and media query? In your opinion, which is more optimal and what scenarios are ideal for each? Appreciate it! ...

Tips for aligning an image of varying dimensions in the center

Although I've done some research and attempted to splice together code from various sources, including here, here, and other places, I'm still struggling with centering an image on a webpage. The page in question features three layered .png imag ...

Display the PDF without providing the option to download

When clicking on any of the PDF links, it will open in a new tab with options available in the PDF reader. https://i.sstatic.net/2bVB7.jpg I am looking to disable only the download button within the PDF. To elaborate further, a client will upload their ...

Put the SVG at the lower right corner of the image using Bootstrap

I'm currently attempting to insert an SVG into the lower right corner of an image within a bootstrap card. I experimented with a solution similar to this one: picture on the bottom right cornor of image, but when I apply CSS styles for the icon, my SV ...

Exploring the depths of CSS table-cell and the impact of percentage-based

During my exploration of Github, I came across a fascinating menu display: If you pay attention, each item in the menu is assigned an equal width. In CSS, we typically give it a percentage value - but why? It's interesting to note that the parent div ...

Adding Space Before Bullet Points in HTML: A Quick Guide

Is there a way to add space before bullet points? My requirements are as follows: This is paragraph 1 The first text line The second text line This is paragraph 2 The first text line The second text line I would greatly appreciate any ...

jQuery - translating and organizing names of countries

I have implemented a jQuery function to organize a list of country names based on the user's selected language code (via a language select dropdown). You can find more information on this topic in this related post. The translation of country names s ...

Strategies for adjusting text size to fit within a resizable div container

I'm facing an issue with a resizable div that has text inside. When I resize the div, the last line of the text goes beyond the boundaries of the div. How can I ensure that all the text fits within the resizable div while maintaining the appropriate f ...

How can you efficiently update another ng-model value based on a select input in AngularJS using ng-change?

<select data-ng-init="selectedItem='previewWidth = 1920; previewHeight = 1080'" data-ng-model="selectedItem" data-ng-change="GetNewData(); {{selectedItem}}"> <option value="previewWidth = 1920; previe ...

PHP code for turning an email address into a clickable link

While I was able to discover how to convert a URL into a clickable link using PHP here, I am now curious if anyone has a solution for the same functionality but with an email address. Any help would be appreciated! Thank you! ...

Only implement $(document).on(...) for every JQuery request

As someone new to Jquery, I'm facing challenges in grasping its functionality. Specifically, my struggle lies in setting up an event listener on an i element with the class of .dataPickerIcon, which should respond to a click by inserting more HTML usi ...

Differences in rendering of HTML select element between Chrome on macOS and Chrome on Windows

During testing of a section of the app at my workplace, it was discovered that dropdowns and select elements in a specific UI scenario appeared differently on Chrome for Windows and Ubuntu compared to Chrome for macOS. I attempted to analyze the elements ...

Site Having Trouble Displaying Image

I'm currently working on a Bridgetown website using Bootstrap 5, and I've encountered an issue with adding an image that won't show up on the site. This is what it currently looks like: https://i.sstatic.net/IUR7x.jpg Code <nav class=&quo ...

Is it possible for me to interact with different elements upon hovering?

html, <div id="first"> <a>Click here</a> </div> <div id=second"> second div content </div> css, #first a:hover{ color:blue; /*change color on hover */ #second{ background:blue; } } In ...

Locate the image in the table by searching for the alt attribute and then show the entire row

I am looking to use the alt attribute of images in a table to search and display the entire row using javascript or jquery. <div class="input-group"> <span class="input-group-addon">Filter</span> <input id=& ...

Adjust the height of videos automatically on columns

I need help figuring out how to display two videos with different dimensions side by side without any weird gaps. I've already tried using flex display with no luck. My current code looks like this: <div class="row"> <d ...

Ways to remove the default classes added by ngbootstrap

My current challenge involves utilizing ngbootstrap for popovers, yet desiring to override its default styling. Specifically, I have a form that should function as a popover triggered by a button click, and it needs to maintain its own distinct styles. Up ...

What is preventing the src attribute from loading inside a <picture> element?

<picture> <source type="image/webp" srcset="images/me.webp"> <img id="avatar" src="images/me.webp" alt="Me"> </picture> Whenever I utilize the picture element, the image fails to load along with the other resources in the brows ...

When two rectangles are created at the same coordinates (x, y) in SVG, it results in an unexpected border appearing

.rect-x { fill: red; } .rect-y { fill: pink; } <svg viewBox="0 0 1024 768"> <rect class="rect-x" x="0" y="0" width="100" height="100"></rect> <rect class="rect-y" x="0" y="0" width="100" height="100"></rect> </svg& ...