views:

25

answers:

2

I have <a> elements in two different contexts on my page, some are in divs (call them .container > a) and some are in child divs (like .container > .section > a) and even some that are in further descendant divs (like .container > ... > .section > a). I am currently doing some formatting on the inline <a> elements with the following CSS:

line-height:1.4;
position: relative;
left: 15px;
margin-left: -5px;

Since I am currently styling the links with a border-bottom: 1px dotted #333, it is necessary that the links remain inline elements. The problem is that sometimes links in .section behave differently from the ones in just .container. The latter look fine in both FF 3.6 and IE7. The former have the first character or so (whatever lies inside the amount of the negative margin) cut off in IE7 (I'm assuming by the negative margin).

I think that it might be a bug with hasLayout, so I checked the status of the three cases. They are as follows:

Case 1) For .container > a, .container hasLayout is true. (http://imgur.com/WJ3zM.png)
Case 2) For .container > .section > a, .section hasLayout is false and .container hasLayout is true. (http://imgur.com/4NHxj.png)
Case 3) For .container > ... > .section > a, .section hasLayout is false, all but one of the intervening containers (divs, li, and ul) hasLayout is true, and .container hasLayout is true. (http://imgur.com/WefBk.png)

The first two cases look fine in IE7, and the third case has the negative margin bug. What could be causing this to happen, and in such a limited context?

A: 

Set a z-index explicitly to override siblings or you may need to set a position on the parent element of that relative positioned element. IE incorrectly applies z-index of 0 to all elements. It could also be overflow:hidden.

Images aren't as great as live examples.

meder
I'm not sure what you mean about the z-index, could you clarify?I tried setting <code>position: relative</code> on the .section div to no effect. I also tried giving .section <code>overflow: visible</code>, and that did nothing either.I'm sorry that images aren't ideal, I'll see what I can do as far as a live example, but in this case it is fairly complicated. The "> ... >" in Case 3 is actually 2 divs, then a ul and its child li, and then another div.
burningstar4
`z-index:5;`.. can you make a demo?
meder
A pretty complete demo is here: http://www.webdevout.net/test?03V
burningstar4
A: 

It could be the hasLayout. Did you try adding layout in case 3 to .container? (Sorry, you said it already had layout, I meant one of the .section...)

Added based on my comment and experiment below:

Change your margin-left: -5px to text-indent: -5px on your a tags.

Scott
For Case 2, I gave the .section div layout (using zoom: 1 in the IE Developer Toolbar) and that actually made the bug appear in that case as well. When I gave .section layout in Case 3, it did not solve the problem.
burningstar4
Well, if nothing else, it confirms that `hasLayout` is your problem. Without code, it would be impossible for me to debug. I'm not sure why you are doing it the way you are, but why not just set `left: 10px` and eliminate the -5px of margin (if the negative margin is what is causing the bug)?
Scott
The margin, since it only affects the first line, is used to create the indenting of the link's second line, if it wraps. I'll work on getting some stripped-down code available to look at.
burningstar4
Not sure if it will help, but you might try using `text-indent: -5px` rather than `margin` to shift your first line of text.
Scott
You can see the code that's in error (works in Firefox, not in IE7) here: http://www.webdevout.net/test?03V
burningstar4
Well, my quick experiment seemed to show that the `text-indent` change I mentioned in the comment above worked.
Scott
Firefox appears not to do anything for text-indent, maybe because the `<a>` is not a block element? I could always use some conditional comment or something to make both work, though, thanks!
burningstar4