Forum Moderators: not2easy

Message Too Old, No Replies

Using 2 divs in table cell (using float: left)

div float; left in td

         

Joris

3:49 pm on Jan 14, 2010 (gmt 0)

10+ Year Member



Hi all,

if I have this piece of html:


<html>
<head><title>test</title></head>
<body>
<table width="100%" cellspacing="0" cellpadding="0" border="1" style="table-layout: fixed;">
<tr>
<td style='width: 230px; height: 40px;'>
<div style="float: left; width: 190px; height: 40px;">
<strong>
Naam (code)
</strong>
<br><i>department</i>
</div>
<div style="width: 30px; height: 40px;">
<br><img src="http://www.example.com/user-icon.png" border="0" >
</div>
</td>
<td nowrap="nowrap" align="left" valign="top">
&nbsp;data
</td>
</tr>
</table>
</body>
</html>

It works fin in IE8. I have the text in my tabel cell on the left side, and my image on the right side. However, when I have the same code in FF3.5, the two divs are shown under each other. What am I doing wrong?

Thanks for the help... I know it maybe is an easy question, but I'm just starting to experiment with css.

[edited by: limbo at 7:03 pm (utc) on Jan. 15, 2010]
[edit reason] examplified [/edit]

CSS_Kidd

4:42 pm on Jan 14, 2010 (gmt 0)

10+ Year Member



Question:

What is your image size? You may want to declare it.

also remove the <br> from:

<br><img src="http://www.example.com/user-icon.png" border="0" >

[edited by: limbo at 7:03 pm (utc) on Jan. 15, 2010]

GrafixGuru

5:40 am on Jan 15, 2010 (gmt 0)

10+ Year Member



Modify the second div - add the display property and overflow property as shown below

<div style="width: 30px; height: 40px;display:inline-block;overflow:hidden;">

Joris

7:41 am on Jan 15, 2010 (gmt 0)

10+ Year Member



Thanks GrafixGuru! This does the trick, but could you explain why I have to do this?

Joris

8:29 am on Jan 15, 2010 (gmt 0)

10+ Year Member



<div style="width: 30px; height: 40px; float: right;"> does also work!

GrafixGuru

10:54 am on Jan 15, 2010 (gmt 0)

10+ Year Member



yes it does,

Explanation for my post.
Div 1 was float left, so if we want to place the Div 2 next to Div 1 we have two option. First option is giving the display property as inline-block for the Div 2, so it sits next to Div 1 and second option is we can give float right.