Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Div spans display issues in IE

  1. #1
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default Div spans display issues in IE

    Hi all,

    I am having some problems with one of my page which involves some span elements inside a div element. Since it is an internal project unable to provide a link, plz find the source, in which I've simulated the issue:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<title>Untitled Document</title>
            <style type="text/css">
            .value {
            		padding:0px 0px 0px 24px; 
    			color:#0080FF; 
    			font-weight:bold; 
    			cursor:pointer; 
    			background: transparent url(images_sprites.gif) no-repeat scroll 4px -447px;
    		}
            .c{
            		width:100%;
    			border:1px solid red;				
    		}
    		#main { 
    			background-color:#FFFFDA; 
    			border-top:1px solid #BBD0F0; 
    			line-height:20px; 
    			width: 100px; 
    			position: static;
    		}
    		</style>
    		<script type="text/javascript">
    		
    		</script>
    	</head>
    	<body>
    		<div id="main">
    			<div class="c">
    				<span class="value">hello</span>
    				<span class="value">se cond</span>				
    			</div>
    		</div>		
    	</body>
    </html>
    Plz find the image used in the above source as attachment, which is important to identify the problem.

    After saving the source and image together in the same location view the page in Firefox and in IE, you can identify the problem quickly. I would like to avoid such problems in IE and want to make it exactly like Firefox if that is possible otherwise I would like to make a uniform method applicable to both items.

    Any help appreciated.

    Thanks in advance.

  2. #2
    Join Date
    Dec 2004
    Posts
    177
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default

    ...Well, is the space in the word second intended? Is the containing div intended to be too small? Really, I'm not sure what's important regarding your site, because all I'm looking at is two words.
    Verzeihung!

  3. #3
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    @thetestingsite...

    That's quite easy to fix. Your use of the CSS shorthand in your background tag is a bit verbose. You can't fit all background CSS properties into the shorthand tag.

    The shorthand style follows the following convention:
    Code:
    background: #fff url(image.gif) no-repeat top left
    ...instead of
    Code:
    background-color: #fff;
    background-image: url(image.gif);
    background-repeat: no-repeat;
    background-position: top left;
    So, in your code change:
    Code:
    background: transparent url(images_sprites.gif) no-repeat scroll 4px -447px;
    to
    Code:
    background: transparent url(images_sprites.gif) no-repeat 4px -447px;
    Basically, remove "scroll"

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by Minos View Post
    ...Well, is the space in the word second intended? Is the containing div intended to be too small? Really, I'm not sure what's important regarding your site, because all I'm looking at is two words.
    First of all if you check the display in Firefox and IE you can clearly identify that the view is not similar. I have a div element in which I am inserting span elements. When I insert a span element which goes to the next line due to the width restriction of div element in Firefox it correctly shows the background image I've set for the span element. But in IE7 and IE6 it gives me a distorted display (not showing the X mark in the desired position but showing a wrong image in another position). I would like to make the display of IE like Firefox, if that is possible.

    Regarding the code I've posted here, I've clearly mentioned that the code is a simulated one of my problem. I am sure that the demo code does shows the problem clearly.



    Quote Originally Posted by Medyman View Post
    @thetestingsite...

    That's quite easy to fix. Your use of the CSS shorthand in your background tag is a bit verbose. You can't fit all background CSS properties into the shorthand tag.

    The shorthand style follows the following convention:
    Code:
    background: #fff url(image.gif) no-repeat top left
    ...instead of
    Code:
    background-color: #fff;
    background-image: url(image.gif);
    background-repeat: no-repeat;
    background-position: top left;
    So, in your code change:
    Code:
    background: transparent url(images_sprites.gif) no-repeat scroll 4px -447px;
    to
    Code:
    background: transparent url(images_sprites.gif) no-repeat 4px -447px;
    Basically, remove "scroll"
    I think there is some issues with the way you've mentioned the order of background CSS shorthand properties. That should be in the following order I think

    Code:
    background-color
    background-image
    background-repeat 
    background-attachment 
    background-position
    The "scroll" is the value for the highlighted portion in the above. It can have either "scroll" or "fixed".

    Anyway removing that will not solve the issue if you try that in the demo page I've provided.

    I am still open for a solution.

    Thanks in advance.

  5. #5
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    See if this ammendment helps:
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    		<title>Untitled Document</title>
            <style type="text/css">
    			#main { 
    			background-color:#FFFFDA; 
    			border-top:1px solid #BBD0F0; 
    			line-height:20px; 
    			width: 150px; 
    		}
            .value {
            	padding:0px 0px 0px 24px; 
    			color:#0080FF; 
    			font-weight:bold; 
    			cursor:pointer; 
    			background: transparent url(images_sprites.gif) no-repeat scroll 4px -447px;
    		}
            .c{
    			border:1px solid red;				
    		}
    		</style>
    		<script type="text/javascript">
    		
    		</script>
    	</head>
    	<body>
    		<div id="main">
    			<div class="c">
    				<span class="value">hello</span>
    				<span class="value">se cond</span>				
    			</div>
    		</div>		
    	</body>
    </html>
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The problem here is that you are applying a background image to an inline element that has wrapped. In FF, the left edge of the left padding on the first line is seen as the 0 x coord of the background image. In IE, the left most portion of the wrapped line signifies this position. If you were to add an id to the second span:

    Code:
    				<span class="value">hello</span>
    				<span class="value" id="two">se cond</span>
    and this conditional stylesheet in the head:

    Code:
    <!--[if IE]>
    <style type="text/css">
    #two {
    background-position: 62px -447px;
    }
    </style>
    <![endif]-->
    It would work out. Alternatively, you could forget about all that, and just make the value class display:block; That would make the alignment uniform, but also change the layout though:

    Code:
            .value {
            		padding:0px 0px 0px 24px; 
    			color:#0080FF; 
    			font-weight:bold; 
    			cursor:pointer; 
    			background: transparent url(images_sprites.gif) no-repeat scroll 4px -447px;
    			display:block;
    		}
    If the container (main) was wide enough to prevent wrapping (as someone else hinted at already), that would also solve the problem.

    Finally, although I haven't tested this yet (I will, and report back only if there are problems). I believe you could use 4 spans in place of the two:

    HTML Code:
    <span class="value"></span>
    <span class="text">hello</span>
    <span class="value"></span>
    <span class="text">se cond</span>
    apply the background image style only to the value spans, and apply whatever text styling you prefer to the text spans. The value spans would still need padding to be wide enough.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    As promised, since that (my last idea from my previous post) didn't exactly work out, here is a cross browser method that appears to satisfy your requirements:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    		<title>Untitled Document</title>
            <style type="text/css">
            .value {
    			color:#0080FF; 
    			font-weight:bold; 
    			cursor:pointer; 
    			background: transparent url(images_sprites.gif) no-repeat 0 -447px;
    		}
            .text {
    			color:#0080FF; 
    			font-weight:bold; 
    			cursor:pointer; 
    		}
            .c{
            		width:100%;
    			border:1px solid red;				
    		}
    		#main { 
    			background-color:#FFFFDA; 
    			border-top:1px solid #BBD0F0; 
    			line-height:20px; 
    			width: 100px; 
    			position: static;
    		}
    		</style>
    	</head>
    	<body>
    		<div id="main">
    			<div class="c">
    <span class="value">&nbsp;&nbsp;&nbsp;&nbsp;</span>
    <span class="text">hello</span>
    <span class="value">&nbsp;&nbsp;&nbsp;&nbsp;</span>
    <span class="text">se cond</span>				
    			</div>
    		</div>		
    	</body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. The Following User Says Thank You to jscheuer1 For This Useful Post:

    codeexploiter (06-10-2008)

  9. #8
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    This is amazing John! I've actually done exactly the same method and when I came here to reply to you about it, you have posted the same thing here also

    Actually this problem occurs in a dynamic environment in which I used to insert the span elements in the div element using JS code. The idea was to display a line of items (all of them are span elements) and each of them has their own onclick events. So the idea of assigning an ID after checking whether the item is the last one in a line or not seems to be bit difficult and not optimized. So I've changed my span element structure and that worked as it should.

    Thanks a lot for the valuable help from your side whenever we people need that.

  10. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I hope you aren't implying that this structure cannot be dynamically generated. If you are, that's OK really - but I can assure that it can be dynamically generated.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  11. #10
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    No basically I wanted a method for arranging the internal span elements in a non-JavaScript based method. So was trying to adjust the CSS part alone. Due to some other reasons I don't want to touch the main JS of mine.

    Since this is a typical issue that can happen to anyone out there if you can provide a working example about solving this issue someone else can have some advantage.

    I would appreciate if you can provide one such example, if that is possible.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •