Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > <img> or CSS background-image?

Reply
Thread Tools

<img> or CSS background-image?

 
 
JWL
Guest
Posts: n/a
 
      10-02-2006
Hi

Suppose I have a site that requires a horizontal line of four images on
each page. This is a design thing and doesn't really have much bearing
on the site's content. The images differ from page to page.

Anyway, using a CSS layout, I left-floated the four divs and placed
<img> tags in them to display the images. But now I'm thinking: would it
be better to place background images in the divs using CSS? By using
contextual selectors I could place exactly the same HTML on each page
and have the CSS select the different images, which would make things
much cleaner. Is there any reason not to do this? I'm not sure whether
to choose one or the other.

Related to that, suppose I do have a div that exists only to display a
background image:

#header {
width: 800px;
height: 100px;
background: url('banner.gif') no-repeat;
}

Is it OK to have an empty div in the HTML:

<div id="header"></div>

Or should I put a space in:

<div id="header"> </div>

Looking at people's source, I've seen both techniques, but I don't know
if it makes the blindest bit of difference to all the browsers I'm
unable to test in.

Thanks for looking!
 
Reply With Quote
 
 
 
 
Ben C
Guest
Posts: n/a
 
      10-02-2006
On 2006-10-02, JWL <> wrote:
> Hi
>
> Suppose I have a site that requires a horizontal line of four images on
> each page. This is a design thing and doesn't really have much bearing
> on the site's content. The images differ from page to page.
>
> Anyway, using a CSS layout, I left-floated the four divs and placed
><img> tags in them to display the images. But now I'm thinking: would it
> be better to place background images in the divs using CSS? By using
> contextual selectors I could place exactly the same HTML on each page
> and have the CSS select the different images, which would make things
> much cleaner. Is there any reason not to do this?


Not that I know of.

> I'm not sure whether to choose one or the other.


If using CSS makes what you're doing cleaner, use that.

> Related to that, suppose I do have a div that exists only to display a
> background image:
>
> #header {
> width: 800px;
> height: 100px;
> background: url('banner.gif') no-repeat;
> }
>
> Is it OK to have an empty div in the HTML:
>
><div id="header"></div>


Yes.

> Or should I put a space in:
>
><div id="header"> </div>


It makes no difference if the div is whitespace: collapse (which is the
default).

> Looking at people's source, I've seen both techniques, but I don't
> know if it makes the blindest bit of difference to all the browsers
> I'm unable to test in.


Shouldn't do.
 
Reply With Quote
 
 
 
 
Jukka K. Korpela
Guest
Posts: n/a
 
      10-02-2006
Scripsit JWL:

> Suppose I have a site that requires a horizontal line of four images
> on each page.


Suppose that you gave us the URL. Then we would know what this is really
about and could give a simple, direct answer.

> This is a design thing and doesn't really have much
> bearing on the site's content. The images differ from page to page.


But the site _requires_ the images? So it's presumably unusable by anyone
who uses a text browser, speech browser, Braille device, or otherwise
imageless browsing. Right? I guess not.

The key question is: is it genuine content, or just decoration? Or something
between? Exactly where there?

If content, use <img> with adequate alt attributes. If decoration, use
background image _or_ <img> with alt=""; the choice between these depends on
the circumstances but isn't generally a big issue.

> width: 800px;


Too much width. Broken by design. Remarkably many web sites force horizontal
scrolling just because some dee-ziner decided on wide banner image.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      10-02-2006

JWL wrote:

> Anyway, using a CSS layout, I left-floated the four divs and placed
> <img> tags in them to display the images. But now I'm thinking: would it
> be better to place background images in the divs using CSS?


The fact that you can place background images through CSS is no
indication that you ought to. The notion that you can apply CSS
rollovers to them isn't a good recommendation either.

CSS only supports "background" images, not foreground. The useful
behaviours that emerge from this (such as rollovers) don't change the
fact that it's primarily a background feature. It's definitely a
mistake to start treating this as a primary way of distributing real
content. Stick with <img>.

For one simple example, general default behaviour on printing is to not
print CSS background images. This is such a useful feature (because of
excess eye candy) that it's impractical to change this setting. So if
you want your images to be printable, then don't stick them through CSS
backgrounds.

 
Reply With Quote
 
Alan J. Flavell
Guest
Posts: n/a
 
      10-02-2006
On Mon, 2 Oct 2006, JWL wrote:

> #header {
> width: 800px;


You'll be fighting my user stylesheet which, at least for my regular
browsing, says max-width: 55em;

In CSS the user has the last word. Are you sure that the rest of your
design can live with that?

 
Reply With Quote
 
richard
Guest
Posts: n/a
 
      10-03-2006

"JWL" <> wrote in message
news:...
> Hi
>
> Suppose I have a site that requires a horizontal line of four images on
> each page. This is a design thing and doesn't really have much bearing on
> the site's content. The images differ from page to page.
>
> Anyway, using a CSS layout, I left-floated the four divs and placed <img>
> tags in them to display the images. But now I'm thinking: would it be
> better to place background images in the divs using CSS? By using
> contextual selectors I could place exactly the same HTML on each page and
> have the CSS select the different images, which would make things much
> cleaner. Is there any reason not to do this? I'm not sure whether to
> choose one or the other.
>
> Related to that, suppose I do have a div that exists only to display a
> background image:
>
> #header {
> width: 800px;
> height: 100px;
> background: url('banner.gif') no-repeat;
> }
>
> Is it OK to have an empty div in the HTML:
>
> <div id="header"></div>
>
> Or should I put a space in:
>
> <div id="header"> </div>
>
> Looking at people's source, I've seen both techniques, but I don't know if
> it makes the blindest bit of difference to all the browsers I'm unable to
> test in.
>
> Thanks for looking!


I kind of like the CSS version on account of the validator is happier that
way.
If you use <img> then you've got to add in all kinds of stuff just to
validate.
CSS is quicker and cleaner.

 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      10-03-2006

richard wrote:

> I kind of like the CSS version on account of the validator is happier that
> way. If you use <img> then you've got to add in all kinds of stuff just to
> validate.


What complete and utter rubbish.

You _are_ Richard Bullis, aren't you?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Layout question - how to duplicate a table layout with CSS Eric ASP .Net 4 12-24-2004 04:54 PM
confused - html validates, css validates but validate css from the html causes errors Titus A Ducksass - AKA broken-record HTML 6 11-15-2004 12:59 PM
Set CSS property equal to another CSS property? Noozer HTML 10 10-13-2004 09:20 PM
Is there a way to set the a CSS property to be explicitly the same as another CSS property? Joshua Beall HTML 1 12-10-2003 07:21 PM
print.css and screen.css tom watson HTML 1 09-09-2003 02:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57