Forum Moderators: not2easy

Message Too Old, No Replies

CSS list background image

         

ollyno1uk

12:59 pm on Oct 13, 2008 (gmt 0)

10+ Year Member



Hi

I am new here!

I have a CSS menu that I am working with and I am trying to get an image as a background the the links. I have got the background showing but it is the wrong size. It would appear that the size of the link is dependant on font size.

I have tried adding the line-height: 30px; and height: 30 px; but doesn't seem to make a difference.

#menu a{
font: bold 12px arial;
color: #999999;
display: block;
background: url(../images/category_bg.jpg) no-repeat bottom left;
text-decoration: none;
line-height: 30px;
height: 30px;
}

D_Blackwell

3:28 am on Oct 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It would appear that the size of the link is dependant [sic] on font size.

The 'size' of the link is dependent upon the size of the container and you've got several declarations that affect the container in this case.

By default, it would simply be the 'size' of the space it takes up as an inline element. The font-size: would be a key factor. However, {display: block;} adds full width:, which has been controlled by the seemingly cumbersome addition of no-repeat and possibly unneeded positioning. Also, the additional attempt to control the 'size' with line-height: and height: - These affect the display differently. You might want one or the other, or both, or neither - depends.

Defining the 'right size' as compared to the "wrong size" problem would seem essential before I could suggest a solution. It seems the central issue and needs clarification.

Setting a background-image: is simple enough. Does it need to be on the <a> or would setting it on the <li> be preferable, or does it matter?

ollyno1uk

8:13 am on Oct 14, 2008 (gmt 0)

10+ Year Member



thanks for the response.

the height and line-height elements do not need to be present if the background image at its full size, takes up the full space - this is 230 x 30 px.

As far as I see, whether the background displays on the <li> or the <a> is irrelevant as they are one in the same as far as the results go.

Potentially also the positioning is not needed but I added it trying to achieve the results I need - can be removed no problem.

Quite simply, I have a list of urls that I am trying to fit centrally into their own individual 230 x 30px.

Thanks a lot for your input

D_Blackwell

3:31 pm on Oct 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This meets the criteria as I understand them. You will have to rework to me the your specific need. It is one option. You may get others.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<style>
/*#menu a{
font: bold 12px arial;
color: #999999;
display: block;
background: url(../images/category_bg.jpg) no-repeat bottom left;
text-decoration: none;
line-height: 30px;
height: 30px;
} */
#menu {

}
#menu li {
list-style-type: none;
background: #fff url(aaa.jpg);
width: 230px;
text-align: center;
}
#menu a {
font: bold 12px arial;
color: #999;
display: block;
text-decoration: none;
line-height: 30px;
/*width: 100%; if supporting IE6 */
}
</style>
</head>
<body>
<div id="menu">
<ul>
<li>
<a href="www.example.com">
LINK
</a>
</li>
<li>
<a href="www.example.com">
LINK
</a>
</li>
</ul>
</div>
<!--
I have a CSS menu that I am working with and I am trying to get an image as a background the the links. I have got the background showing but it is the wrong size. It would appear that the size of the link is dependant on font size.

I have tried adding the line-height: 30px; and height: 30 px; but doesn't seem to make a difference
. . . . . . . . . . . . . . . . . .
the height and line-height elements do not need to be present if the background image at its full size, takes up the full space - this is 230 x 30 px.

As far as I see, whether the background displays on the <li> or the <a> is irrelevant as they are one in the same as far as the results go.

Potentially also the positioning is not needed but I added it trying to achieve the results I need - can be removed no problem.

Quite simply, I have a list of urls that I am trying to fit centrally into their own individual 230 x 30px.
-->
</body>
</html>

ollyno1uk

2:47 pm on Oct 15, 2008 (gmt 0)

10+ Year Member



I have't tried your solution but one requirements is that the image is only there on the <a> as I want a hover effect - ( a change to a simplw white background) when the link is hovered over.

Thanks a lot