-2

So, when ive been looking at the code that goes along with a HTML website i noticed at the top where the Facebook, Twitter & Google logos are i searched for the HTML code where i found a link. However can someone explain why there is no <img src="...."> with the image and only <a href=".....">. This may be a novice question but its bugging me. Thanks for any help.

Edward Falk
  • 9,991
  • 11
  • 77
  • 112
  • 2
    Can you please provide a clearer example, it's extremely fuzzy what's you're trying to describe here. Just going to guess you're stumbling across CSS background image replacements. – deceze Jun 03 '13 at 16:04
  • This could be true of any version of HTML, not just version 5. – Rob Jun 03 '13 at 16:05

2 Answers2

2

That <a> is probably styled with CSS to have a background image:

background-image: url('path/to/background/image.jpg');
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
0

It's somewhat common to just set the background-image CSS property on e.g. a link, instead of including a full image tag, in instances like a logo.

Without seeing the example code, one good reason for this might be because they have styled the tag to look nice when putting images inside the body of the page, but they don't want to apply those styles to their logo (it shouldn't have, probably, padding, margins, etc.). Using background-image is a way to avoid inheriting styles, without just overriding them explicitly.

For a more detailed discussion of when one is used instead of the other, you might try reading some of the answers in this other SO question: When to use IMG vs. CSS background-image?

Community
  • 1
  • 1
CmdrMoozy
  • 3,870
  • 3
  • 19
  • 31