Welcome to WebmasterWorld Guest from 54.167.29.254

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

5+ Year Member

joined:Oct 19, 2006
posts:21
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>
</div>

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:

#searchdiv{
height:30px;
width:805px;
display:inline;
background-image:url(images/greystripe.gif);
background-position:top left;
background-repeat:no-repeat;
margin-bottom:5px;
padding:0;
}

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
posts:4988
votes: 12


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

5+ Year Member

joined:Oct 19, 2006
posts:21
votes: 0


Fotiman:

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