473,761 Members | 9,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

float:right goes to next line

Hi,
I am trying to put text on left and right side of the page and used:
<div>
<span>blah blah</span>
<span style="float:ri ght">blah blah</span>
</div>
The 2nd text does go to the right but the next line. What am I doing
wrong?

TIA.

Jan 12 '07 #1
22 51552
Rik
as*******@hotma il.com wrote:
Hi,
I am trying to put text on left and right side of the page and used:
<div>
<span>blah blah</span>
<span style="float:ri ght">blah blah</span>
</div>
The 2nd text does go to the right but the next line. What am I doing
wrong?
Nothing really. As far as I know it _should_ work, but doesn't.
Browser bug. If you change it to this it renders OK:
<div>
<span style="float:ri ght">blah blah</span>
<span>blah blah</span>
</div>
--
Rik Wasmus
Jan 12 '07 #2
On 2007-01-12, Rik <lu************ @hotmail.comwro te:
as*******@hotma il.com wrote:
>Hi,
I am trying to put text on left and right side of the page and used:
<div>
<span>blah blah</span>
<span style="float:ri ght">blah blah</span>
</div>
The 2nd text does go to the right but the next line. What am I doing
wrong?

Nothing really. As far as I know it _should_ work, but doesn't.
Browser bug. If you change it to this it renders OK:
<div>
<span style="float:ri ght">blah blah</span>
<span>blah blah</span>
</div>
Yes, this is a known bug in Firefox. Unless the float comes first thing,
it goes one line down, which is contrary to the spec.

But actually simpler in many ways.

In the case where there are a few words followed by a float, the browser
doesn't know which line the float should start on until it has a go at
laying out the words (the words might take up two and half lines or so).
Then it gets to the float, and puts that in. But now that the float's in
the way, the words on that line might not all fit any more-- the line
might need to be broken. This could result in the word preceding the
float in the content ending up below it, which is excluded by the rules,
so the browser may have to restart the line, this time putting the float
on the next line.

If it puts the float on the next line anyway (unless it's right at the
start), its job is a lot easier.
Jan 12 '07 #3

Rik wrote:
as*******@hotma il.com wrote:
Hi,
I am trying to put text on left and right side of the page and used:
<div>
<span>blah blah</span>
<span style="float:ri ght">blah blah</span>
</div>
The 2nd text does go to the right but the next line. What am I doing
wrong?

Nothing really. As far as I know it _should_ work, but doesn't.
Browser bug. If you change it to this it renders OK:
<div>
<span style="float:ri ght">blah blah</span>
<span>blah blah</span>
</div>
--
Rik Wasmus
Thanks Rick. Putting the float:right first fixed the problem.
By the way, I had this problem in IE7 as well as FF.

Jan 12 '07 #4
Ben C wrote:
On 2007-01-12, Rik <lu************ @hotmail.comwro te:
>as*******@hotma il.com wrote:
>>Hi,
I am trying to put text on left and right side of the page and used:
<div>
<span>blah blah</span>
<span style="float:ri ght">blah blah</span>
</div>
The 2nd text does go to the right but the next line. What am I doing
wrong?
Nothing really. As far as I know it _should_ work, but doesn't.
Browser bug.
I don't think that it's a bug at all and that Fx, Opera and even IE
render it identically as they should according to the markup.
>If you change it to this it renders OK:
<div>
<span style="float:ri ght">blah blah</span>
<span>blah blah</span>
</div>
This is the way to get it to render as you want it to.
Yes, this is a known bug in Firefox. Unless the float comes first thing,
it goes one line down, which is contrary to the spec.
I don't believe that it is a bug. Please state the Bug# and/or any
reference to it. I believe that the browsers all (identically) render in
accordance to the specs. Here is a detailed, referenced explanation of
the OP's markup:

<http://www.w3.org/TR/CSS21/visuren.html#q5 >
9.2.1 Block-level elements and block boxes
Block-level elements (the DIV wrapper in this case) generate a principal
block box that contains either only block boxes or only inline boxes.
The principal block box establishes the containing block for descendant
boxes and generated content and is also the box involved in any
positioning scheme. Principal block boxes participate in a block
formatting context.

