This works fine in the DIV, but the IMG does not work because it overlaps the area in which the internal borders apply. Fortunately, there is a very simple way: to contain the IMG inside the DIV.
<div><img src="pic.jpg" alt="1" height="200" width="200" /></div>
And apply the styles:
img {border: 2px solid red;} div {border: 3px solid black; width:204px; height:204px;}
Until you need to explicitly set the height / width of img in your HTML, you still need to know what it is, because the height / width of the DIV is calculated like this: div h = img h + img borderx2; div w = img w + img borderx2
Moses source share