vayumahesh — 2012-10-19T16:11:38-04:00 — #1
I have the following code through which I have images to the left and right of a link.
<li><a href='default.aspx' class="bulletLevel1">Home Page</a> <img src="images/new.gif" /></li>
I am using CSS class as follows for the left-side image. However, I am using img tag for the right side image. I am looking to come up with a CSS class for the right-side image also instead of using the img tag. Can someone help please. Thanks.
background-position: left 50%;
ralphm — 2012-10-19T17:25:52-04:00 — #2
Yes, background images are the way to go. What I would suggest is that you firstly set the <a> to display: block;. Then add some right padding to it (enough to fit the image) and place the image as a background on the <a>, setting it to
background: url(images/menu-item-default.gif) no-repeat 100% 50%;
Then, put left padding on the <li>, and put the left image on the <li> itself. The reason is that you can't have two background images on the one element in CSS2, though some browsers do support the new CSS3 option to have multiple backgrounds.
An alternative to putting the left image on the <li> is to put a span inside the <a> and place it on there instead. Make sure to set the <span> to display: block too.
vayumahesh — 2012-10-23T12:59:12-04:00 — #3
That did not work. I have the <li> tag inside a td. The image is appearing to the far right in the cell. How can I get the image to appear next to the <a> itself (say, 25px from where the link title ends)?
dresden_phoenix — 2012-10-23T16:23:08-04:00 — #4
Let get some concept straight.
Are your images part of the content,or are they purely decorative? If they aren't icons or each image is different and related directly to the specific text...they are a content and you are better off using the IMG tag for BOTH.
If your images are merely dividers, icons or any such other decoration then a BG image is best. Do note that BG images DO NOT alter (make space for themselves) the content flow so you need to make the space for them using padding or margin methods.
UNLESS you intend to support ONLY CSS3, you can only put ONE background image per element. So, for example you will put the left image in the LI and the right image in the anchor.
ROUGHLY, something like this:
background: url(images/menu-item-default.gif) no-repeat 0 50% ;
padding-left: 20px; /* i assumed the image to be 10px so I added 10px to your padding*/
background: url(images/menu-item-default2.gif) no-repeat 100% 50% ;
padding-right: 20px; /* i assumed the image to be 10px so I added 10px to your padding*/
hope that helps.
technobear — 2012-10-24T07:47:10-04:00 — #5
Do you mean that you have a list - <ol> or <ul> - inside your <td>, or just a single <li>? If the latter, then that is not valid (X)HTML.
It would help if you could provide a link, or at least the full HTML/CSS, so we can see what's going on.
vayumahesh — 2012-10-24T13:08:03-04:00 — #6
Thanks, that helped. I had a parent div with fixed width and so the image was aligning to the far right of the div. position:absolute on the <a> tag fixed the issue.