<http://www.w3.org/TR/CSS21/visuren.html#an onymous-block-level>
9.2.1.1 Anonymous block boxes
How anonymous block boxes may spring into existence around anonymous
content.
The DIV appears to have both inline content and block content. To make
it easier to define the formatting, we assume that there is an anonymous
block box around "Some [anonymous] text". In other words: if a block box
has another block box inside it, then we force it to have only block
boxes inside it.

<http://www.w3.org/TR/CSS21/visuren.html#q1 5>
9.4.1 Block formatting contexts
Floats establish new block formatting contexts.
In a block formatting context, boxes are laid out one after the other,
vertically, beginning at the top of a containing block. The vertical
distance between two sibling boxes is determined by the 'margin'
properties. Vertical margins between adjacent block boxes in a block
formatting context collapse.

Explaining the behavior:
1. The principal block box (the div container) may contain either only
block boxes or only inline boxes.
2. If a block box has another block box inside it, then we force it to
have only block boxes inside it.
3. The principal block box (the div container) contains a floated SPAN
which establishes a new block formatting context.
4. Since there is a block in the container, the in-flow SPAN is forced
to have an assumed anonymous block box around it.
5. The in-flow SPAN, essentially a block now, is presented.
6. The floated SPAN, essentially a block now, is presented (laid out
after the other, vertically, floated right on a new line).
7. The anonymous text (also with an assumed anonymous block box around
it) flows up between the two SPANs (as long as it fits, which it does
here) as high as it can, which here is the same as that of the in-flow SPAN.

--
Gus
Jan 13 '07 #5
Gus Richter wrote:
7. The anonymous text (also with an assumed anonymous block box around
it) flows up between the two SPANs (as long as it fits, which it does
here) as high as it can, which here is the same as that of the in-flow
SPAN.
Ignore item 7. since this was something not included in the OP's
example, but something extra left over from one of my tests as in:

<div>
<span>blah blah</span>
<span style="float:ri ght">blah blah</span>
Some anonymous text.
</div>

--
Gus
Jan 13 '07 #6
On 2007-01-13, Gus Richter <gu********@net scape.netwrote:
Ben C wrote:
>On 2007-01-12, Rik <lu************ @hotmail.comwro te:
>>as*******@hotma il.com wrote:
Hi,
I am trying to put text on left and right side of the page and used:
<div>
<span>blah blah</span>
<span style="float:ri ght">blah blah</span>
</div>
The 2nd text does go to the right but the next line. What am I doing
wrong?
Nothing really. As far as I know it _should_ work, but doesn't.
Browser bug.

I don't think that it's a bug at all and that Fx, Opera and even IE
render it identically as they should according to the markup.
Opera and FF don't render it identically. Opera and Konqueror both get
it right, FF wrong. I haven't tried IE.

Try the OP's example, make sure there's enough room on the first line
for the first "blah blah" and the float. In that case, the top of the
float should be aligned with the top of the line box. FF aligns its top
with the top of the next line (although I am still on version 1.5--
maybe they fixed this in version 2?)

The relevant part of the spec is in 9.5 (CSS 2.1), second paragraph,
which you left out of the sections you posted.

"If there’s a line box, the top of the floated box is aligned with
the top of the current line box."

[snip]
>Yes, this is a known bug in Firefox. Unless the float comes first thing,
it goes one line down, which is contrary to the spec.

I don't believe that it is a bug. Please state the Bug# and/or any
reference to it.
I think someone in one of c.i.w.a.[hs] or alt.html posted a link that
referenced the bug on some Mozilla page somewhere, so you could try the
Google groups search.
Jan 13 '07 #7
On 2007-01-13, Gus Richter <gu********@net scape.netwrote:
Ben C wrote:
>On 2007-01-12, Rik <lu************ @hotmail.comwro te:
>>as*******@hotma il.com wrote:
Hi,
I am trying to put text on left and right side of the page and used:
<div>
<span>blah blah</span>
<span style="float:ri ght">blah blah</span>
</div>
The 2nd text does go to the right but the next line. What am I doing
wrong?
[snip]

