Help - Search - Members - Calendar
Full Version: Why does the class work inside the img tag but not inside div?
HTMLHelp Forums > Web Authoring > Markup (HTML, XHTML, XML)
hhaarr
Hello everyone

why does it work here

CODE
<divs>
      <img src="pix.jpeg" alt="Eastern Port" class="A5">
</div>

but not here

CODE
<divs class="A5" >
      <img src="pix.jpeg" alt="Eastern Port">
</div>


this is as far as it goes for the class in CSS
CODE
.A5 {
        width: 50%;
}


Thanks for any help
CharlesEF
Maybe because there is no < divs >, it should be < div>
hhaarr
QUOTE(CharlesEF @ Feb 2 2021, 05:36 PM) *

Maybe because there is no < divs >, it should be < div>

just a typo, same thing with Div
pandy
No reason why it shouldn't work. Do you expect it to change the width of the image? It won't. It will change the width of the DIV. You can see that it does if you make the DIV visible by putting a border or background color on it.

If you want the image to fill the DIV, not matter what width the DIV is, you need to set the width of the image to 100%.
Christian J
Also, image files have an intrinsic width (which is used if no width is specified for the IMG element), and if that width is wider than the container element, the image will spill out. By adding a border or background to the DIV you can check this.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.