Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Positon: Relative hides <li> bullet point! (?)

Status
Not open for further replies.

Monkey36

MIS
May 23, 2005
60
GB
I'm having real CSS woes today! Hopefully someone can sort me out with this one as well..

Below is a stripped down version of what I'm trying to do; a page with a sidebar of information, with "float: left" so that the rest of the page flows around it. But I'm coming up against a problem in IE with <li> items.

If I put in a list then the bullet points get lost behind the sidebar. If I change the list-style-position to inside then the bullet point is visible again, but if the list item doesn't fit on one line then it gets wrapped underneath the bullet point. Ugly.

I can't use padding or margins because of the float (I tried it and it doesn't work correctly in IE or Firefox due to the way the item bounding box is calculated).

So I thought I'd use relative positioning and shift the list item over a little bit (and give it a right margin so it doesn't get pushed off the side of the screen).

This works perfectly in FireFox. In Internet Explorer the text looks fine but the bullet point symbol has disappeared! I'm going a bit mental on this one, if someone could either solve this problem or suggest another route to take to get the desired effect it would be very much appreciated!

Code:
<html>

<head>
<style type="text/css">
 #sidebar {
   background-color: gray;
   width: 200;
   height: 400;
   float: left;
   margin-right: 32px;
 }

 #content ul {
 }

 #content ul li {
   position: relative;
   left: 1em;
   margin-right: 1em;
 }
</style>
</head>

<body>
  <div id="sidebar">Sidebar</div>
  <div id="content">
    <ul>
      <li>Item1</li>
      <li>Item2</li>
    </ul>
  </div>
</body>

</html>
Cheers,
Dan.
 
I tried your code in IE and Opera. In IE, I get the behavior you describe. In Opera, I still see the bullets.

I imagine the differences between the two browsers comes to a debate over the definition of "relative." That is: relative to WHAT? In other words, in an LI element, what is the 0,0 point? Is it the bottom top-left "corner" of the bullet or the top-left corner of the first word in the text? My guess is that IE says "text" and Opera says "bullet".

Nicely-formatted question, by the way. I appreciate being handed a small-but-complete example to test for myself!

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
I would also suggest adding a doctype. That will help with differences in the box model.
 
Hmm.. well first off, thanks for the suggestions! I've tried using a doctype that forces standards-compliance, but that didn't help.

To LFI: I see what you're saying, but I've come up with a refined test that I think says different. "Position: Relative" does seem to affect the whole item (bullet and text), not just the text itself, as can be seen in the sidebar.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>

<head>
<style type="text/css">
 #sidebar {
   background-color: gray;
   float: left;
 }

 li {
   position: relative;
   left: 1em;
   margin-right: 1em;
 }
</style>
</head>

<body>
  <div id="sidebar">
    <ul>
      <li>Item1</li>
      <li>Item2</li>
    </ul>
  </div>
  <div id="content">
    <ul>
      <li>Item1</li>
      <li>Item2</li>
    </ul>
  </div>
</body>
</html>

To BillyRay: The problem does happen identically in both browsers with those lines removed, and this was the situation I was facing. I was hoping to find a solution to the problem that would work cross-browser, but I'm just not doing too well so far :(
 
To BillyRay: The problem does happen identically in both browsers with those lines removed

Not for me it didn't - and I have no DOCTYPE. Try this for size:

Code:
<html>
<head>
	<style type="text/css">
		#sidebar {
			background-color: gray;
			width: 200;
			height: 400;
			float: left;
			margin-right: 32px;
		}

		#content ul li {
			xposition: relative;
			xleft: 1em;
			margin-right: 1em;
		}
	</style>
</head>

<body>
	<div id="sidebar">Sidebar</div>
	<div id="content">
		<ul>
			<li>Item1 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
			<li>Item2 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
		</ul>
	</div>
</body>
</html>

I see bullets just fine in both IE and Fx.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Ok, I think we're getting there. But just to push my luck and nitpick a bit, I'm still having a problem with the alignment of the bullet points.

In a normal page, if you've got text in <p> tags and then an unordered list, the bullet points of the list are projected inward (to the right) of the paragraph. In this case, once we get past the sidebar, this behaviour is as expected. But where there is content alongside the sidebar, the bullet points appear shifted along to the left, so that they appear outside of the observed text body.

Not sure I'm explaining very well, but hopefully this example will show it. Happens in both FireFox and IE, btw.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]

<html>
<head>
    <style type="text/css">
        #sidebar {
            background-color: gray;
            float: left;
            margin-right: 32px;
            padding: 32px;
            padding-bottom: 100px;
        }
    </style>
</head>