Sorry, missed this bit.
Explaining the behavior:
1. The principal block box (the div container) may contain either only
block boxes or only inline boxes.
Correct.
2. If a block box has another block box inside it, then we force it to
have only block boxes inside it.
Well, this is a bit different though. What we have is a block box with a
float in it. Although a float is display: block, that's really all about
how you lay out what's _inside_ the float, not about how the float fits
into its surroundings.

Float placing is something that goes hand-in-hand with inline-box
layout.
3. The principal block box (the div container) contains a floated SPAN
which establishes a new block formatting context.
Correct.
4. Since there is a block in the container, the in-flow SPAN is forced
to have an assumed anonymous block box around it.
No, there's definitely not a block box around inline content either side
of a float-- the text has to flow around the float.

I say "definitely ", but this is really a matter of interpretation, so
I'm tempted not to argue. But I can't see much sense in the idea that
text flowing around a float is split into two anonymous blocks either
side of the float.
Jan 13 '07 #8
In article <_Z************ *************** ***@golden.net> ,
Gus Richter <gu********@net scape.netwrote:
Ben C wrote:
On 2007-01-12, Rik <lu************ @hotmail.comwro te:
as*******@hotma il.com wrote:
Hi,
I am trying to put text on left and right side of the page and used:
<div>
<span>blah blah</span>
<span style="float:ri ght">blah blah</span>
</div>
The 2nd text does go to the right but the next line. What am I doing
wrong?
Nothing really. As far as I know it _should_ work, but doesn't.
Browser bug.

I don't think that it's a bug at all and that Fx, Opera and even IE
render it identically as they should according to the markup.
When I tested about a year ago, Opera and Safari got it "right", in that
the floated element stayed on the same line, as I intended it. Firefox
and IE got it "wrong" from my point of view, by putting the element on
the next line.
>
If you change it to this it renders OK:
<div>
<span style="float:ri ght">blah blah</span>
<span>blah blah</span>
</div>

This is the way to get it to render as you want it to.
My test page for something similar to this has been up for a while at
http://www.ericlindsay.com/palmtop/palmnote.htm
and the right hand item in the header and footer are on the same line in
Safari and Opera.

I never did understand why this caused problems with Firefox, so I am
delighted this thread appeared.
Yes, this is a known bug in Firefox. Unless the float comes first thing,
it goes one line down, which is contrary to the spec.
Thanks for your explanation of what you believe should be happening. I
am putting a bunch of LI block elements inline, and selecting one of
these elements to be floated right. So within the UL block element, all
the LI were now declared inline, and the UL block contained only LI
elements. Since all the other identically styled LI block elements stay
inline, I couldn't understand why one of them should decide it was
really still a block. Especially since two browsers worked the way I
expected.
<http://www.w3.org/TR/CSS21/visuren.html#q1 5>
9.4.1 Block formatting contexts
Floats establish new block formatting contexts.
In a block formatting context, boxes are laid out one after the other,
vertically, beginning at the top of a containing block. The vertical
distance between two sibling boxes is determined by the 'margin'
properties. Vertical margins between adjacent block boxes in a block
formatting context collapse.

Explaining the behavior:
1. The principal block box (the div container) may contain either only
block boxes or only inline boxes.
2. If a block box has another block box inside it, then we force it to
have only block boxes inside it.
3. The principal block box (the div container) contains a floated SPAN
which establishes a new block formatting context.
4. Since there is a block in the container, the in-flow SPAN is forced
to have an assumed anonymous block box around it.
5. The in-flow SPAN, essentially a block now, is presented.
6. The floated SPAN, essentially a block now, is presented (laid out
after the other, vertically, floated right on a new line).
7. The anonymous text (also with an assumed anonymous block box around
it) flows up between the two SPANs (as long as it fits, which it does
here) as high as it can, which here is the same as that of the in-flow SPAN.
After reading your fine explanation, I think I am still confused as to
why different browsers made different decisions about this.

