Aziz Al-ghannam
Aziz Al-ghannam

Reputation: 309

why is he putting one specific img tag inside div tag?

the code isn't some random messed up code, i found it in a book:

<div id="main">
<div><img src="images/img1.png" /></div>
<div><img src="images/img2.png" /></div>
<div><img src="images/img3.png" /></div>
<div><img src="images/img4.png" /></div>
</div>

so..why is he putting every img tag inside div tag? for styling maybe? he can use img tag to style them, or even main ID

Upvotes: 0

Views: 1322

Answers (2)

Sir Crispalot
Sir Crispalot

Reputation: 4844

Maybe because <div> is a block level element and <img> is not?

In any case, code found in books is often there merely as an illustration and sometimes does not represent best practice.

<img> is actually a replaced inline element. However my point about sample code in books still stands.

There are also many ways to skin a cat ...

Upvotes: 2

Chuck
Chuck

Reputation: 237010

Just from the look of it, I'd guess this is a logical <ul> that got afflicted by divitis. Books tend to have some degree of quality control on them, but they're still lousy with div-ridden WTFs just because that's how so many designers learned to do it. But it's hard to say for certain without either seeing the book or having convenient access to the author's brain.

Also, though, a lot of people forget that they can style normally unobtrusive inline elements in arbitrarily fancy ways, so they end up adding elements that they're more used to styling in those ways. I once simplified a really slick-looking, professionally-designed category header link with an odd shape and very specific spacing because it was causing odd problems when moved to a different area of the page. IIRC, their version used three divs, an img, an anchor and a span. Mine used an anchor and an img and was pixel-identical.

Upvotes: 1

Related Questions