Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / CSS / June 2005



Tip: Looking for answers? Try searching our database.

inline float right, but not down?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Shell - 27 Jun 2005 11:06 GMT
 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 no matter what kind
of element it may be". Thus, my floated spans are "elevated"
to block level status and are therefore not placed on the same
line in which they are declared.

Now, I can compensate for this by using a negative top margin
equal in magnitude to the line-height as is done with span 2b
in the example below.

My questions are:

1. Is my method of getting the floated span on the same
  line reliable under major recent 6th generation browsers
  (all my tests so far were done under Firefox).

2. Is there a better way to get an inline element against the
  right/let side of the paragraph containing a line, such as
  when placing a hyperlink box to the right of a line of text
  that describes and points to it?

 Thanks in advance,

 Mike Shell

------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Floated Element Height Test</title>
<meta http-equiv="Content-type"
     content="text/html; charset=utf-8"></meta>
<style type="text/css">
body {line-height:1.25em;}
span {margin:0em; padding:0em; border:1px solid red;}
</style>
</head>

<body>
<p>
Body has a line-height (leading) of 1.25em.
</p>
<hr></hr>
<p>
<span>Span 1</span>
<span style="float:right;">Right Floated Span 2</span>
<br/>
<span>Span 3</span>
</p>
<hr></hr>

<hr></hr>
<p>
<span>Span 1b</span>
<span style="float:right; margin-top:-1.25em;">Right
Floated Span 2b with -1.25em top margin</span>
<br/>
<span>Span 3b</span>
</p>
<hr></hr>

</body>
</html>

------
Els - 27 Jun 2005 11:37 GMT
>   Greetings,
>
[quoted text clipped - 8 lines]
> to block level status and are therefore not placed on the same
> line in which they are declared.

Correct.

> Now, I can compensate for this by using a negative top margin
> equal in magnitude to the line-height as is done with span 2b
> in the example below.

No need.

> 2. Is there a better way to get an inline element against the
>    right/let side of the paragraph containing a line, such as
>    when placing a hyperlink box to the right of a line of text
>    that describes and points to it?

Place the float before the rest of the text that you want on the same
line.

Instead of this:

<span>Span 1</span>
<span style="float:right;">Right Floated Span 2</span>
<br/>
<span>Span 3</span>

write this:

<span style="float:right;">Right Floated Span 2</span>
<span>Span 1</span>
<br/>
<span>Span 3</span>

Signature

Els                     http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
                            - Renato Russo -
Now playing: The Stranglers - All Day And All Of The Night

Michael Shell - 28 Jun 2005 02:53 GMT
> Place the float before the rest of the text that you want on the same
> line.

Well, it makes me feel a bit like an idiot, but at least I got a good
answer. In my defense, this is very counter intuitive - I would have
thought that placing it first would have given me an additional
line break/space at the start of the structure. For the record,
display:inline will not help either.

Thank you for your help,

 Mike
Els - 28 Jun 2005 08:03 GMT
>> Place the float before the rest of the text that you want on the same
>> line.
[quoted text clipped - 3 lines]
> thought that placing it first would have given me an additional
> line break/space at the start of the structure.

Depends how you think about it - I see the float as "shove this to one
side, and see how much will fit in the freed space".
A bit like organising the mess in the attic or garage ;-)

> For the record,
> display:inline will not help either.

Display:inline and float are mutually exclusive :-)

>  Thank you for your help,

You're welcome.

Signature

Els                     http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
                            - Renato Russo -

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.