Bugle margins in CSS

Asked

Viewed 37 times

-1

I’m trying to put an edge on an image, but the result is that the margin extends across the horizontal of the page, as shown in the print. inserir a descrição da imagem aqui

The idea is that the margin is around the image and its legend...

In HTML:

<figure class = 'foto-legenda'>
    <img src = '_imagens/glass-quadro-homem-mulher.jpg'>
    <figcaption>
        <h3>Google Glass</h3>
        <p>Uma nova maneira de ver o mundo.</p>
    </figcaption>
</figure>

In the CSS:

figure.foto-legenda {
    border: 8px solid white;
    box-shadow: 1px 1px 4px black;
}

The teacher also instructed to include the following section in order to prevent the margin from "misaligning" the image by resizing the browser window:

figure.foto-legenda img {
    width: 100%;
    height: 100%;
}

In doing so, apparently the edge fits right, but the image becomes gigantic...

Q. S.: I already tried to remove the caption text, but the result was the same.

  • Important you [Dit] your question and explain objectively and punctually the difficulty found, accompanied by a [mcve] of the problem and attempt to solve. To better enjoy the site, understand and avoid closures and negativities worth reading the Stack Overflow Survival Guide in English.

1 answer

2


If I understand the question correctly, what was missing there was you declare a maximum size for the conteiner, that is, the place that the other elements will fit, which in this case is the tag figure. In the case of my example, the image I placed has the width (width) of 536px:

figure.foto-legenda {
  max-width: 536px;         /* seta o tamanho fixo */
  border: 8px solid white;
  box-shadow: 1px 1px 4px black;
}

figure.foto-legenda img {
  width: 100%;
  height: 100%;
}
<figure class="foto-legenda">
  <img src="https://i.picsum.photos/id/257/536/354.jpg?hmac=nm-DRQwYb7mx97h32hITnpzDptvXok_UJCT3CY-LxJY">
  <figcaption>
    <h3>Google Glass</h3>
    <p>Uma nova maneira de ver o mundo.</p>
  </figcaption>
</figure>

  • Your solution worked, thank you very much; I’m just curious why the professor didn’t have to do it... Could it be because the class is from 2013 and since then has changed the functioning of these properties or something?

  • 1

    Bernardo, I can not say exactly because I would have to see the code, but, has a great possibility of this being the reason. If I am not mistaken the HTML5 was only released in 2014 officially, I think, so probably even the HTML of the course there is a lower version than the current browsers. So, perhaps, many of the things that the teacher shows how to do differs from the current way. The tip is always try to do more current courses possible, because technologies change very fast and evolve a lot from one version to another!

Browser other questions tagged

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