Link to home
Start Free TrialLog in
Avatar of Refael
RefaelFlag for United States of America

asked on

unordered list background image


something very simple i am trying to achieve but it looks harder than i thought.....

in an unordered list (with a link inside it) i am trying to aligned the background image (which is an arrow) to the right with a little bit of left padding so it will not be so close to the link.
the link can be at any length so i am not able to fix the width of the <li> nor the <a>.
the background image or goes way to the right or when using left position and paddings the arrow background image get cut due to the font size.

attached a screenshot of what i am trying to archive. again the link text can be at any length.

 User generated image
Thanks!!!
Avatar of bill30
bill30
Flag of United States of America image

a few solutions:

after the text type &nbsp;
&nbsp; is the http command for a space and it could give you the space you want, you can use it several times &nbsp;&nbsp;
ex: <ul>
<li><a href="#">THIS IS THE LINK TEXT</a>&nbsp;&nbsp;</li>
</ul>

or photoshop the image and add extra white pixels to the left of it until you have the spacing you need
Here is an image to use:
link.png
And here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Demo</title>
<style type="text/css">
html,body {
background:#fff;
}

ul {
list-style: none;
margin: 0;
padding: 0;
}

li {
background: transparent url(http://filedb.experts-exchange.com/incoming/2011/04_w15/440692/link.png) no-repeat scroll 100% 100%;
height: 34px;
line-height: 34px;
padding: 2px 1px 0 1px;
margin: 0;
width: 200px;
}

li a, li a:link, li a:visited {
font-family: "arial narrow", "helvetica narrow", arial, helvetica, "san serif";
font-size: 18px;
font-weight: 600;
color: #2C3F5F;
height: 34px;
line-height: 34px;
text-decoration: none;
display: block;
}

li a:hover {
color: red;
}

</style>
</head>
<body>

<h1>Hello World</h1>

<div>
 <ul>
  <li><a href="#">Link 1</a></li>
  <li><a href="#">Link 2</a></li>
  <li><a href="#">Link 3</a></li>
  <li><a href="#">Another Link Example</a></li>
 </ul>
</div>

</body>
</html>

Open in new window

Avatar of Refael

ASKER


hankknight, thanks for the example
the problem is you set the width to 200px. Some links text are shorter and some are longer.
ASKER CERTIFIED SOLUTION
Avatar of hankknight
hankknight
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Refael

ASKER


so after spending hours, here is the solution. compatible in IE 7 and 8 as well:
ul {
	margin:0;
	padding:0;
	margin-top:10px;
	list-style:none;
}
li {
	padding:0;
	height:29px;
	line-height:28px;
	font-family:Helvetica, Arial, sans-serif;		
}
li span {
	display:inline-block;
	width:21px;
	float:left;
	background: transparent url(../layout/more_arrow.png) no-repeat scroll 100% 100%;
	height:25px;
	line-height:32px;
	padding: 0px 10px 0px 0px;
}
li a {
	float:left;
	font-size:12px;
        font-weight: 600;
        color: #2C3F5F;
	height: 20px;
        line-height: 28px;
	text-decoration:none;
        border-bottom:2px #900 solid;
	letter-spacing:1px;
        text-transform:uppercase;
}



<li><a href="#">THE LINK TEXT</a><span></span></li>

Open in new window