Take the size of an image

Asked

Viewed 438 times

1

There is the possibility to take the size via javascript of an external image to my directory?

For example in this use:

.divExterna{
background-image:url(http://www.backsite.com.br/datafiles/suite/escritorio/aplicativo/conteudo/album_fotografico/769.jpg),
height: seu_tamanho
}

I would like to take your size to apply as my div’s height.

1 answer

1


So (as it has structured css) will not give because the image is in the background, can however do so:

div {
 display: inline-block;
 border: 2px solid yellow; /* isto é só para ver a div (altura/comprimento) */
 height: 150px;
}
img {
   height: 100%; 
}
<div>
  <img src="https://catracalivre.com.br/wp-content/uploads/2015/10/imagens-3D_11.gif">
</div>

This way the image will always have the height (height) that defined in the parent element (div in this case)

  • then the point is that I work with mobiles, and I would like the div to have real size image, there would be no way I would rescue that value in any way?

  • @Henricão, not with javascript... You cannot navigate (as far as I know) the directories and see the contents, you can only see the size of an element that exists in the DOM. But this works in mobile also, the image so is the height that you set for div

  • I will try to apply this, thank you very much for the feedback

  • You’re welcome @Henricão

Browser other questions tagged

You are not signed in. Login or sign up in order to post.