tags:

views:

343

answers:

3

I have an unordered list and the background image is being cut off when trying to place it next to the text.

I'm using jquery to add the class to the anchor tag to display the image, and its working fine, the only problem is the image gets cut off. I've been playing around with the css, but can't seem to figure out how to make the image display properly...it seems like the < li > is hiding the image behind it somehow...can I place the image in front of the < li > to make it display...or am I missing something else?

Can someone help me? Thanks.

Here's the HTML:

<ul id="nav>
    <li>
       <a class="folder_closed">Item 1</a>
       <div style="display:none">Content for item 1</div>
    </li>
</ul>

Here's the CSS:

ul#nav{
    margin-left:0;
    margin-right:0;
    padding-left:0px;
    text-indent:15px;
}

#nav > li{
    vertical-align: top;
    text-align:left;
    clear: both;
    margin-left:0px;
    margin-right:0px;
    padding-right:0px;
    padding-left:15px;
}

.folder_open{
    position:relative;
    background-image: url(../images/maximize.png);
    background-repeat: no-repeat;
    background-position: -5px 1px;
}
.folder_closed{
    position:relative;
    background-image: url(../images/minimize.png);
    background-repeat: no-repeat;
    background-position: -5px 1px; 
}
A: 

You need to add display:block and some dimensions (and perhaps some padding to make it look nice) to your A tag to ensure the element will be big enough to contain your background image.

You're better off transferring all of the styling to your A tag. Don't bother styling the LI tags at all (unless you need floats).

.folder_open{
    vertical-align: top; <--- use padding to accomplish this instead
    text-align:left; <-- this too
    clear: both;
    margin-left:0px;
    margin-right:0px;
    padding-right:0px;
    padding-left:15px;
    position:relative;  <--- not needed.
    background-image: url(../images/maximize.png);
    background-repeat: no-repeat;
    background-position: -5px 1px;
    display:block;
    height: ??px;
    width: ??px
}
Diodeus
Diodeus, this is great. Thanks, it displays the icon's as I wanted. I appreciate your help. One weird thing though. This is an expandable menu, (I updated the original post) to show a <div> that is directly below the <a> tag where I hide/display content. Now when I click on the <a> tag it shows the hidden div, except the folder icon for any items down the tree don't get pushed down, but the text for that item does? see the image: http://www.redsandstech.com/ff_broken.jpg . Any ideas?
Ronedog
If I remove the display block, then the icon gets pushed down correctly...but of course the original problem of the icon getting cut off comes back.
Ronedog
If "FACT" supposed to be next to the folder?
Diodeus
no, the folder is supposed to be next to "FACT"...in other words, "FACT" is being pushed down to where I want it to go, but the folder is remaining up at the top...further debugging helped me find out that the folder is the top most part of the <li> and FACT is at the bottom most part of the <li>...by shading the <li> I figured this out...but why is it doing this? I thought block elements just get pushed down...this is only doing this in FF3, ie7 its working in???
Ronedog
If you put the background on the A tag (with the appropriate left padding), it should always be one the same line as the text, because they're the SAME element. I'm not sure what you're doing wrong here.
Diodeus
I'm not sure the problem either...is it possible there is a problem if this ul list is contained inside a <td> tag of a table?
Ronedog
A: 

It looks like it might be your background position... if I understand it properly, the maximize image is disappearing, correct?

Also, one good practice, when specifying background images, I have found, is to explicitly set the background color to transparent.

.folder_closed {
  background: transparent url(../images/maximize.png) no-repeat scroll -5px 1px;
}
Atømix
A: 

This sounds like a line-height issue---just for experimentation try setting the LI "line-height: 40px;" and see if your image shows completely...

One of the things I do in this case is I use some absolute positioning. First to set it up you have to have your UL and LIs relatively-positioned:

<style type="text/css">
  ul, li {
    position: relative;
  }
</style>
<ul>
  <li> ... </li>
  <li> ... </li>
  <li> ... </li>
</ul>

Then add some padding to the left side of the LI:

<style type="text/css">
  li {
    padding-left: 30px;
  }
</style>

In this case you're using an <A> anchor w/ some class styling. Break up the <A> into two As:

<li>
  <a class="folder_icon folder_closed"></a>
  <a class="folder_title">... your title ...</a>
  ... your other content ...
</li>

And then turn one of the As into blocked display:

<style type="text/css">
  li .folder_icon {
    position: absolute;
    left: 0px;
    top: 0px;
    display: block;
    width: 16px;
    height: 16px;
  }

  li .folder_closed {
    background-image: url("../images/minimize.png");
    background-repeat: no-repeat;
    background-position: -5px 1px; 
  }
</style>

How is that?

Amy
Great! If I was rich I'd give you a million dollars! My initial tests show the icon's working the way I needed and the div's are pushing down as I need...there are a few more tests I need to run, but I've got to leave out of town right now...I'll run them tomorrow and report! Thank you!
Ronedog
Well, after further testing I ended up with the same problem. I just noticed that this <ul> tree is contained inside a <table><tr><td>....Is it possible that being contained inside the table is causing this weird stuff? It just doesn't make sense they way things are acting?
Ronedog
Hm, that is weird. Are you using a Strict doctype? Or Transitional? In my experience that makes all the world of difference.One other thing you'll probably have to do with the icons is ensure that all containing elements need to be relatively positioned. That goes for the TD, TR, and TABLE too. I usually pop open Firebug and start editing the styles in realtime and try to get things to lay out properly with that.p.s. Sorry I didn't read this until now. I don't log onto S.O. every day. :)
Amy