The way I read 9.4.1 and your explanation is that my floated right LI
becomes a new block pulled out of normal display. If the floated element
is first, it is positioned at the right. However there is then still
room for the other inline LI to be positioned prior to reaching the new
block. if the floated LI is not first, then some LI elements are already
positioned within the UL containing block. So the floated LI must go
below them. It would seem that some browsers regard turning a floated
element into a block is overridden if the element was styled as display
inline. Doing so seemed reasonable to me, which is why I expected it to
work.

--
http://www.ericlindsay.com
Jan 14 '07 #9
Ben C wrote:
>
Opera and FF don't render it identically. Opera and Konqueror both get
it right, FF wrong. I haven't tried IE.

Try the OP's example, make sure there's enough room on the first line
for the first "blah blah" and the float. In that case, the top of the
float should be aligned with the top of the line box. FF aligns its top
with the top of the next line (although I am still on version 1.5--
maybe they fixed this in version 2?)
Sadly I did not apply a Strict Doctype so my results were Quirky (Fx,
Opera, IE6, IE7 all identical - line spaced). No idea why Opera renders
this differently in Quirk Mode.
With a Strict DTD Doctype applied, (Fx, IE6, IE7 all identical - line
spaced. Opera odd man out - on the same line). I'm on the side of Fx and
IE on this (so far).
No idea on any other browsers' rendering.
The relevant part of the spec is in 9.5 (CSS 2.1), second paragraph,
which you left out of the sections you posted.

"If there’s a line box, the top of the floated box is aligned with
the top of the current line box."
<http://www.w3.org/TR/CSS21/visuren.html#li ne-box>
9.4.2 Inline formatting context
This defines a "line box" in an inline formatting context which I
believe it isn't. In reading this section, I believe the OP's example to
be in a block formatting context.

--
Gus
Jan 14 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3320
by: JKenyon | last post by:
I am attempting to display two images on a web page. The second "image" is actually two images, one overlaid on the other. The first one is aligned on the left using float:left. I have enclosed the next two images in a <DIV> tag with float: right in order to force the containing content to be aligned on the right. I also set position:relative so that any absolute positioning within the <DIV> will be relative to the itself. The...
9
17977
by: leegold | last post by:
Why does float:right cause a line break? Try the code below. Is there a fix? I want the link on the same line as the text. Thanks <html> <head> <STYLE> span.linkpos { float:right; clear: none; color:blue; } </style> </head>
3
19416
by: Michael Shell | last post by:
Greetings, I've been playing with CSS inline floats of <span> elements and the results are not quite what I would expect. In the example attached at the end of this post, I would expect the floated span 2 to be on the same line as span 1, but instead it is on the same line as span 3, which is on the line below span 1. Eric Meyer's CSS pocket reference gives a clue as to why this is so: "A floated element will generate a block-level box...
5
4923
by: Oliver Block | last post by:
Hello everybody, I wonder why a <span style="float:right">some text</span> might be displayed out of a surrounding div element. It is shifted to the next line. I thougt it is supposed to appear inside the surrounding div. There is
15
16610
dlite922
by: dlite922 | last post by:
I'm back again, Intro: I've got a floating div (outerDIV) with fixed width that contains an image (IMG) and a div that contains a short text (innerDIV) Problem: In FF, the innerDIV is displaying under the IMG because outerDIV is not wide enough to contain both of them (in some instances). In the instances where the outerDIV is wide, I don't have this problem. IE wraps the text but still keeps it to the right of the IMG. FF doesn't...
2
6429
by: paragpdoke | last post by:
Hello All. I have a weird observation regarding the CSS float style for span. Allow me to share details before asking my question: Screen resolution: 1024x768 (I know my monitor is outdated; it can't display higher than this) Link: http://www.w3schools.com/js/tryit.asp?filename=try_dom_style_cssfloat Text entered in the left side: <html> <body>
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.