<body>
    <div id="sidebar">Sidebar</div>
    <div id="content">
        <p>
          lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet...
        </p>
        <ul>
            <li>Item1 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
            <li>Item2 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
            <li>Item2 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
            <li>Item2 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
            <li>Item2 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
            <li>Item2 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
            <li>Item2 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
            <li>Item2 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
            <li>Item2 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
            <li>Item2 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... </li>
        </ul>
        <p>
          lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet...
        </p>
    </div>
</body>
</html>
NB: Sorry the example is quite long, but I needed to get enough "content" in to ensure that it passed below the sidebar. (Not sure if you have to watch out for line-wrapping if you copy and paste).

Thanks again everyone!
 
How about just moving the bullets over a bit with a margin:
Code:
	li {
	    margin-left: 12px;
	}
or would you prefer that the items under the side bar didn't have this behaviour?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm: Unfortunately, this doesn't work in IE, only in Firefox. And, I would prefer that the items under the side bar maintain their original behaviour, and only fix the item alongside the side bar.

BillyRay: Your solution does fix the problem in Firefox, which is a step in the right direction, but because I'm expecting most people using the site to be on IE, I'd really like to get a solution for that as well.

Anyone got another idea to move this along at all?

Thanks again,
Dan.
 
Actually, how about setting the list style position? e.g.
Code:
	li {
            list-style-position: inside;
	}
It will mean that the text on the next line wraps underneath the bullet though.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Although, it shows you here how to get around that problem.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I've just read through that article, and unless I've misunderstood, I don't think the answer is in there. If I use "list-style-position: inside;", then I need to then use "text-indent: -1em" to get the top line pushed back a bit, but then it looks identical to how it did before (effectively we've recreated "list-style-position: outside;").

This could work if there was an explicit way to indent all lines except the first one (kinda the opposite to text-indent), but I can't see how to do so if there is one.

Thanks for the suggestions, though, keep them coming!

Cheers,
Dan.
 
Here are two radical suggestions:

1. Realise that you might never get it working perfectly in all browsers, so run with something that works acceptably.

2. Realise that the float is causing problems, so remove it, and work out the layout some other way.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Ok! I think I've come up with a solution. It's a bit rough around the edges, though.

The method I wanted to use works fine with Firefox. However, I just could not get the bullet points to display correctly/in the right place in Internet Explorer.

To get around this I used a slightly dodgy approach, and turned off the symbols and used an image. This image does not scale properly so if the user adjusts font size then it starts to look less good - like when the user holds down [CTRL] and use the mouse wheel. However, in IE (at least version 6) there is a cap on how small or large the fonts will go using this method so it's not too bad. Similarly, this bullet point will only really look good with normal sized texts (ie. not big headings).

However, this is all IE-specific, as style attributes set that are preceded by an underscore are interpreted by IE, but not by other browsers.

Also note that this doesn't seem to work properly if you use declare a doctype to be wholly standards-compliant (but since I've got this working as is, I've currently lost the will to care about such things! :)

Code:
<html>
<head>
<style type="text/css">

 #sidebar {
   float: left;
   padding: 12px;
   margin-right: 32px;
   margin-bottom: 8px;
   font-size: 75%;
 }
 #sidebar div {
   padding-bottom: 8px;
   border-bottom: 1px dotted black;
 }
 #sidebar div p {
   font-weight: 700;
 }

 #content ul {
   _list-style-type: none;
 }
 #content ul li {
   _background: url('images/bullet.jpg') no-repeat 50% left;
   _width: 100%;
   position: relative;
   left: 2em;
   _padding-left: 1em;
   margin-bottom: 1em;
   margin-right: 2em;
 }

</style>
</head>

<body>
  <div id="sidebar">
    <div>
      <p>Customer Logon:</p>
      <form>
        <label for="username">Username:</label><br>
        <input type="text" id="username"><br>
        <label for="password">Password:</label><br>
        <input type="text" id="password"><br>
        <input type="submit" value="Log in">
      </form>
      <a href="new.html">Click here</a> to register<br>for a customer login
    </div>
  </div>

    <div id="content">
      <p>
        Item1 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet...
      </p>
      <ul>
        <li>Item1 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet...</li>
        <li>Item1 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet...</li>
        <li>Item1 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet...</li>
        <li>Item1 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet...</li>
        <li>Item1 lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet...</li>
      </ul>
      <p>
        lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet... lorum ipsum dolor sit amet...
      </p>
    </div>
</body>
</html>

Anyway, thanks again for all your help and suggestions!

PS: I've just tried it in Opera and it doesn't actually fix the problem, the bullet points are still not where they should be when alongside a float-ed item. However, it degrades nicely enough as none of the code above really damages it, it just doesn't make the problem go away.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top