Results 1 to 9 of 9

Thread: why extra space between two lines in IE?

  1. #1
    Join Date
    Jul 2008
    Posts
    34
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default why extra space between two lines in IE?

    Hi folks,

    I am playing around with css, and I want to control the font of text in a table. The html code is:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
    	<title>Table with DIV and CSS</title>
    	<link rel="stylesheet" href="style.css" type="text/css" />
    </head>
    
    <body>
    <div class="leftnav">
    	<div id="main">	
    		<a href="localhost">
    		<div class="element">
    			<img class="divright" src="a.jpg" alt="intro_thumnail" />
    			<p>
    				<span class="text1" >test1</span><br />
    				<span class="text2" >test2</span>
    			</p>
    		</div>	
    		</a><a href="localhost">
    		<div class="element">
    			<img src="b.jpg" class="divright" width="50" height="50" alt="intro_thumnail" />
    			<p>test3, test 4 test 5</p>
    		</div></a>
    	</div>
    	</div>
    </body>
    </html>
    and style.css
    Code:
    .leftnav {
    	float: left;
    	width: 400px;
    }
    
    .content {
    	margin-left: 400px;
    }
    
    .rightnav {
    	float: right;
    	width: 300px;
    }
    
    #main {
    	background-color: #ffffff;
    	border: 2px solid blue;
    	margin: 0 0 0 0;
    	width:60%;
    }
    
    .element {
    	background-color: red;
    	border: 2px solid blue;
    	margin: 0 0 0 0;
    	float: left;
    	width:99%;
    }
    
    .element:hover {
    	background-color: green;
    }
    
    div.element p { 
    	margin-top: 0;
    }
    
    .divright {
    	float: left;
    	width: 100px;
    	margin: 0 0 0 0px;
    	background-color: #ddd;
    	padding: 2px;
    	border: 1px solid blue;
    	width:100px;
    }
    
    span.text1 {
    	font: 15px arial;
    	background-color: 	white;
    	margin-bottom:20px;
    	padding: 0px;
    	width:100%;
    
    }
    
    span.text2 {
    	font: 8px arial;
    	background-color: 	white;
    	margin: 0 0 0 0;
    	padding: 0px;
    }
    My question is about test1 and test2 (I put the red and white background for easily see the problem). In FF I see no gap or extra space between those to white spans, but in IE, there is a red space between them. Why is that? How can I eliminate that space?

    Thanhks,

    D.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I believe you mean text1 and text2.
    The reason why is because your giving margin-bottom to the text1 span. And I think for some reason in FF margin doesn't work for spans. Try this:
    Code:
    .leftnav
    {
    	float: left;
    	width: 400px;
    }
    .content
    {
    	margin-left: 400px;
    }
    .rightnav
    {
    	float: right;
    	width: 300px;
    }
    #main
    {
    	background-color: #ffffff;
    	border: 2px solid blue;
    	margin: 0 0 0 0;
    	width: 60%;
    }
    .element
    {
    	background-color: red;
    	border: 2px solid blue;
    	float: left;
    	margin: 0 0 0 0;
    	width: 99%;
    }
    .element:hover
    {
    	background-color: green;
    }
    div.element p
    {
    	margin-top: 0;
    }
    .divright
    {
    	background-color: #ddd;
    	border: 1px solid blue;
    	float: left;
    	margin: 0 0 0 0px;
    	padding: 2px;
    	width: 100px;
    }
    span.text1
    {
    	background-color: white;
    	font: 15px arial;
    	margin-bottom: 0;
    	padding: 0px;
    	width: 100%;
    }
    span.text2
    {
    	background-color: white;
    	font: 8px arial;
    	margin: 0 0 0 0;
    	padding: 0px;
    }
    Jeremy | jfein.net

  3. #3
    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

    Generally speaking, the default padding and margins for elements varies among browsers (and of course, among elements). So it is often a very good practice to start your stylesheet with:

    Code:
    * {
    margin:0;
    padding:0;
    }
    Then whatever elements, classes and/or uniquely id'ed elements and their various descendant elements (if any) you style, you can rest assured that they are otherwise starting with 0 padding and margins.
    - John
    ________________________

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

  4. #4
    Join Date
    Jul 2008
    Posts
    34
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    I believe you mean text1 and text2.
    Yes Nile, those two spans.
    Quote Originally Posted by Nile View Post
    The reason why is because your giving margin-bottom to the text1 span. And I think for some reason in FF margin doesn't work for spans. Try this:
    Code:
    .leftnav
    {
    	float: left;
    	width: 400px;
    }
    .content
    {
    	margin-left: 400px;
    }
    .rightnav
    {
    	float: right;
    	width: 300px;
    }
    #main
    {
    	background-color: #ffffff;
    	border: 2px solid blue;
    	margin: 0 0 0 0;
    	width: 60%;
    }
    .element
    {
    	background-color: red;
    	border: 2px solid blue;
    	float: left;
    	margin: 0 0 0 0;
    	width: 99%;
    }
    .element:hover
    {
    	background-color: green;
    }
    div.element p
    {
    	margin-top: 0;
    }
    .divright
    {
    	background-color: #ddd;
    	border: 1px solid blue;
    	float: left;
    	margin: 0 0 0 0px;
    	padding: 2px;
    	width: 100px;
    }
    span.text1
    {
    	background-color: white;
    	font: 15px arial;
    	margin-bottom: 0;
    	padding: 0px;
    	width: 100%;
    }
    span.text2
    {
    	background-color: white;
    	font: 8px arial;
    	margin: 0 0 0 0;
    	padding: 0px;
    }
    Nope, does not help at all. I put all margin to 0. See here: http://mangthugian.com/test/table.html. It is fine in FF, but there is a red space in IE (both 7 and 6).

    I think BR tag causes the problem, but I tried to assign BR tag a class with height = 0 or line-height = 0 but still no help.

    D.

  5. #5
    Join Date
    Jul 2008
    Posts
    34
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Generally speaking, the default padding and margins for elements varies among browsers (and of course, among elements). So it is often a very good practice to start your stylesheet with:

    Code:
    * {
    margin:0;
    padding:0;
    }
    Then whatever elements, classes and/or uniquely id'ed elements and their various descendant elements (if any) you style, you can rest assured that they are otherwise starting with 0 padding and margins.
    Yes, I know I should do that, but in the case I am adding some content to the already-there site, then adding that in the extra css will screw up the whole site.

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Alright, try giving your text some line-height
    Giving your code line-height may effect the pages appearance. Well, that is more then the span spacing. For any reason it may change other divs vertical align too. Then you will end up having to give those divs line-height. But thats not hard.
    Good Luck!
    Jeremy | jfein.net

  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

    This worked fine here in IE 6 & 7 and FF 3:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
    	<title>Table with DIV and CSS</title>
    <style type="text/css">
    .leftnav {
    	float: left;
    	width: 400px;
    }
    
    .content {
    	margin-left: 400px;
    }
    
    .rightnav {
    	float: right;
    	width: 300px;
    }
    
    #main {
    	background-color: #ffffff;
    	border: 2px solid blue;
    	margin: 0 0 0 0;
    	width:60%;
    }
    
    .element {
    	background-color: red;
    	border: 2px solid blue;
    	margin: 0 0 0 0;
    	float: left;
    	width:99%;
    }
    
    .element:hover {
    	background-color: green;
    }
    
    div.element p { 
    	margin-top: 0;
    }
    
    .divright {
    	float: left;
    	width: 100px;
    	margin: 0 0 0 0px;
    	background-color: #ddd;
    	padding: 2px;
    	border: 1px solid blue;
    	width:100px;
    }
    
    span.text1 {
    	font: 15px arial;
    	background-color: 	white;
    	margin-bottom:20px;
    	padding: 0px;
    	width:100%;
    
    }
    
    span.text2 {
    	font: 8px arial;
    	background-color: 	white;
    	margin: 0 0 0 0;
    	padding: 0px;
    vertical-align:top;
    }
    </style>
    </head>
    
    <body>
    <div class="leftnav">
    	<div id="main">	
    		<a href="localhost">
    		<div class="element">
    			<img class="divright" src="a.jpg" alt="intro_thumnail" />
    			<p>
    				<span class="text1" >test1</span><br />
    				<span class="text2" >test2</span>
    			</p>
    		</div>	
    		</a><a href="localhost">
    		<div class="element">
    			<img src="b.jpg" class="divright" width="50" height="50" alt="intro_thumnail" />
    			<p>test3, test 4 test 5</p>
    		</div></a>
    	</div>
    	</div>
    </body>
    </html>
    - John
    ________________________

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

  8. #8
    Join Date
    Jul 2008
    Posts
    34
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    This worked fine here in IE 6 & 7 and FF 3:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
    	<title>Table with DIV and CSS</title>
    <style type="text/css">
    .leftnav {
    	float: left;
    	width: 400px;
    }
    
    .content {
    	margin-left: 400px;
    }
    
    .rightnav {
    	float: right;
    	width: 300px;
    }
    
    #main {
    	background-color: #ffffff;
    	border: 2px solid blue;
    	margin: 0 0 0 0;
    	width:60%;
    }
    
    .element {
    	background-color: red;
    	border: 2px solid blue;
    	margin: 0 0 0 0;
    	float: left;
    	width:99%;
    }
    
    .element:hover {
    	background-color: green;
    }
    
    div.element p { 
    	margin-top: 0;
    }
    
    .divright {
    	float: left;
    	width: 100px;
    	margin: 0 0 0 0px;
    	background-color: #ddd;
    	padding: 2px;
    	border: 1px solid blue;
    	width:100px;
    }
    
    span.text1 {
    	font: 15px arial;
    	background-color: 	white;
    	margin-bottom:20px;
    	padding: 0px;
    	width:100%;
    
    }
    
    span.text2 {
    	font: 8px arial;
    	background-color: 	white;
    	margin: 0 0 0 0;
    	padding: 0px;
    vertical-align:top;
    }
    </style>
    </head>
    
    <body>
    <div class="leftnav">
    	<div id="main">	
    		<a href="localhost">
    		<div class="element">
    			<img class="divright" src="a.jpg" alt="intro_thumnail" />
    			<p>
    				<span class="text1" >test1</span><br />
    				<span class="text2" >test2</span>
    			</p>
    		</div>	
    		</a><a href="localhost">
    		<div class="element">
    			<img src="b.jpg" class="divright" width="50" height="50" alt="intro_thumnail" />
    			<p>test3, test 4 test 5</p>
    		</div></a>
    	</div>
    	</div>
    </body>
    </html>
    Ah, it is vertical-alignment not the padding or margin or height? That is... unpredictable. How can you figure out such a solution? The two spans are identical in P tag, and the first one comes up top, why the second one does not? IE is very funny.

    Another thing I do not understand, without vertical-align: top added, what value it was? Is it middle or bottom? In any case, it should locate in the middle or in the bottom, isnt it?

    Anyway, thank you very much John.

  9. #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

    The default for vertical-align is baseline. To tell you the truth, I hadn't realized all of the values that are available for this property, or the fact that it is particularly well suited to inline elements like (in their default display mode) span, a, input, and image, etc. I was more aware of its use in a table cell, as the close equivalent to the valign attribute.

    I found this illuminating:

    http://www.eskimo.com/~bloo/indexdot.../vertalign.htm

    However, in this case, primarily (for me) because it states that this property is so apropos to inline elements. But I'm glad to also know of all the possible values for this property.
    - John
    ________________________

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

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
  •