sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
JackRbt's Avatar

span to float right within a div


Question posted by: JackRbt (Newbie) on August 22nd, 2008 09:58 PM
I have a navbar in a div, with several links. The last one is in a <span> because I want it to float to the right by itself. The span does float right, but it shows up below the navbar div. I want it within the div.

Is this doable? Thanks.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. echo "<p>";
  4. echo '<div id="navbar">
  5.            <a href="edit_reg.php">edit</a> 
  6. &nbsp;<a href="undelete.php">undelete</a>
  7. &nbsp;<a href="print_reg.php">print</a>
  8. &nbsp;<a href="rep_sum.php">summary</a>
  9. <span style="float: right"><a href="index.php">reg page</a></span>
  10. </div><p>';
  11.  
  12. ?>
5 Answers Posted
JackRbt's Avatar
JackRbt August 23rd, 2008 01:17 AM
Newbie - 22 Posts
#2: Re: span to float right within a div

I guess it's better to post the HTML output rather than just the PHP source:


Expand|Select|Wrap|Line Numbers
  1. <p>
  2. <div id="navbar">
  3.       <a href="edit_reg.php">edit</a> 
  4. &nbsp;<a href="undelete.php">undelete</a>
  5. &nbsp;<a href="print_reg.php">print</a>
  6. &nbsp;<a href="rep_sum.php">summary</a>
  7. <span style="float: right"><a href="index.php">reg page</a></span>
  8. </div>
David Laakso's Avatar
David Laakso August 23rd, 2008 03:53 PM
Expert - 302 Posts
#3: Re: span to float right within a div

See if this works for you...

Expand|Select|Wrap|Line Numbers
  1.  
  2. CSS
  3. #navlist li{
  4. display: inline;
  5. list-style-type: none;
  6. padding-right: 20px;
  7. }
  8. .c1 {float:right;}
  9.  
  10.  
  11. HTML
  12.  
  13. <div id="navcontainer">
  14. <ul id="navlist">
  15. <li><a href="#">Item one</a></li>
  16. <li><a href="#">Item two</a></li>
  17. <li><a href="#">Item three</a></li>
  18. <li><a href="#">Item four</a></li>
  19. <li class="c1"><a href="#">Item five</a></li>
  20. </ul>
  21. </div>
  22.  
  23.  
  24.  
JackRbt's Avatar
JackRbt August 23rd, 2008 08:41 PM
Newbie - 22 Posts
#4: Re: span to float right within a div

Thanks, David. Unfortunately, that similarly drops down the right-floated item (in IE7 and FF2).

I guess I'll have to live with it... or use a table.
David Laakso's Avatar
David Laakso August 23rd, 2008 10:16 PM
Expert - 302 Posts
#5: Re: span to float right within a div

Sorry. My bad!
Same HTML as in previous example with this CSS:

Expand|Select|Wrap|Line Numbers
  1. html, body {margin:0;padding:0;}
  2. body {
  3. font : 100% arial, sans-serif;
  4. }
  5. #navcontainer ul{
  6. margin:0;
  7. padding: 0;
  8. }
  9.  
  10. #navlist li{
  11. float:left;
  12. padding-right:20px;
  13. display: inline;
  14. list-style-type: none;
  15. }
  16. .c1 {position:absolute;top: 0; right: 20px;}


Quick checked in IE/6, IE/7, Win FF/2.0.0.14, Mac FF3.0.1, Mac Safari, Mac Opera.
JackRbt's Avatar
JackRbt August 24th, 2008 08:51 PM
Newbie - 22 Posts
#6: Re: span to float right within a div

okay, thanks for conveying the concept of absolute positioning

I would have to fine tune the location by pixels, to match
Reply
Not the answer you were looking for? Post your question . . .
197,049 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,049 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top HTML / CSS Contributors