Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

Background-image for div with forma and images

7:39 pm on Jan 16, 2007 (gmt 0)

New User

10+ Year Member

joined:Oct 19, 2006
votes: 0

I'm coding a page with a search bar, behind which is a simple background image. The search form includes: 1. A small icon image (which actually isn't part of the form, but should appear to be so) 2. A text input for the search terms, and 3. An image input button to activate the search. The code looks something like this:

<div id="searchdiv"><img id="glass" src="images/nv-search.gif" width="24" height="23" /><form><input type="text" size="40" /> <input type="image" src="images/search-button.gif" /></form>

The tallest image (the search button) is 30px tall, which is exactly how tall I need the background-image to be. I've styled the div thus:

background-position:top left;

In FF, the background-image is somehow vertically-aligned to the center, and is only about half as tall as it should be. In IE6 and IE7, the background renders fine except that it is still missing about 2px at the top. I've been messing around with this for onger than I should have in the last couple of days, and haven't really been able to figure out what the deal is, so I figure I'm messing something up here that my meager experience with CSS has yet to teach me.

9:32 pm on Jan 16, 2007 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
votes: 14

1. Width does not apply to inline elements. You'll need to make #searchdiv a block element.

2. The extra space you're seeing is probably caused by line-height. Try tweaking that value (maybe try line-height: 100%;)

3. Make sure you're using a valid DOCTYPE so you're not in Quirks mode (beat you to it cmarshall). :)

[edited by: Fotiman at 9:33 pm (utc) on Jan. 16, 2007]

11:17 pm on Jan 16, 2007 (gmt 0)

New User

10+ Year Member

joined:Oct 19, 2006
votes: 0


Setting display to "block" was the magic elixir. Thanks a bunch.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members