Forum Moderators: not2easy

Message Too Old, No Replies

start a new line after float:left

Is there a CSS equivalent to this effect

         

iProgram

11:02 am on Oct 6, 2004 (gmt 0)

10+ Year Member



hello, is there a CSS equivalent to this effect?

<table width="100%">
<tr><td width="200">Text 1</td><td>Text 2</td></tr>
<tr><td colspan="2">New Line Text 3</td></tr>
</table>

Here is my code in XHTML

<div id="float_left_width_200">Text 1</div>
<div id="text_2">Text 2</div>
<div id="new_line">New Line Text 3</div>

But the new_line div is not on a new line:(

BlobFisk

11:13 am on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What about using clear: right on the div with id text_2?

createErrorMsg

12:14 pm on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As Blobfisk says, the clear property should do what you want. Give it a value in the same direction as the float above it (in this case, I believe you need clear:left;).

Also, if the two peices of text you want side by side will be of different lengths, you may need to apply a margin-left equal to the width of the float, in order to prevent the longer text from wrapping beneath the float.

iProgram

1:42 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



Hi, I tried your method but it seems I did something wrong:

<STYLE TYPE="text/css">
<!--
#float_left_width_200{
float: left;
width: 200px;
}
#text_2{
clear: right;
}
-->
</STYLE>


<div id="float_left_width_200"><img src="test.gif" height="200" width="200" /></div>
<div id="text_2">Text 2</div>
<div id="new_line">New Line Text 3</div>

Bonusbana

1:50 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



#float_left_width_200{
float: left;
width: 200px;
}
#new_line{
clear: left;
}

iProgram

2:02 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



Hi Bonusbana, it works. But the text color of their parent div changes to write. (But I can press Ctrl+A to make them appear again).

[edited by: iProgram at 2:21 pm (utc) on Oct. 6, 2004]

createErrorMsg

2:19 pm on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Text disappeared in what browser?

Bonusbana

2:20 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



Font colors dont change just like that.
Post the whole code (css & html) and I will try to help you.

iProgram

2:26 pm on Oct 6, 2004 (gmt 0)

10+ Year Member




Text disappeared in what browser?

IE6. No problem with Opera 7 and Netscape and Firefox.

The problem is the background-color of #main. What's wrong with it?


<STYLE TYPE="text/css">
<!--
body{
background-color: #CCCCCC;
}

#main{
margin: 10px;
background: #FFFFFF;
}

#float_left_width_200{
float: left;
width: 200px;
}

#new_line{
clear: left;
}
-->
</STYLE>


<body>
<div id="main">
<div id="float_left_width_200"><img src="temp.gif" height="200" width="200" /></div>
<div id="text_2">Text 2</div>
<div id="new_line">New Line Text 3</div>
</div>
</body>

If I remove the background-color of #main, or remove the clear: left; of #new_line, the texts appare again.

createErrorMsg

2:57 pm on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're experiencing one of IE's numerous display bugs. (peekaboo, guillotine, disappearing background...probably one of those three).

The 'simple' solution is to use the Holly Hack to apply a height: 1%; to the element causing the bug. The height value has to be delivered ONLY to IE browsers, and hidden from IE/Mac (which does not suffer from these bugs). USe the commented backslash hack to hide from Mac, and the star hack to give it only to ie...

/* hide from iemac \*/
* html YOURSELECTOR {
height: 1%;
}
/* end hide from iemac */

Now, the remaining question is which element is triggering the bug (that's what goes in place of YOURSELECTOR above). I think you want to put it on the non-floated element next to the float, in your case, "text_2." Try that and see if it works.

Also, you can read up on these bugs, how they work, why, how to fix them and why the fixes work, here [positioniseverything.net].

iProgram

3:53 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



Thanks. It now works. I added it to div #main and #main is a globe id selector so I defined a new class (.ie) for this page only:


body{
background-color: #CCCCCC;
}
#main{
margin: 10px;
background: #FFFFFF;
}

#float_left_width_200{
float: left;
width: 200px;
}

#new_line{
clear: left;
}

/* hide from iemac \*/
* html .ie {
height: 1%;
}
/* end hide from iemac */


<body>
<div id="main" class="ie">
<div id="float_left_width_200"><img src="temp.gif" height="200" width="200" /></div>
<div id="text_2">Text 2</div>
<div id="new_line">New Line Text 3</div>
</div>
</body>